Skip to content

Commit cfddd6a

Browse files
authored
Bump OTEL to 0.12.0 (#173)
Signed-off-by: Pavol Loffay <[email protected]>
1 parent 3699c44 commit cfddd6a

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ subprojects {
2828
description = "Hypertrace OpenTelemetry Javaagent"
2929

3030
extra.set("versions", mapOf(
31-
"opentelemetry" to "0.11.0",
32-
"opentelemetry_java_agent" to "0.11.0",
31+
"opentelemetry" to "0.12.0",
32+
"opentelemetry_java_agent" to "0.12.1",
3333
"byte_buddy" to "1.10.18"
3434
))
3535

instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientBodyCaptureFilter.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.opentelemetry.api.common.AttributeKey;
2020
import io.opentelemetry.api.trace.Span;
21+
import io.opentelemetry.context.Context;
2122
import io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.ClientTracingFilter;
2223
import java.util.List;
2324
import java.util.Map;
@@ -39,12 +40,13 @@ public class JaxrsClientBodyCaptureFilter implements ClientRequestFilter, Client
3940

4041
@Override
4142
public void filter(ClientRequestContext requestContext) {
42-
Object spanObj = requestContext.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
43-
if (!(spanObj instanceof Span)) {
43+
Object contextObj = requestContext.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
44+
if (!(contextObj instanceof Context)) {
4445
return;
4546
}
4647

47-
Span currentSpan = (Span) spanObj;
48+
Context currentContext = (Context) contextObj;
49+
Span currentSpan = Span.fromContext(currentContext);
4850
AgentConfig agentConfig = HypertraceConfig.get();
4951

5052
try {
@@ -61,12 +63,13 @@ public void filter(ClientRequestContext requestContext) {
6163

6264
@Override
6365
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) {
64-
Object spanObj = requestContext.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
65-
if (!(spanObj instanceof Span)) {
66+
Object contextObj = requestContext.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
67+
if (!(contextObj instanceof Context)) {
6668
return;
6769
}
6870

69-
Span currentSpan = (Span) spanObj;
71+
Context currentContext = (Context) contextObj;
72+
Span currentSpan = Span.fromContext(currentContext);
7073
AgentConfig agentConfig = HypertraceConfig.get();
7174

7275
try {

instrumentation/jaxrs-client-2.0/src/main/java/io/opentelemetry/instrumentation/hypertrace/jaxrs/v2_0/JaxrsClientEntityInterceptor.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.opentelemetry.instrumentation.hypertrace.jaxrs.v2_0;
1818

1919
import io.opentelemetry.api.trace.Span;
20+
import io.opentelemetry.context.Context;
2021
import io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.ClientTracingFilter;
2122
import java.io.ByteArrayOutputStream;
2223
import 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 {

testing-common/src/main/java/org/hypertrace/agent/testing/InMemoryExporter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import com.google.common.collect.TreeTraverser;
2424
import com.google.common.primitives.Ints;
2525
import com.google.common.primitives.Longs;
26-
import io.opentelemetry.api.common.AttributeConsumer;
27-
import io.opentelemetry.api.common.AttributeKey;
2826
import io.opentelemetry.api.trace.SpanId;
2927
import io.opentelemetry.context.Context;
3028
import io.opentelemetry.sdk.common.CompletableResultCode;
@@ -130,11 +128,8 @@ private String printSpanAttributes(SpanData sd) {
130128
final StringBuilder attributes = new StringBuilder();
131129
sd.getAttributes()
132130
.forEach(
133-
new AttributeConsumer() {
134-
@Override
135-
public <T> void accept(AttributeKey<T> key, T value) {
136-
attributes.append(String.format("Attribute %s=%s", key, value));
137-
}
131+
(key, value) -> {
132+
attributes.append(String.format("Attribute %s=%s", key, value));
138133
});
139134
return attributes.toString();
140135
}

0 commit comments

Comments
 (0)