|
17 | 17 | package io.opentelemetry.javaagent.instrumentation.hypertrace.servlet.v3_0.nowrapping; |
18 | 18 |
|
19 | 19 | import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.safeHasSuperType; |
| 20 | +import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed; |
20 | 21 | import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.NameMatchers.namedOneOf; |
21 | 22 | import static net.bytebuddy.matcher.ElementMatchers.isPublic; |
22 | 23 | import static net.bytebuddy.matcher.ElementMatchers.named; |
|
28 | 29 | import io.opentelemetry.javaagent.instrumentation.api.ContextStore; |
29 | 30 | import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; |
30 | 31 | import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; |
31 | | -import io.opentelemetry.javaagent.instrumentation.hypertrace.servlet.v3_0.nowrapping.request.RequestStreamReaderHolder; |
32 | | -import io.opentelemetry.javaagent.instrumentation.hypertrace.servlet.v3_0.nowrapping.response.ResponseStreamWriterHolder; |
33 | 32 | import io.opentelemetry.javaagent.tooling.TypeInstrumentation; |
34 | 33 | import java.io.BufferedReader; |
35 | 34 | import java.io.PrintWriter; |
|
51 | 50 | import org.hypertrace.agent.config.Config.AgentConfig; |
52 | 51 | import org.hypertrace.agent.core.config.HypertraceConfig; |
53 | 52 | import org.hypertrace.agent.core.instrumentation.HypertraceSemanticAttributes; |
| 53 | +import org.hypertrace.agent.core.instrumentation.SpanAndObjectPair; |
54 | 54 | import org.hypertrace.agent.core.instrumentation.buffer.BoundedByteArrayOutputStream; |
55 | 55 | import org.hypertrace.agent.core.instrumentation.buffer.BoundedCharArrayWriter; |
56 | 56 | import org.hypertrace.agent.core.instrumentation.buffer.ByteBufferSpanPair; |
|
60 | 60 |
|
61 | 61 | public class Servlet31NoWrappingInstrumentation implements TypeInstrumentation { |
62 | 62 |
|
| 63 | + @Override |
| 64 | + public ElementMatcher<ClassLoader> classLoaderOptimization() { |
| 65 | + return hasClassesNamed("javax.servlet.Filter"); |
| 66 | + } |
| 67 | + |
63 | 68 | @Override |
64 | 69 | public ElementMatcher<? super TypeDescription> typeMatcher() { |
65 | | - return safeHasSuperType(namedOneOf("javax.servlet.Filter", "javax.servlet.http.HttpServlet")); |
| 70 | + return safeHasSuperType(namedOneOf("javax.servlet.Filter", "javax.servlet.Servlet")); |
66 | 71 | } |
67 | 72 |
|
68 | 73 | @Override |
@@ -103,8 +108,8 @@ public static boolean start( |
103 | 108 | && ContentTypeUtils.shouldCapture(contentType)) { |
104 | 109 | // The HttpServletRequest instrumentation uses this to |
105 | 110 | // enable the instrumentation |
106 | | - InstrumentationContext.get(HttpServletRequest.class, RequestStreamReaderHolder.class) |
107 | | - .put(httpRequest, new RequestStreamReaderHolder(currentSpan)); |
| 111 | + InstrumentationContext.get(HttpServletRequest.class, SpanAndObjectPair.class) |
| 112 | + .put(httpRequest, new SpanAndObjectPair(currentSpan)); |
108 | 113 | } |
109 | 114 |
|
110 | 115 | Utils.addSessionId(currentSpan, httpRequest); |
@@ -152,18 +157,17 @@ public static void exit( |
152 | 157 | HttpServletRequest httpRequest = (HttpServletRequest) request; |
153 | 158 | AgentConfig agentConfig = HypertraceConfig.get(); |
154 | 159 |
|
| 160 | + // response context to capture body and clear the context |
| 161 | + ContextStore<HttpServletResponse, SpanAndObjectPair> responseContextStore = |
| 162 | + InstrumentationContext.get(HttpServletResponse.class, SpanAndObjectPair.class); |
155 | 163 | ContextStore<ServletOutputStream, BoundedByteArrayOutputStream> outputStreamContextStore = |
156 | 164 | InstrumentationContext.get(ServletOutputStream.class, BoundedByteArrayOutputStream.class); |
157 | 165 | ContextStore<PrintWriter, BoundedCharArrayWriter> writerContextStore = |
158 | 166 | InstrumentationContext.get(PrintWriter.class, BoundedCharArrayWriter.class); |
159 | 167 |
|
160 | | - // response context to capture body and clear the context |
161 | | - ContextStore<HttpServletResponse, ResponseStreamWriterHolder> responseContextStore = |
162 | | - InstrumentationContext.get(HttpServletResponse.class, ResponseStreamWriterHolder.class); |
163 | | - |
164 | 168 | // request context to clear body buffer |
165 | | - ContextStore<HttpServletRequest, RequestStreamReaderHolder> requestContextStore = |
166 | | - InstrumentationContext.get(HttpServletRequest.class, RequestStreamReaderHolder.class); |
| 169 | + ContextStore<HttpServletRequest, SpanAndObjectPair> requestContextStore = |
| 170 | + InstrumentationContext.get(HttpServletRequest.class, SpanAndObjectPair.class); |
167 | 171 | ContextStore<ServletInputStream, ByteBufferSpanPair> inputStreamContextStore = |
168 | 172 | InstrumentationContext.get(ServletInputStream.class, ByteBufferSpanPair.class); |
169 | 173 | ContextStore<BufferedReader, CharBufferSpanPair> readerContextStore = |
|
0 commit comments