Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.servlet.v3_0;

import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Singletons.getSnippetInjectionHelper;
import static io.opentelemetry.javaagent.instrumentation.servlet.v3_0.Servlet3Singletons.helper;

import io.opentelemetry.context.Context;
Expand All @@ -13,7 +14,6 @@
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder;
import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge;
import io.opentelemetry.javaagent.bootstrap.servlet.ExperimentalSnippetHolder;
import io.opentelemetry.javaagent.bootstrap.servlet.MappingResolver;
import io.opentelemetry.javaagent.instrumentation.servlet.ServletRequestContext;
import io.opentelemetry.javaagent.instrumentation.servlet.v3_0.snippet.SnippetInjectingResponseWrapper;
Expand Down Expand Up @@ -43,7 +43,7 @@ public static void onEnter(
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;

String snippet = ExperimentalSnippetHolder.getSnippet();
String snippet = getSnippetInjectionHelper().getSnippet();
if (!snippet.isEmpty()
&& !((HttpServletResponse) response)
.containsHeader(SnippetInjectingResponseWrapper.FAKE_SNIPPET_HEADER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class Servlet3Singletons {
ResponseInstrumenterFactory.createInstrumenter(INSTRUMENTATION_NAME);

private static final OutputStreamSnippetInjectionHelper SNIPPET_INJECTION_HELPER =
new OutputStreamSnippetInjectionHelper(ExperimentalSnippetHolder.getSnippet());
new OutputStreamSnippetInjectionHelper(() -> ExperimentalSnippetHolder.getSnippet());

public static ServletHelper<HttpServletRequest, HttpServletResponse> helper() {
return HELPER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.function.Supplier;
import java.util.logging.Logger;

public class OutputStreamSnippetInjectionHelper {

private static final Logger logger =
Logger.getLogger(OutputStreamSnippetInjectionHelper.class.getName());

private final String snippet;
private final Supplier<String> snippetSupplier;

public OutputStreamSnippetInjectionHelper(String snippet) {
this.snippet = snippet;
this(() -> snippet);
}

public OutputStreamSnippetInjectionHelper(Supplier<String> snippetSupplier) {
this.snippetSupplier = snippetSupplier;
}

public String getSnippet() {
return snippetSupplier.get();
}

/**
Expand Down Expand Up @@ -53,7 +62,7 @@ public boolean handleWrite(
}
byte[] snippetBytes;
try {
snippetBytes = snippet.getBytes(state.getCharacterEncoding());
snippetBytes = snippetSupplier.get().getBytes(state.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
logger.log(FINE, "UnsupportedEncodingException", e);
return false;
Expand All @@ -79,7 +88,7 @@ public boolean handleWrite(InjectionState state, OutputStream out, int b) throws
}
byte[] snippetBytes;
try {
snippetBytes = snippet.getBytes(state.getCharacterEncoding());
snippetBytes = snippetSupplier.get().getBytes(state.getCharacterEncoding());
} catch (UnsupportedEncodingException e) {
logger.log(FINE, "UnsupportedEncodingException", e);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private static MethodHandle findSetContentLengthLongMethod() {
MethodType.methodType(void.class),
SnippetInjectingResponseWrapper.class);
} catch (NoSuchMethodException | IllegalAccessException e) {
logger.log(FINE, "SnippetInjectingResponseWrapper setContentLengthLong", e);
return null;
}
}
Expand Down