1717package io .opentelemetry .instrumentation .hypertrace .jaxrs .v2_0 ;
1818
1919import io .opentelemetry .api .trace .Span ;
20+ import io .opentelemetry .context .Context ;
2021import io .opentelemetry .javaagent .instrumentation .jaxrsclient .v2_0 .ClientTracingFilter ;
2122import java .io .ByteArrayOutputStream ;
2223import java .io .IOException ;
@@ -46,34 +47,35 @@ public class JaxrsClientEntityInterceptor implements ReaderInterceptor, WriterIn
4647
4748 /** Writing response body to input stream */
4849 @ Override
49- public Object aroundReadFrom (ReaderInterceptorContext context )
50+ public Object aroundReadFrom (ReaderInterceptorContext responseContext )
5051 throws IOException , WebApplicationException {
5152
52- MediaType mediaType = context .getMediaType ();
53+ MediaType mediaType = responseContext .getMediaType ();
5354 AgentConfig agentConfig = HypertraceConfig .get ();
5455 if (mediaType == null
5556 || !ContentTypeUtils .shouldCapture (mediaType .toString ())
5657 || !agentConfig .getDataCapture ().getHttpBody ().getResponse ().getValue ()) {
57- return context .proceed ();
58+ return responseContext .proceed ();
5859 }
5960
60- Object spanObj = context .getProperty (ClientTracingFilter .SPAN_PROPERTY_NAME );
61- if (!(spanObj instanceof Span )) {
61+ Object contextObj = responseContext .getProperty (ClientTracingFilter .CONTEXT_PROPERTY_NAME );
62+ if (!(contextObj instanceof Context )) {
6263 log .error (
6364 "Span object is not present in the context properties, response object will not be captured" );
64- return context .proceed ();
65+ return responseContext .proceed ();
6566 }
66- Span currentSpan = (Span ) spanObj ;
67+ Context context = (Context ) contextObj ;
68+ Span currentSpan = Span .fromContext (context );
6769
6870 // TODO as optimization the type could be checked here and if it is a primitive type e.g. String
6971 // it could be read directly.
7072 // context.getType();
7173
72- InputStream entityStream = context .getInputStream ();
74+ InputStream entityStream = responseContext .getInputStream ();
7375 Object entity = null ;
7476 try {
75- String encodingStr = context .getHeaders ().getFirst (HttpHeaders .CONTENT_ENCODING );
76- String contentLengthStr = context .getHeaders ().getFirst (HttpHeaders .CONTENT_LENGTH );
77+ String encodingStr = responseContext .getHeaders ().getFirst (HttpHeaders .CONTENT_ENCODING );
78+ String contentLengthStr = responseContext .getHeaders ().getFirst (HttpHeaders .CONTENT_LENGTH );
7779 int contentLength = ContentLengthUtils .parseLength (contentLengthStr );
7880
7981 ByteArrayOutputStream buffer = new ByteArrayOutputStream (contentLength );
@@ -84,7 +86,7 @@ public Object aroundReadFrom(ReaderInterceptorContext context)
8486 buffer ,
8587 HypertraceSemanticAttributes .HTTP_RESPONSE_BODY ,
8688 ContentEncodingUtils .toCharset (encodingStr )));
87- entity = context .proceed ();
89+ entity = responseContext .proceed ();
8890 } catch (Exception ex ) {
8991 log .error ("Exception while capturing response body" , ex );
9092 }
@@ -93,33 +95,34 @@ public Object aroundReadFrom(ReaderInterceptorContext context)
9395
9496 /** Writing request body to output stream */
9597 @ Override
96- public void aroundWriteTo (WriterInterceptorContext context )
98+ public void aroundWriteTo (WriterInterceptorContext requestContext )
9799 throws IOException , WebApplicationException {
98100
99- Object spanObj = context .getProperty (ClientTracingFilter .SPAN_PROPERTY_NAME );
100- if (!(spanObj instanceof Span )) {
101+ Object contextObj = requestContext .getProperty (ClientTracingFilter .CONTEXT_PROPERTY_NAME );
102+ if (!(contextObj instanceof Context )) {
101103 log .error (
102104 "Span object is not present in the context properties, request body will not be captured" );
103- context .proceed ();
105+ requestContext .proceed ();
104106 return ;
105107 }
106- Span currentSpan = (Span ) spanObj ;
108+ Context context = (Context ) contextObj ;
109+ Span currentSpan = Span .fromContext (context );
107110
108111 AgentConfig agentConfig = HypertraceConfig .get ();
109112 if (agentConfig .getDataCapture ().getHttpBody ().getRequest ().getValue ()) {
110- MediaType mediaType = context .getMediaType ();
113+ MediaType mediaType = requestContext .getMediaType ();
111114 if (mediaType == null || !ContentTypeUtils .shouldCapture (mediaType .toString ())) {
112- context .proceed ();
115+ requestContext .proceed ();
113116 return ;
114117 }
115118 }
116119
117120 // TODO length is not known
118121 ByteArrayOutputStream buffer = new ByteArrayOutputStream ();
119- OutputStream entityStream = context .getOutputStream ();
122+ OutputStream entityStream = requestContext .getOutputStream ();
120123 try {
121124 GlobalObjectRegistry .outputStreamToBufferMap .put (entityStream , buffer );
122- context .proceed ();
125+ requestContext .proceed ();
123126 } catch (Exception ex ) {
124127 log .error ("Failed to capture request body" , ex );
125128 } finally {
0 commit comments