From b83fc0b84d2d184b26610d2997da162d5e054895 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 1 Feb 2022 11:32:00 +0100 Subject: [PATCH 1/5] Refactor AttributesExtractor so that it extracts route from Context --- .../api/instrumenter/AttributesExtractor.java | 42 +++++++++++++++++-- .../api/instrumenter/Instrumenter.java | 4 +- .../http/HttpClientAttributesExtractor.java | 8 ++-- .../http/HttpCommonAttributesExtractor.java | 4 +- .../instrumenter/http/HttpRouteHolder.java | 12 ++---- .../http/HttpServerAttributesExtractor.java | 22 +++++++--- .../instrumenter/http/HttpServerMetrics.java | 21 +--------- .../HttpClientAttributesExtractorTest.java | 9 ++-- .../HttpServerAttributesExtractorTest.java | 19 +++++---- .../http/HttpServerMetricsTest.java | 6 +-- 10 files changed, 90 insertions(+), 57 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java index 8cdc52774d2d..25ebc429f96d 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.db.DbAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; @@ -25,21 +26,56 @@ * @see NetServerAttributesExtractor */ public interface AttributesExtractor { + + // TODO: use new methods everywhere + + /** + * Extracts attributes from the {@link Context} and the {@link REQUEST} into the {@link + * AttributesBuilder} at the beginning of a request. + */ + default void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { + onStart(attributes, request); + } + /** * Extracts attributes from the {@link REQUEST} into the {@link AttributesBuilder} at the * beginning of a request. */ - void onStart(AttributesBuilder attributes, REQUEST request); + // * @deprecated Use {@link #onStart(AttributesBuilder, Context, Object)} instead. + // @Deprecated + default void onStart(AttributesBuilder attributes, REQUEST request) { + throw new UnsupportedOperationException( + "This method variant is deprecated and will be removed in the next minor release."); + } + + /** + * Extracts attributes from the {@link Context}, the {@link REQUEST} and either {@link RESPONSE} + * or {@code error} into the {@link AttributesBuilder} at the end of a request. + */ + default void onEnd( + AttributesBuilder attributes, + Context context, + REQUEST request, + @Nullable RESPONSE response, + @Nullable Throwable error) { + onEnd(attributes, request, response, error); + } /** * Extracts attributes from the {@link REQUEST} and either {@link RESPONSE} or {@code error} into * the {@link AttributesBuilder} at the end of a request. */ - void onEnd( + // * @deprecated Use {@link #onEnd(AttributesBuilder, Context, Object, Object, Throwable)} + // instead. + // @Deprecated + default void onEnd( AttributesBuilder attributes, REQUEST request, @Nullable RESPONSE response, - @Nullable Throwable error); + @Nullable Throwable error) { + throw new UnsupportedOperationException( + "This method variant is deprecated and will be removed in the next minor release."); + } /** * Sets the {@code value} with the given {@code key} to the {@link AttributesBuilder} if {@code diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java index 37cf55eb2a3f..b76ae7553665 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Instrumenter.java @@ -171,7 +171,7 @@ public Context start(Context parentContext, REQUEST request) { UnsafeAttributes attributesBuilder = new UnsafeAttributes(); for (AttributesExtractor extractor : attributesExtractors) { - extractor.onStart(attributesBuilder, request); + extractor.onStart(attributesBuilder, parentContext, request); } Attributes attributes = attributesBuilder; @@ -221,7 +221,7 @@ public void end( UnsafeAttributes attributes = new UnsafeAttributes(); for (AttributesExtractor extractor : attributesExtractors) { - extractor.onEnd(attributes, request, response, error); + extractor.onEnd(attributes, context, request, response, error); } span.setAllAttributes(attributes); diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java index 6b34fc45f9fe..e2226a38dfa4 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -49,18 +50,19 @@ private HttpClientAttributesExtractor( } @Override - public void onStart(AttributesBuilder attributes, REQUEST request) { - super.onStart(attributes, request); + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { + super.onStart(attributes, parentContext, request); set(attributes, SemanticAttributes.HTTP_URL, getter.url(request)); } @Override public void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { - super.onEnd(attributes, request, response, error); + super.onEnd(attributes, context, request, response, error); set(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response)); } } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java index 7dcb220085a4..45a2da66842a 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpCommonAttributesExtractor.java @@ -9,6 +9,7 @@ import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpHeaderAttributes.responseAttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.List; @@ -32,7 +33,7 @@ abstract class HttpCommonAttributesExtractor< } @Override - public void onStart(AttributesBuilder attributes, REQUEST request) { + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { set(attributes, SemanticAttributes.HTTP_METHOD, getter.method(request)); set(attributes, SemanticAttributes.HTTP_USER_AGENT, userAgent(request)); @@ -47,6 +48,7 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index 6840c86de65d..292811a09a27 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -11,7 +11,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.server.ServerSpan; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; /** @@ -20,7 +19,7 @@ * *

Usually the route is not accessible when the request processing starts; and needs to be set * later, after the instrumented operation starts. This class provides several static methods that - * allow the isntrumentation author to provide the matching HTTP route to the instrumentation when + * allow the instrumentation author to provide the matching HTTP route to the instrumentation when * it is discovered. */ public final class HttpRouteHolder { @@ -131,11 +130,8 @@ public static void updateHttpRoute( } } - // TODO: instead of calling setAttribute() consider storing the route in context end retrieving it - // in the AttributesExtractor private static void updateSpanData(Span serverSpan, String route) { serverSpan.updateName(route); - serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, route); } // This is used when setting route from a servlet filter to pick the most descriptive (longest) @@ -147,11 +143,11 @@ private boolean isBetterRoute(String name) { } /** - * Returns the {@code http.route} attribute value that's stored in the passed {@code context}, or - * null if it was not set before. + * Returns the {@code http.route} attribute value that's stored in the {@code context}, or null if + * it was not set before. */ @Nullable - public static String getRoute(Context context) { + static String getRoute(Context context) { HttpRouteHolder httpRouteHolder = context.get(CONTEXT_KEY); return httpRouteHolder == null ? null : httpRouteHolder.route; } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java index 1ceca0b0c6b4..5f06dcdfcfa3 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractor.java @@ -9,8 +9,10 @@ import static io.opentelemetry.instrumentation.api.instrumenter.http.ForwarderHeaderParser.extractForwardedFor; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.function.Function; import javax.annotation.Nullable; /** @@ -42,18 +44,24 @@ public static HttpServerAttributesExtractor HttpServerAttributesExtractor create( HttpServerAttributesGetter getter, CapturedHttpHeaders capturedHttpHeaders) { - return new HttpServerAttributesExtractor<>(getter, capturedHttpHeaders); + return new HttpServerAttributesExtractor<>( + getter, capturedHttpHeaders, HttpRouteHolder::getRoute); } - private HttpServerAttributesExtractor( + private final Function httpRouteHolderGetter; + + // visible for tests + HttpServerAttributesExtractor( HttpServerAttributesGetter getter, - CapturedHttpHeaders capturedHttpHeaders) { + CapturedHttpHeaders capturedHttpHeaders, + Function httpRouteHolderGetter) { super(getter, capturedHttpHeaders); + this.httpRouteHolderGetter = httpRouteHolderGetter; } @Override - public void onStart(AttributesBuilder attributes, REQUEST request) { - super.onStart(attributes, request); + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { + super.onStart(attributes, parentContext, request); set(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request)); set(attributes, SemanticAttributes.HTTP_SCHEME, getter.scheme(request)); @@ -66,12 +74,14 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { - super.onEnd(attributes, request, response, error); + super.onEnd(attributes, context, request, response, error); set(attributes, SemanticAttributes.HTTP_SERVER_NAME, getter.serverName(request, response)); + set(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context)); } @Nullable diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index dc085de60708..22413c7321c4 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -18,9 +18,7 @@ import io.opentelemetry.instrumentation.api.annotations.UnstableApi; import io.opentelemetry.instrumentation.api.instrumenter.RequestListener; import io.opentelemetry.instrumentation.api.instrumenter.RequestMetrics; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; -import java.util.function.Function; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,14 +49,8 @@ public static RequestMetrics get() { private final LongUpDownCounter activeRequests; private final DoubleHistogram duration; - private final Function httpRouteHolderGetter; private HttpServerMetrics(Meter meter) { - this(meter, HttpRouteHolder::getRoute); - } - - // visible for tests - HttpServerMetrics(Meter meter, Function httpRouteHolderGetter) { activeRequests = meter .upDownCounterBuilder("http.server.active_requests") @@ -72,8 +64,6 @@ private HttpServerMetrics(Meter meter) { .setUnit("ms") .setDescription("The duration of the inbound HTTP request") .build(); - - this.httpRouteHolderGetter = httpRouteHolderGetter; } @Override @@ -96,19 +86,10 @@ public void end(Context context, Attributes endAttributes, long endNanos) { activeRequests.add(-1, applyActiveRequestsView(state.startAttributes())); duration.record( (endNanos - state.startTimeNanos()) / NANOS_PER_MS, - applyServerDurationView(state.startAttributes(), addHttpRoute(context, endAttributes)), + applyServerDurationView(state.startAttributes(), endAttributes), context); } - // TODO: the http.route should be extracted by the AttributesExtractor, HttpServerMetrics should - // not access the context to get it - private Attributes addHttpRoute(Context context, Attributes endAttributes) { - String route = httpRouteHolderGetter.apply(context); - return route == null - ? endAttributes - : endAttributes.toBuilder().put(SemanticAttributes.HTTP_ROUTE, route).build(); - } - @AutoValue abstract static class State { diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java index f36c1197b0e4..3b6a7189686a 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.List; @@ -109,7 +110,7 @@ void normal() { singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header"))); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, request); + extractor.onStart(attributes, Context.root(), request); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.HTTP_METHOD, "POST"), @@ -119,7 +120,7 @@ void normal() { AttributeKey.stringArrayKey("http.request.header.custom_request_header"), asList("123", "456"))); - extractor.onEnd(attributes, request, response, null); + extractor.onEnd(attributes, Context.root(), request, response, null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.HTTP_METHOD, "POST"), @@ -151,10 +152,10 @@ void invalidStatusCode() { new TestHttpClientAttributesGetter(), CapturedHttpHeaders.empty()); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, request); + extractor.onStart(attributes, Context.root(), request); assertThat(attributes.build()).isEmpty(); - extractor.onEnd(attributes, request, response, null); + extractor.onEnd(attributes, Context.root(), request, response, null); assertThat(attributes.build()).isEmpty(); } } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java index 70aefd86d391..e4e6b63f3357 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorTest.java @@ -14,10 +14,12 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import org.junit.jupiter.api.Test; class HttpServerAttributesExtractorTest { @@ -124,14 +126,17 @@ void normal() { response.put("responseContentLengthUncompressed", "21"); response.put("header.custom-response-header", "654,321"); + Function routeFromContext = ctx -> "/repositories/{repoId}"; + HttpServerAttributesExtractor, Map> extractor = - HttpServerAttributesExtractor.create( + new HttpServerAttributesExtractor<>( new TestHttpServerAttributesExtractor(), CapturedHttpHeaders.create( - singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header"))); + singletonList("Custom-Request-Header"), singletonList("Custom-Response-Header")), + routeFromContext); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, request); + extractor.onStart(attributes, Context.root(), request); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.HTTP_FLAVOR, "http/2"), @@ -146,7 +151,7 @@ void normal() { AttributeKey.stringArrayKey("http.request.header.custom_request_header"), asList("123", "456"))); - extractor.onEnd(attributes, request, response, null); + extractor.onEnd(attributes, Context.root(), request, response, null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.HTTP_METHOD, "POST"), @@ -154,7 +159,7 @@ void normal() { entry(SemanticAttributes.HTTP_HOST, "github.com"), entry(SemanticAttributes.HTTP_TARGET, "/repositories/1"), entry(SemanticAttributes.HTTP_USER_AGENT, "okhttp 3.x"), - entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{id}"), + entry(SemanticAttributes.HTTP_ROUTE, "/repositories/{repoId}"), entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1"), entry( AttributeKey.stringArrayKey("http.request.header.custom_request_header"), @@ -181,11 +186,11 @@ void extractClientIpFromX_Forwarded_For() { new TestHttpServerAttributesExtractor(), CapturedHttpHeaders.empty()); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, request); + extractor.onStart(attributes, Context.root(), request); assertThat(attributes.build()) .containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1")); - extractor.onEnd(attributes, request, null, null); + extractor.onEnd(attributes, Context.root(), request, null, null); assertThat(attributes.build()) .containsOnly(entry(SemanticAttributes.HTTP_CLIENT_IP, "1.1.1.1")); } diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java index 3ade6bd6b811..289f24319f60 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsTest.java @@ -157,7 +157,7 @@ void collectsMetrics() { } @Test - void collectsHttpRouteFromContext() { + void collectsHttpRouteFromEndAttributes() { // given InMemoryMetricReader metricReader = InMemoryMetricReader.create(); SdkMeterProvider meterProvider = @@ -166,12 +166,12 @@ void collectsHttpRouteFromContext() { .setMinimumCollectionInterval(Duration.ZERO) .build(); - RequestListener listener = new HttpServerMetrics(meterProvider.get("test"), c -> "/test/{id}"); + RequestListener listener = HttpServerMetrics.get().create(meterProvider.get("test")); Attributes requestAttributes = Attributes.builder().put("http.host", "host").put("http.scheme", "https").build(); - Attributes responseAttributes = Attributes.empty(); + Attributes responseAttributes = Attributes.builder().put("http.route", "/test/{id}").build(); Context parentContext = Context.root(); From 6550e8e72d51e7ec9545768abebb4b2440449776 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 1 Feb 2022 16:14:20 +0100 Subject: [PATCH 2/5] typo --- .../instrumentation/api/instrumenter/http/HttpRouteHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index 292811a09a27..5e773fbea3a9 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -51,7 +51,7 @@ private HttpRouteHolder() {} *

If there is a server span in the context, and the context has been customized with a {@link * HttpRouteHolder}, then this method will update the route using the provided {@code httpRoute} * if and only if the last {@link HttpRouteSource} to update the route using this method has - * strictly lower priority than the provided {@link HttpRouteSource}, and the pased value is + * strictly lower priority than the provided {@link HttpRouteSource}, and the passed value is * non-null. * *

If there is a server span in the context, and the context has NOT been customized with a From 930a296fbf5adb2a8ad553b9c3433a098aad5a28 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 1 Feb 2022 16:19:01 +0100 Subject: [PATCH 3/5] fix tests --- .../api/instrumenter/http/HttpRouteHolder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index 5e773fbea3a9..f05b46da3d88 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.server.ServerSpan; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; /** @@ -110,7 +111,9 @@ public static void updateHttpRoute( if (httpRouteHolder == null) { String httpRoute = httpRouteGetter.get(context, arg1, arg2); if (httpRoute != null && !httpRoute.isEmpty()) { - updateSpanData(serverSpan, httpRoute); + // update both span and name, since there's no HttpRouteHolder in the context + serverSpan.updateName(httpRoute); + serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, httpRoute); } return; } @@ -123,17 +126,17 @@ public static void updateHttpRoute( if (route != null && !route.isEmpty() && (!onlyIfBetterRoute || httpRouteHolder.isBetterRoute(route))) { - updateSpanData(serverSpan, route); + + // update just the span name - the attribute will be picked up by the + // HttpServerAttributesExtractor at the end of request processing + serverSpan.updateName(route); + httpRouteHolder.updatedBySourceOrder = source.order; httpRouteHolder.route = route; } } } - private static void updateSpanData(Span serverSpan, String route) { - serverSpan.updateName(route); - } - // This is used when setting route from a servlet filter to pick the most descriptive (longest) // route. private boolean isBetterRoute(String name) { From 7ac7d43d14463c2d527fb522ca729e1cd37ef62c Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 2 Feb 2022 11:27:03 +0100 Subject: [PATCH 4/5] Update instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java Co-authored-by: Trask Stalnaker --- .../instrumentation/api/instrumenter/http/HttpRouteHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index f05b46da3d88..130dfa1e4996 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -111,7 +111,7 @@ public static void updateHttpRoute( if (httpRouteHolder == null) { String httpRoute = httpRouteGetter.get(context, arg1, arg2); if (httpRoute != null && !httpRoute.isEmpty()) { - // update both span and name, since there's no HttpRouteHolder in the context + // update both span name and attribute, since there's no HttpRouteHolder in the context serverSpan.updateName(httpRoute); serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, httpRoute); } From b2b40c640f7df2c9b7ac624a8b1dd23c4e41e0f4 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Wed, 2 Feb 2022 12:26:49 +0100 Subject: [PATCH 5/5] fix all AttributesExtractors --- .../MethodSpanAttributesExtractor.java | 4 ++- .../MethodSpanAttributesExtractorTest.groovy | 23 ++++++++---- .../api/instrumenter/AttributesExtractor.java | 23 ++++++------ .../ConstantAttributesExtractor.java | 4 ++- .../PeerServiceAttributesExtractor.java | 4 ++- .../code/CodeAttributesExtractor.java | 4 ++- .../db/DbAttributesExtractor.java | 5 ++- .../db/SqlAttributesExtractor.java | 5 +-- .../MessagingAttributesExtractor.java | 4 ++- .../net/NetClientAttributesExtractor.java | 4 ++- .../net/NetServerAttributesExtractor.java | 4 ++- .../rpc/RpcAttributesExtractor.java | 4 ++- .../instrumenter/AttributesExtractorTest.java | 13 ++++--- .../api/instrumenter/InstrumenterTest.java | 8 +++-- .../PeerServiceAttributesExtractorTest.java | 31 ++++++++++------ .../code/CodeAttributesExtractorTest.java | 9 +++-- .../db/DbAttributesExtractorTest.java | 9 +++-- .../db/SqlAttributesExtractorTest.java | 13 ++++--- .../MessagingAttributesExtractorTest.java | 13 ++++--- ...tAddressNetClientAttributesGetterTest.java | 15 +++++--- ...tAddressNetServerAttributesGetterTest.java | 15 +++++--- .../net/NetClientAttributesExtractorTest.java | 19 ++++++---- .../net/NetServerAttributesExtractorTest.java | 19 ++++++---- .../rpc/RpcAttributesExtractorTest.java | 7 ++-- .../apachecamel/CamelSingletons.java | 5 ++- ...tpClientAdditionalAttributesExtractor.java | 5 ++- .../ApiGatewayProxyAttributesExtractor.java | 5 ++- .../AwsLambdaFunctionAttributesExtractor.java | 18 ++++++---- .../internal/SqsEventAttributesExtractor.java | 4 ++- .../SqsMessageAttributesExtractor.java | 4 ++- ...AwsSdkExperimentalAttributesExtractor.java | 4 ++- ...AwsSdkExperimentalAttributesExtractor.java | 7 +++- .../v4_0/CassandraAttributesExtractor.java | 5 ++- ...nsportExperimentalAttributesExtractor.java | 8 +++-- ...nsportExperimentalAttributesExtractor.java | 8 +++-- ...nsportExperimentalAttributesExtractor.java | 8 +++-- ...nsportExperimentalAttributesExtractor.java | 9 +++-- .../grpc/v1_6/GrpcAttributesExtractor.java | 5 ++- ...ernateExperimentalAttributesExtractor.java | 5 ++- .../ExperimentalAttributesExtractor.java | 5 ++- .../HttpJspPageInstrumentationSingletons.java | 5 ++- ...ationContextInstrumentationSingletons.java | 6 +++- ...ConsumerAdditionalAttributesExtractor.java | 5 ++- ...nsumerExperimentalAttributesExtractor.java | 5 ++- ...ProducerAdditionalAttributesExtractor.java | 5 ++- ...rnetesExperimentalAttributesExtractor.java | 4 ++- .../LettuceConnectAttributesExtractor.java | 9 +++-- .../LettuceConnectAttributesExtractor.java | 9 +++-- .../lettuce/v5_1/OpenTelemetryTracing.java | 35 +++++++++---------- .../mongo/v3_1/MongoAttributesExtractor.java | 5 ++- ...liveryExperimentalAttributesExtractor.java | 5 ++- ...abbitDeliveryExtraAttributesExtractor.java | 5 ++- ...eceiveExperimentalAttributesExtractor.java | 5 ++- ...onsumerExperimentalAttributeExtractor.java | 4 ++- ...roducerExperimentalAttributeExtractor.java | 5 ++- .../ServletAdditionalAttributesExtractor.java | 6 +++- .../ServletRequestParametersExtractor.java | 6 +++- .../ExperimentalAttributesExtractor.java | 4 ++- ...ebfluxExperimentalAttributesExtractor.java | 4 ++- .../ModelAndViewAttributesExtractor.java | 5 ++- .../spring/webmvc/StatusCodeExtractor.java | 5 ++- .../TomcatAdditionalAttributesExtractor.java | 4 ++- ...TwilioExperimentalAttributesExtractor.java | 9 +++-- 63 files changed, 366 insertions(+), 153 deletions(-) diff --git a/instrumentation-api-annotation-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/MethodSpanAttributesExtractor.java b/instrumentation-api-annotation-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/MethodSpanAttributesExtractor.java index 561874460c7b..b53e86baebd6 100644 --- a/instrumentation-api-annotation-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/MethodSpanAttributesExtractor.java +++ b/instrumentation-api-annotation-support/src/main/java/io/opentelemetry/instrumentation/api/annotation/support/MethodSpanAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.annotation.support; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.cache.Cache; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import java.lang.reflect.Method; @@ -45,7 +46,7 @@ public static MethodSpanAttributesExtractor { - // TODO: use new methods everywhere - /** * Extracts attributes from the {@link Context} and the {@link REQUEST} into the {@link * AttributesBuilder} at the beginning of a request. @@ -40,9 +38,10 @@ default void onStart(AttributesBuilder attributes, Context parentContext, REQUES /** * Extracts attributes from the {@link REQUEST} into the {@link AttributesBuilder} at the * beginning of a request. + * + * @deprecated Use {@link #onStart(AttributesBuilder, Context, Object)} instead. */ - // * @deprecated Use {@link #onStart(AttributesBuilder, Context, Object)} instead. - // @Deprecated + @Deprecated default void onStart(AttributesBuilder attributes, REQUEST request) { throw new UnsupportedOperationException( "This method variant is deprecated and will be removed in the next minor release."); @@ -64,10 +63,10 @@ default void onEnd( /** * Extracts attributes from the {@link REQUEST} and either {@link RESPONSE} or {@code error} into * the {@link AttributesBuilder} at the end of a request. + * + * @deprecated Use {@link #onEnd(AttributesBuilder, Context, Object, Object, Throwable)} instead. */ - // * @deprecated Use {@link #onEnd(AttributesBuilder, Context, Object, Object, Throwable)} - // instead. - // @Deprecated + @Deprecated default void onEnd( AttributesBuilder attributes, REQUEST request, diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java index c61b41ac7fe0..882e120302fc 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/ConstantAttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import javax.annotation.Nullable; final class ConstantAttributesExtractor @@ -21,13 +22,14 @@ final class ConstantAttributesExtractor } @Override - public void onStart(AttributesBuilder attributes, REQUEST request) { + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { attributes.put(attributeKey, attributeValue); } @Override public void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java index 21c1669c65f2..9b4e06b0dfb1 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractor.java @@ -8,6 +8,7 @@ import static java.util.Collections.emptyMap; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -49,11 +50,12 @@ public static PeerServiceAttributesExtractor implements AttributesExtractor { @Override - public final void onStart(AttributesBuilder attributes, REQUEST request) { + public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { Class cls = codeClass(request); if (cls != null) { set(attributes, SemanticAttributes.CODE_NAMESPACE, cls.getName()); @@ -32,6 +33,7 @@ public final void onStart(AttributesBuilder attributes, REQUEST request) { @Override public final void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java index e1b879c86b64..407a87fad9bb 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.db; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -21,8 +22,9 @@ */ public abstract class DbAttributesExtractor implements AttributesExtractor { + @Override - public void onStart(AttributesBuilder attributes, REQUEST request) { + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { set(attributes, SemanticAttributes.DB_SYSTEM, system(request)); set(attributes, SemanticAttributes.DB_USER, user(request)); set(attributes, SemanticAttributes.DB_NAME, name(request)); @@ -34,6 +36,7 @@ public void onStart(AttributesBuilder attributes, REQUEST request) { @Override public final void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java index aae95337a219..5d17410f5f65 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.db.SqlStatementInfo; import io.opentelemetry.instrumentation.api.db.SqlStatementSanitizer; import javax.annotation.Nullable; @@ -26,8 +27,8 @@ public abstract class SqlAttributesExtractor extends DbAttributesExtractor { @Override - public final void onStart(AttributesBuilder attributes, REQUEST request) { - super.onStart(attributes, request); + public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { + super.onStart(attributes, parentContext, request); AttributeKey dbTable = dbTableAttribute(); if (dbTable != null) { set(attributes, dbTable, table(request)); diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractor.java index 70a88261ea55..f9a87d0f98f0 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.messaging; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -24,7 +25,7 @@ public abstract class MessagingAttributesExtractor public static final String TEMP_DESTINATION_NAME = "(temporary)"; @Override - public final void onStart(AttributesBuilder attributes, REQUEST request) { + public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { set(attributes, SemanticAttributes.MESSAGING_SYSTEM, system(request)); set(attributes, SemanticAttributes.MESSAGING_DESTINATION_KIND, destinationKind(request)); boolean isTemporaryDestination = temporaryDestination(request); @@ -55,6 +56,7 @@ public final void onStart(AttributesBuilder attributes, REQUEST request) { @Override public final void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java index 563fc3013eef..9a64823a4a6f 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.net; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -34,11 +35,12 @@ private NetClientAttributesExtractor(NetClientAttributesGetter getter) } @Override - public final void onStart(AttributesBuilder attributes, REQUEST request) { + public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { set(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request)); String peerIp = getter.peerIp(request); @@ -51,6 +52,7 @@ public final void onStart(AttributesBuilder attributes, REQUEST request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) {} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java index 912212e92c05..8e1a20967376 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -23,7 +24,7 @@ public abstract class RpcAttributesExtractor implements AttributesExtractor { @Override - public final void onStart(AttributesBuilder attributes, REQUEST request) { + public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { set(attributes, SemanticAttributes.RPC_SYSTEM, system(request)); set(attributes, SemanticAttributes.RPC_SERVICE, service(request)); set(attributes, SemanticAttributes.RPC_METHOD, method(request)); @@ -32,6 +33,7 @@ public final void onStart(AttributesBuilder attributes, REQUEST request) { @Override public final void onEnd( AttributesBuilder attributes, + Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable error) { diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractorTest.java index b05f1ee6a77e..d4f2754a591d 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/AttributesExtractorTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; @@ -22,7 +23,8 @@ static class TestAttributesExtractor implements AttributesExtractor, Map> { @Override - public void onStart(AttributesBuilder attributes, Map request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, Map request) { set(attributes, AttributeKey.stringKey("animal"), request.get("animal")); set(attributes, AttributeKey.stringKey("country"), request.get("country")); } @@ -30,6 +32,7 @@ public void onStart(AttributesBuilder attributes, Map request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, Map request, @Nullable Map response, @Nullable Throwable error) { @@ -54,9 +57,11 @@ void normal() { Exception error = new RuntimeException(); AttributesBuilder attributesBuilder = Attributes.builder(); - extractor.onStart(attributesBuilder, request); - extractor.onEnd(attributesBuilder, request, response, null); - extractor.onEnd(attributesBuilder, request, null, error); + Context context = Context.root(); + + extractor.onStart(attributesBuilder, context, request); + extractor.onEnd(attributesBuilder, context, request, response, null); + extractor.onEnd(attributesBuilder, context, request, null, error); assertThat(attributesBuilder.build()) .containsOnly( diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java index 889d3e773db7..228532b03488 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java @@ -81,7 +81,8 @@ static class AttributesExtractor1 implements AttributesExtractor, Map> { @Override - public void onStart(AttributesBuilder attributes, Map request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, Map request) { attributes.put("req1", request.get("req1")); attributes.put("req2", request.get("req2")); } @@ -89,6 +90,7 @@ public void onStart(AttributesBuilder attributes, Map request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, Map request, Map response, @Nullable Throwable error) { @@ -101,7 +103,8 @@ static class AttributesExtractor2 implements AttributesExtractor, Map> { @Override - public void onStart(AttributesBuilder attributes, Map request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, Map request) { attributes.put("req3", request.get("req3")); attributes.put("req2", request.get("req2_2")); } @@ -109,6 +112,7 @@ public void onStart(AttributesBuilder attributes, Map request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, Map request, Map response, @Nullable Throwable error) { diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java index e2c856487f96..2f24e7cbde55 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/PeerServiceAttributesExtractorTest.java @@ -14,6 +14,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; @@ -35,10 +36,12 @@ void shouldNotSetAnyValueIfNetExtractorReturnsNulls() { PeerServiceAttributesExtractor underTest = new PeerServiceAttributesExtractor<>(peerServiceMapping, netAttributesExtractor); + Context context = Context.root(); + // when AttributesBuilder attributes = Attributes.builder(); - underTest.onStart(attributes, "request"); - underTest.onEnd(attributes, "request", "response", null); + underTest.onStart(attributes, context, "request"); + underTest.onEnd(attributes, context, "request", "response", null); // then assertTrue(attributes.build().isEmpty()); @@ -54,11 +57,13 @@ void shouldNotSetAnyValueIfPeerNameDoesNotMatch() { given(netAttributesExtractor.peerName(any(), any())).willReturn("example2.com"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, "request"); + underTest.onStart(startAttributes, context, "request"); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, "request", "response", null); + underTest.onEnd(endAttributes, context, "request", "response", null); // then assertTrue(startAttributes.build().isEmpty()); @@ -75,11 +80,13 @@ void shouldNotSetAnyValueIfPeerIpDoesNotMatch() { given(netAttributesExtractor.peerIp(any(), any())).willReturn("1.2.3.5"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, "request"); + underTest.onStart(startAttributes, context, "request"); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, "request", "response", null); + underTest.onEnd(endAttributes, context, "request", "response", null); // then assertTrue(startAttributes.build().isEmpty()); @@ -98,11 +105,13 @@ void shouldSetPeerNameIfItMatches() { given(netAttributesExtractor.peerName(any(), any())).willReturn("example.com"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, "request"); + underTest.onStart(startAttributes, context, "request"); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, "request", "response", null); + underTest.onEnd(endAttributes, context, "request", "response", null); // then assertThat(startAttributes.build()).isEmpty(); @@ -123,11 +132,13 @@ void shouldSetPeerIpIfItMatchesAndNameDoesNot() { given(netAttributesExtractor.peerName(any(), any())).willReturn("test.com"); given(netAttributesExtractor.peerIp(any(), any())).willReturn("1.2.3.4"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, "request"); + underTest.onStart(startAttributes, context, "request"); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, "request", "response", null); + underTest.onEnd(endAttributes, context, "request", "response", null); // then assertThat(startAttributes.build()).isEmpty(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeAttributesExtractorTest.java index 36d9f2bf370f..9476b7c60b07 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/code/CodeAttributesExtractorTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Collections; import java.util.HashMap; @@ -56,12 +57,14 @@ void shouldExtractAllAttributes() { request.put("filePath", "/tmp/TestClass.java"); request.put("lineNo", "42"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, request); + underTest.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, request, null, null); + underTest.onEnd(endAttributes, context, request, null, null); // then assertThat(startAttributes.build()) @@ -78,7 +81,7 @@ void shouldExtractAllAttributes() { void shouldExtractNoAttributesIfNoneAreAvailable() { // when AttributesBuilder attributes = Attributes.builder(); - underTest.onStart(attributes, Collections.emptyMap()); + underTest.onStart(attributes, Context.root(), Collections.emptyMap()); // then assertThat(attributes.build().isEmpty()).isTrue(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java index c4cc80156ca7..6ce7918029e4 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbAttributesExtractorTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Collections; import java.util.HashMap; @@ -61,12 +62,14 @@ void shouldExtractAllAvailableAttributes() { request.put("db.statement", "SELECT * FROM potato"); request.put("db.operation", "SELECT"); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, request); + underTest.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, request, null, null); + underTest.onEnd(endAttributes, context, request, null, null); // then assertThat(startAttributes.build()) @@ -85,7 +88,7 @@ void shouldExtractAllAvailableAttributes() { void shouldExtractNoAttributesIfNoneAreAvailable() { // when AttributesBuilder attributes = Attributes.builder(); - underTest.onStart(attributes, Collections.emptyMap()); + underTest.onStart(attributes, Context.root(), Collections.emptyMap()); // then assertThat(attributes.build().isEmpty()).isTrue(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java index 5bfc535969c8..7c086a64cd55 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/db/SqlAttributesExtractorTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Collections; import java.util.HashMap; @@ -65,12 +66,14 @@ void shouldExtractAllAttributes() { dbTableAttribute = SemanticAttributes.DB_SQL_TABLE; + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, request); + underTest.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, request, null, null); + underTest.onEnd(endAttributes, context, request, null, null); // then assertThat(startAttributes.build()) @@ -94,9 +97,11 @@ void shouldNotExtractTableIfAttributeIsNotSet() { dbTableAttribute = null; + Context context = Context.root(); + // when AttributesBuilder attributes = Attributes.builder(); - underTest.onStart(attributes, request); + underTest.onStart(attributes, context, request); // then assertThat(attributes.build()) @@ -109,7 +114,7 @@ void shouldNotExtractTableIfAttributeIsNotSet() { void shouldExtractNoAttributesIfNoneAreAvailable() { // when AttributesBuilder attributes = Attributes.builder(); - underTest.onStart(attributes, Collections.emptyMap()); + underTest.onStart(attributes, Context.root(), Collections.emptyMap()); // then assertThat(attributes.build().isEmpty()).isTrue(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java index d1971fa3a6e0..d3ee7874be19 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; import java.util.Collections; @@ -50,12 +51,14 @@ void shouldExtractAllAvailableAttributes( TestMessagingAttributesExtractor underTest = new TestMessagingAttributesExtractor(operation); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, request); + underTest.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, request, "42", null); + underTest.onEnd(endAttributes, context, request, "42", null); // then List, Object>> expectedEntries = new ArrayList<>(); @@ -95,12 +98,14 @@ void shouldExtractNoAttributesIfNoneAreAvailable() { TestMessagingAttributesExtractor underTest = new TestMessagingAttributesExtractor(MessageOperation.SEND); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - underTest.onStart(startAttributes, Collections.emptyMap()); + underTest.onStart(startAttributes, context, Collections.emptyMap()); AttributesBuilder endAttributes = Attributes.builder(); - underTest.onEnd(endAttributes, Collections.emptyMap(), null, null); + underTest.onEnd(endAttributes, context, Collections.emptyMap(), null, null); // then assertThat(startAttributes.build().isEmpty()).isTrue(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java index edb7354609cd..ad95b8da761f 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetClientAttributesGetterTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.junit.jupiter.api.Test; @@ -40,7 +41,7 @@ public String transport(InetSocketAddress request, InetSocketAddress response) { void noInetSocketAddress() { AttributesBuilder attributes = Attributes.builder(); - extractor.onEnd(attributes, null, null, null); + extractor.onEnd(attributes, Context.root(), null, null, null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)); @@ -55,12 +56,14 @@ void fullAddress() { InetSocketAddress response = new InetSocketAddress("api.github.com", 456); assertThat(request.getAddress().getHostAddress()).isNotNull(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); @@ -82,12 +85,14 @@ void unresolved() { InetSocketAddress response = InetSocketAddress.createUnresolved("api.github.com", 456); assertThat(request.getAddress()).isNull(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java index 2fa803635eba..9515dde3f03f 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/InetSocketAddressNetServerAttributesGetterTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.net.InetSocketAddress; import org.junit.jupiter.api.Test; @@ -36,7 +37,7 @@ public String transport(InetSocketAddress request) { @Test void noInetSocketAddress() { AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, null); + extractor.onStart(attributes, Context.root(), null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)); @@ -51,12 +52,14 @@ void fullAddress() { InetSocketAddress response = new InetSocketAddress("api.github.com", 456); assertThat(request.getAddress().getHostAddress()).isNotNull(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()) @@ -78,12 +81,14 @@ void unresolved() { InetSocketAddress response = InetSocketAddress.createUnresolved("api.github.com", 456); assertThat(request.getAddress()).isNull(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()) diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java index a1709fc96c3a..ecc25f9d15af 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetClientAttributesExtractorTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -68,12 +69,14 @@ void normal() { NetClientAttributesExtractor, Map> extractor = NetClientAttributesExtractor.create(getter); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); @@ -103,12 +106,14 @@ public void doesNotSetDuplicateAttributes() { NetClientAttributesExtractor, Map> extractor = NetClientAttributesExtractor.create(getter); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); @@ -132,12 +137,14 @@ public void doesNotSetNegativePort() { NetClientAttributesExtractor, Map> extractor = NetClientAttributesExtractor.create(getter); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java index d3566dd636b5..c63ffa609dfe 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/net/NetServerAttributesExtractorTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -58,12 +59,14 @@ void normal() { NetServerAttributesExtractor, Map> extractor = createTestExtractor(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()) @@ -93,12 +96,14 @@ public void doesNotSetDuplicateAttributes() { NetServerAttributesExtractor, Map> extractor = createTestExtractor(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()) @@ -122,12 +127,14 @@ public void doesNotSetNegativePort() { NetServerAttributesExtractor, Map> extractor = createTestExtractor(); + Context context = Context.root(); + // when AttributesBuilder startAttributes = Attributes.builder(); - extractor.onStart(startAttributes, request); + extractor.onStart(startAttributes, context, request); AttributesBuilder endAttributes = Attributes.builder(); - extractor.onEnd(endAttributes, request, response, null); + extractor.onEnd(endAttributes, context, request, response, null); // then assertThat(startAttributes.build()).isEmpty(); diff --git a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractorTest.java b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractorTest.java index 7b2e698f2f1b..f69139aa3894 100644 --- a/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractorTest.java +++ b/instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcAttributesExtractorTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashMap; import java.util.Map; @@ -41,15 +42,17 @@ void normal() { request.put("service", "my.Service"); request.put("method", "Method"); + Context context = Context.root(); + TestExtractor extractor = new TestExtractor(); AttributesBuilder attributes = Attributes.builder(); - extractor.onStart(attributes, request); + extractor.onStart(attributes, context, request); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.RPC_SYSTEM, "test"), entry(SemanticAttributes.RPC_SERVICE, "my.Service"), entry(SemanticAttributes.RPC_METHOD, "Method")); - extractor.onEnd(attributes, request, null, null); + extractor.onEnd(attributes, context, request, null, null); assertThat(attributes.build()) .containsOnly( entry(SemanticAttributes.RPC_SYSTEM, "test"), diff --git a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/CamelSingletons.java b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/CamelSingletons.java index 16153d7e643f..84ffc6cf3fa3 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/CamelSingletons.java +++ b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/CamelSingletons.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; @@ -39,7 +40,8 @@ public final class CamelSingletons { new AttributesExtractor() { @Override - public void onStart(AttributesBuilder attributes, CamelRequest camelRequest) { + public void onStart( + AttributesBuilder attributes, Context parentContext, CamelRequest camelRequest) { SpanDecorator spanDecorator = camelRequest.getSpanDecorator(); spanDecorator.pre( attributes, @@ -51,6 +53,7 @@ public void onStart(AttributesBuilder attributes, CamelRequest camelRequest) { @Override public void onEnd( AttributesBuilder attributes, + Context context, CamelRequest camelRequest, @Nullable Void unused, @Nullable Throwable error) { diff --git a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientAdditionalAttributesExtractor.java b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientAdditionalAttributesExtractor.java index 022b982af9f3..ebaecd717099 100644 --- a/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientAdditionalAttributesExtractor.java +++ b/instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientAdditionalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -16,11 +17,13 @@ public class AsyncHttpClientAdditionalAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, RequestContext requestContext) {} + public void onStart( + AttributesBuilder attributes, Context parentContext, RequestContext requestContext) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, RequestContext requestContext, @Nullable Response response, @Nullable Throwable error) { diff --git a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/ApiGatewayProxyAttributesExtractor.java b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/ApiGatewayProxyAttributesExtractor.java index 9656270fbdd3..2536920559ca 100644 --- a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/ApiGatewayProxyAttributesExtractor.java +++ b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/ApiGatewayProxyAttributesExtractor.java @@ -16,6 +16,7 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.awslambda.v1_0.AwsLambdaRequest; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -28,7 +29,8 @@ final class ApiGatewayProxyAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, AwsLambdaRequest request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, AwsLambdaRequest request) { if (request.getInput() instanceof APIGatewayProxyRequestEvent) { set(attributes, FAAS_TRIGGER, SemanticAttributes.FaasTriggerValues.HTTP); onRequest(attributes, (APIGatewayProxyRequestEvent) request.getInput()); @@ -78,6 +80,7 @@ private static String getHttpUrl( @Override public void onEnd( AttributesBuilder attributes, + Context context, AwsLambdaRequest request, @Nullable Object response, @Nullable Throwable error) { diff --git a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/AwsLambdaFunctionAttributesExtractor.java b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/AwsLambdaFunctionAttributesExtractor.java index 7e6b27d4389d..845ade40f014 100644 --- a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/AwsLambdaFunctionAttributesExtractor.java +++ b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/AwsLambdaFunctionAttributesExtractor.java @@ -40,27 +40,31 @@ class AwsLambdaFunctionAttributesExtractor private volatile String accountId; @Override - public void onStart(AttributesBuilder attributes, AwsLambdaRequest request) { - Context context = request.getAwsContext(); - set(attributes, FAAS_EXECUTION, context.getAwsRequestId()); - set(attributes, FAAS_ID, getFunctionArn(context)); - set(attributes, CLOUD_ACCOUNT_ID, getAccountId(getFunctionArn(context))); + public void onStart( + AttributesBuilder attributes, + io.opentelemetry.context.Context parentContext, + AwsLambdaRequest request) { + Context awsContext = request.getAwsContext(); + set(attributes, FAAS_EXECUTION, awsContext.getAwsRequestId()); + set(attributes, FAAS_ID, getFunctionArn(awsContext)); + set(attributes, CLOUD_ACCOUNT_ID, getAccountId(getFunctionArn(awsContext))); } @Override public void onEnd( AttributesBuilder attributes, + io.opentelemetry.context.Context context, AwsLambdaRequest request, @Nullable Object response, @Nullable Throwable error) {} @Nullable - private static String getFunctionArn(Context context) { + private static String getFunctionArn(Context awsContext) { if (GET_FUNCTION_ARN == null) { return null; } try { - return (String) GET_FUNCTION_ARN.invoke(context); + return (String) GET_FUNCTION_ARN.invoke(awsContext); } catch (Throwable throwable) { return null; } diff --git a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsEventAttributesExtractor.java b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsEventAttributesExtractor.java index babc531cf5a7..99b73f4bb13b 100644 --- a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsEventAttributesExtractor.java +++ b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsEventAttributesExtractor.java @@ -7,13 +7,14 @@ import com.amazonaws.services.lambda.runtime.events.SQSEvent; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; class SqsEventAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, SQSEvent event) { + public void onStart(AttributesBuilder attributes, Context parentContext, SQSEvent event) { attributes.put(SemanticAttributes.MESSAGING_SYSTEM, "AmazonSQS"); attributes.put(SemanticAttributes.MESSAGING_OPERATION, "process"); } @@ -21,6 +22,7 @@ public void onStart(AttributesBuilder attributes, SQSEvent event) { @Override public void onEnd( AttributesBuilder attributes, + Context context, SQSEvent event, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsMessageAttributesExtractor.java b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsMessageAttributesExtractor.java index cfd6771906c4..301f1405e0f8 100644 --- a/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsMessageAttributesExtractor.java +++ b/instrumentation/aws-lambda-1.0/library/src/main/java/io/opentelemetry/instrumentation/awslambda/v1_0/internal/SqsMessageAttributesExtractor.java @@ -7,13 +7,14 @@ import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; class SqsMessageAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, SQSMessage message) { + public void onStart(AttributesBuilder attributes, Context parentContext, SQSMessage message) { attributes.put(SemanticAttributes.MESSAGING_SYSTEM, "AmazonSQS"); attributes.put(SemanticAttributes.MESSAGING_OPERATION, "process"); attributes.put(SemanticAttributes.MESSAGING_MESSAGE_ID, message.getMessageId()); @@ -23,6 +24,7 @@ public void onStart(AttributesBuilder attributes, SQSMessage message) { @Override public void onEnd( AttributesBuilder attributes, + Context context, SQSMessage message, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkExperimentalAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkExperimentalAttributesExtractor.java index 695df858fa80..9a0f824a3fc9 100644 --- a/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkExperimentalAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-1.11/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v1_11/AwsSdkExperimentalAttributesExtractor.java @@ -18,6 +18,7 @@ import com.amazonaws.Request; import com.amazonaws.Response; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; @@ -26,7 +27,7 @@ class AwsSdkExperimentalAttributesExtractor private static final String COMPONENT_NAME = "java-aws-sdk"; @Override - public void onStart(AttributesBuilder attributes, Request request) { + public void onStart(AttributesBuilder attributes, Context parentContext, Request request) { set(attributes, AWS_AGENT, COMPONENT_NAME); set(attributes, AWS_ENDPOINT, request.getEndpoint().toString()); @@ -41,6 +42,7 @@ public void onStart(AttributesBuilder attributes, Request request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, Request request, @Nullable Response response, @Nullable Throwable error) { diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkExperimentalAttributesExtractor.java b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkExperimentalAttributesExtractor.java index f246d49a1024..7a365317cfce 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkExperimentalAttributesExtractor.java +++ b/instrumentation/aws-sdk/aws-sdk-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AwsSdkExperimentalAttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import software.amazon.awssdk.core.interceptor.ExecutionAttributes; @@ -19,13 +20,17 @@ class AwsSdkExperimentalAttributesExtractor private static final AttributeKey AWS_AGENT = AttributeKey.stringKey("aws.agent"); @Override - public void onStart(AttributesBuilder attributes, ExecutionAttributes executionAttributes) { + public void onStart( + AttributesBuilder attributes, + Context parentContext, + ExecutionAttributes executionAttributes) { attributes.put(AWS_AGENT, COMPONENT_NAME); } @Override public void onEnd( AttributesBuilder attributes, + Context context, ExecutionAttributes executionAttributes, @Nullable SdkHttpResponse sdkHttpResponse, @Nullable Throwable error) {} diff --git a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java index b353cbb0f703..c28d3349e26c 100644 --- a/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java +++ b/instrumentation/cassandra/cassandra-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/cassandra/v4_0/CassandraAttributesExtractor.java @@ -11,6 +11,7 @@ import com.datastax.oss.driver.api.core.cql.Statement; import com.datastax.oss.driver.api.core.metadata.Node; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -19,11 +20,13 @@ final class CassandraAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, CassandraRequest request) {} + public void onStart( + AttributesBuilder attributes, Context parentContext, CassandraRequest request) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, CassandraRequest request, @Nullable ExecutionInfo executionInfo, @Nullable Throwable error) { diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportExperimentalAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportExperimentalAttributesExtractor.java index 01c1f3b7708d..8a172a38686c 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportExperimentalAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_0/Elasticsearch5TransportExperimentalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_0; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportExperimentalAttributesExtractor; import org.elasticsearch.action.DocumentRequest; @@ -14,8 +15,11 @@ public class Elasticsearch5TransportExperimentalAttributesExtractor extends ElasticsearchTransportExperimentalAttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, ElasticTransportRequest transportRequest) { - super.onStart(attributes, transportRequest); + public void onStart( + AttributesBuilder attributes, + Context parentContext, + ElasticTransportRequest transportRequest) { + super.onStart(attributes, parentContext, transportRequest); Object request = transportRequest.getRequest(); if (request instanceof DocumentRequest) { diff --git a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportExperimentalAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportExperimentalAttributesExtractor.java index 8ea39d715c27..52a6d6eb2abc 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportExperimentalAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53TransportExperimentalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v5_3; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportExperimentalAttributesExtractor; import org.elasticsearch.action.DocWriteRequest; @@ -14,8 +15,11 @@ public class Elasticsearch53TransportExperimentalAttributesExtractor extends ElasticsearchTransportExperimentalAttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, ElasticTransportRequest transportRequest) { - super.onStart(attributes, transportRequest); + public void onStart( + AttributesBuilder attributes, + Context parentContext, + ElasticTransportRequest transportRequest) { + super.onStart(attributes, parentContext, transportRequest); Object request = transportRequest.getRequest(); if (request instanceof DocWriteRequest) { diff --git a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportExperimentalAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportExperimentalAttributesExtractor.java index f2b8a1811e9e..336329e6dfac 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportExperimentalAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/Elasticsearch6TransportExperimentalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.v6_0; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticTransportRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.transport.ElasticsearchTransportExperimentalAttributesExtractor; import org.elasticsearch.action.DocWriteRequest; @@ -14,8 +15,11 @@ public class Elasticsearch6TransportExperimentalAttributesExtractor extends ElasticsearchTransportExperimentalAttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, ElasticTransportRequest transportRequest) { - super.onStart(attributes, transportRequest); + public void onStart( + AttributesBuilder attributes, + Context parentContext, + ElasticTransportRequest transportRequest) { + super.onStart(attributes, parentContext, transportRequest); Object request = transportRequest.getRequest(); if (request instanceof DocWriteRequest) { diff --git a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportExperimentalAttributesExtractor.java b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportExperimentalAttributesExtractor.java index 6262df2498ba..0afda0d10773 100644 --- a/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportExperimentalAttributesExtractor.java +++ b/instrumentation/elasticsearch/elasticsearch-transport-common/library/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/ElasticsearchTransportExperimentalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.elasticsearch.transport; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import org.elasticsearch.action.ActionResponse; @@ -21,7 +22,10 @@ public class ElasticsearchTransportExperimentalAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, ElasticTransportRequest transportRequest) { + public void onStart( + AttributesBuilder attributes, + Context parentContext, + ElasticTransportRequest transportRequest) { Object request = transportRequest.getRequest(); attributes.put("elasticsearch.action", transportRequest.getAction().getClass().getSimpleName()); attributes.put("elasticsearch.request", request.getClass().getSimpleName()); @@ -45,8 +49,9 @@ public void onStart(AttributesBuilder attributes, ElasticTransportRequest transp @Override public void onEnd( AttributesBuilder attributes, + Context context, ElasticTransportRequest request, - ActionResponse response, + @Nullable ActionResponse response, @Nullable Throwable error) { if (response instanceof GetResponse) { GetResponse resp = (GetResponse) response; diff --git a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcAttributesExtractor.java b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcAttributesExtractor.java index a2c28b44f0e6..6de0bdd3baad 100644 --- a/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcAttributesExtractor.java +++ b/instrumentation/grpc-1.6/library/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/GrpcAttributesExtractor.java @@ -7,19 +7,22 @@ import io.grpc.Status; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; final class GrpcAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, GrpcRequest grpcRequest) { + public void onStart( + AttributesBuilder attributes, Context parentContext, GrpcRequest grpcRequest) { // No request attributes } @Override public void onEnd( AttributesBuilder attributes, + Context context, GrpcRequest request, @Nullable Status status, @Nullable Throwable error) { diff --git a/instrumentation/hibernate/hibernate-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hibernate/HibernateExperimentalAttributesExtractor.java b/instrumentation/hibernate/hibernate-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hibernate/HibernateExperimentalAttributesExtractor.java index e576ca0f3c9f..9d4790ec5e07 100644 --- a/instrumentation/hibernate/hibernate-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hibernate/HibernateExperimentalAttributesExtractor.java +++ b/instrumentation/hibernate/hibernate-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hibernate/HibernateExperimentalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.hibernate; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; @@ -13,7 +14,8 @@ class HibernateExperimentalAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, HibernateOperation hibernateOperation) { + public void onStart( + AttributesBuilder attributes, Context parentContext, HibernateOperation hibernateOperation) { String sessionId = hibernateOperation.getSessionId(); if (sessionId != null) { attributes.put("hibernate.session_id", sessionId); @@ -23,6 +25,7 @@ public void onStart(AttributesBuilder attributes, HibernateOperation hibernateOp @Override public void onEnd( AttributesBuilder attributes, + Context context, HibernateOperation hibernateOperation, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/hystrix-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hystrix/ExperimentalAttributesExtractor.java b/instrumentation/hystrix-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hystrix/ExperimentalAttributesExtractor.java index 190e51605fd1..c7d6ff1a45b9 100644 --- a/instrumentation/hystrix-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hystrix/ExperimentalAttributesExtractor.java +++ b/instrumentation/hystrix-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/hystrix/ExperimentalAttributesExtractor.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; @@ -20,7 +21,8 @@ final class ExperimentalAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, HttpServletRequest request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, HttpServletRequest request) { if (!CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { return; } @@ -81,6 +83,7 @@ public void onStart(AttributesBuilder attributes, HttpServletRequest request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, HttpServletRequest httpServletRequest, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspCompilationContextInstrumentationSingletons.java b/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspCompilationContextInstrumentationSingletons.java index 624458be151b..b6a698b7078b 100644 --- a/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspCompilationContextInstrumentationSingletons.java +++ b/instrumentation/jsp-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsp/JspCompilationContextInstrumentationSingletons.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; @@ -46,11 +47,14 @@ private static class CompilationAttributesExtractor @Override public void onStart( - AttributesBuilder attributes, JspCompilationContext jspCompilationContext) {} + AttributesBuilder attributes, + Context parentContext, + JspCompilationContext jspCompilationContext) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, JspCompilationContext jspCompilationContext, @Nullable Void unused, @Nullable Throwable error) { diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerAdditionalAttributesExtractor.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerAdditionalAttributesExtractor.java index 56864baeefb9..4a346b4e12dd 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerAdditionalAttributesExtractor.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerAdditionalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.kafka.internal; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -14,7 +15,8 @@ public final class KafkaConsumerAdditionalAttributesExtractor implements AttributesExtractor, Void> { @Override - public void onStart(AttributesBuilder attributes, ConsumerRecord consumerRecord) { + public void onStart( + AttributesBuilder attributes, Context parentContext, ConsumerRecord consumerRecord) { set( attributes, SemanticAttributes.MESSAGING_KAFKA_PARTITION, @@ -27,6 +29,7 @@ public void onStart(AttributesBuilder attributes, ConsumerRecord consumerR @Override public void onEnd( AttributesBuilder attributes, + Context context, ConsumerRecord consumerRecord, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerExperimentalAttributesExtractor.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerExperimentalAttributesExtractor.java index cb433c97bbf6..c3bd60e4ac54 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerExperimentalAttributesExtractor.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaConsumerExperimentalAttributesExtractor.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; @@ -30,7 +31,8 @@ public static boolean isEnabled() { } @Override - public void onStart(AttributesBuilder attributes, ConsumerRecord consumerRecord) { + public void onStart( + AttributesBuilder attributes, Context parentContext, ConsumerRecord consumerRecord) { set(attributes, KAFKA_OFFSET, consumerRecord.offset()); // don't record a duration if the message was sent from an old Kafka client @@ -48,6 +50,7 @@ public void onStart(AttributesBuilder attributes, ConsumerRecord consumerR @Override public void onEnd( AttributesBuilder attributes, + Context context, ConsumerRecord consumerRecord, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaProducerAdditionalAttributesExtractor.java b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaProducerAdditionalAttributesExtractor.java index 2184f14a4d2b..e949270267c3 100644 --- a/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaProducerAdditionalAttributesExtractor.java +++ b/instrumentation/kafka/kafka-clients/kafka-clients-common/library/src/main/java/io/opentelemetry/instrumentation/kafka/internal/KafkaProducerAdditionalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.kafka.internal; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -14,7 +15,8 @@ public final class KafkaProducerAdditionalAttributesExtractor implements AttributesExtractor, Void> { @Override - public void onStart(AttributesBuilder attributes, ProducerRecord producerRecord) { + public void onStart( + AttributesBuilder attributes, Context parentContext, ProducerRecord producerRecord) { Integer partition = producerRecord.partition(); if (partition != null) { set(attributes, SemanticAttributes.MESSAGING_KAFKA_PARTITION, partition.longValue()); @@ -27,6 +29,7 @@ public void onStart(AttributesBuilder attributes, ProducerRecord producerR @Override public void onEnd( AttributesBuilder attributes, + Context context, ProducerRecord producerRecord, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesExperimentalAttributesExtractor.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesExperimentalAttributesExtractor.java index bd8e79a2d2c3..75834b121bcc 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesExperimentalAttributesExtractor.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesExperimentalAttributesExtractor.java @@ -7,6 +7,7 @@ import io.kubernetes.client.openapi.ApiResponse; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import okhttp3.Request; @@ -14,7 +15,7 @@ class KubernetesExperimentalAttributesExtractor implements AttributesExtractor> { @Override - public void onStart(AttributesBuilder attributes, Request request) { + public void onStart(AttributesBuilder attributes, Context parentContext, Request request) { KubernetesRequestDigest digest = KubernetesRequestDigest.parse(request); attributes .put("kubernetes-client.namespace", digest.getResourceMeta().getNamespace()) @@ -24,6 +25,7 @@ public void onStart(AttributesBuilder attributes, Request request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, Request request, @Nullable ApiResponse apiResponse, @Nullable Throwable error) {} diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java index 66579e6644b6..cb669ddc2da2 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectAttributesExtractor.java @@ -7,6 +7,7 @@ import com.lambdaworks.redis.RedisURI; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -14,7 +15,7 @@ final class LettuceConnectAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, RedisURI redisUri) { + public void onStart(AttributesBuilder attributes, Context parentContext, RedisURI redisUri) { attributes.put(SemanticAttributes.DB_SYSTEM, SemanticAttributes.DbSystemValues.REDIS); int database = redisUri.getDatabase(); @@ -25,5 +26,9 @@ public void onStart(AttributesBuilder attributes, RedisURI redisUri) { @Override public void onEnd( - AttributesBuilder attributes, RedisURI redisUri, Void unused, @Nullable Throwable error) {} + AttributesBuilder attributes, + Context context, + RedisURI redisUri, + Void unused, + @Nullable Throwable error) {} } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java index 45262559e6da..6ad11a37a72c 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceConnectAttributesExtractor.java @@ -7,6 +7,7 @@ import io.lettuce.core.RedisURI; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -14,7 +15,7 @@ final class LettuceConnectAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, RedisURI redisUri) { + public void onStart(AttributesBuilder attributes, Context parentContext, RedisURI redisUri) { attributes.put(SemanticAttributes.DB_SYSTEM, SemanticAttributes.DbSystemValues.REDIS); int database = redisUri.getDatabase(); @@ -25,5 +26,9 @@ public void onStart(AttributesBuilder attributes, RedisURI redisUri) { @Override public void onEnd( - AttributesBuilder attributes, RedisURI redisUri, Void unused, @Nullable Throwable error) {} + AttributesBuilder attributes, + Context context, + RedisURI redisUri, + Void unused, + @Nullable Throwable error) {} } diff --git a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java index 2a010614bd34..c96240f0f01d 100644 --- a/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java +++ b/instrumentation/lettuce/lettuce-5.1/library/src/main/java/io/opentelemetry/instrumentation/lettuce/v5_1/OpenTelemetryTracing.java @@ -155,7 +155,7 @@ private OpenTelemetrySpan nextSpan(Context context) { .setSpanKind(SpanKind.CLIENT) .setParent(context) .setAttribute(SemanticAttributes.DB_SYSTEM, DbSystemValues.REDIS); - return new OpenTelemetrySpan(spanBuilder); + return new OpenTelemetrySpan(context, spanBuilder); } } @@ -164,19 +164,18 @@ private OpenTelemetrySpan nextSpan(Context context) { // particularly safe, synchronizing all accesses. Relying on implementation details would allow // reducing synchronization but the impact should be minimal. private static class OpenTelemetrySpan extends Tracer.Span { + + private final Context context; private final SpanBuilder spanBuilder; @Nullable private String name; - @Nullable private List events; - @Nullable private Throwable error; - @Nullable private Span span; - @Nullable private String args; - OpenTelemetrySpan(SpanBuilder spanBuilder) { + OpenTelemetrySpan(Context context, SpanBuilder spanBuilder) { + this.context = context; this.spanBuilder = spanBuilder; } @@ -194,11 +193,22 @@ public synchronized Tracer.Span name(String name) { @Override public synchronized Tracer.Span remoteEndpoint(Endpoint endpoint) { if (endpoint instanceof OpenTelemetryEndpoint) { - fillEndpoint(span, spanBuilder, (OpenTelemetryEndpoint) endpoint); + fillEndpoint((OpenTelemetryEndpoint) endpoint); } return this; } + private void fillEndpoint(OpenTelemetryEndpoint endpoint) { + AttributesBuilder attributesBuilder = Attributes.builder(); + Context currentContext = span == null ? context : context.with(span); + netAttributesExtractor.onEnd(attributesBuilder, currentContext, endpoint, null, null); + if (span != null) { + span.setAllAttributes(attributesBuilder.build()); + } else { + spanBuilder.setAllAttributes(attributesBuilder.build()); + } + } + // Added and called in 6.0+ // @Override public synchronized Tracer.Span start(RedisCommand command) { @@ -314,15 +324,4 @@ private void finish(Span span) { span.end(); } } - - private static void fillEndpoint( - @Nullable Span span, SpanBuilder spanBuilder, OpenTelemetryEndpoint endpoint) { - AttributesBuilder attributesBuilder = Attributes.builder(); - netAttributesExtractor.onEnd(attributesBuilder, endpoint, null, null); - if (span != null) { - span.setAllAttributes(attributesBuilder.build()); - } else { - spanBuilder.setAllAttributes(attributesBuilder.build()); - } - } } diff --git a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java index 52b095282bfc..40c731426833 100644 --- a/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java +++ b/instrumentation/mongo/mongo-3.1/library/src/main/java/io/opentelemetry/instrumentation/mongo/v3_1/MongoAttributesExtractor.java @@ -10,6 +10,7 @@ import com.mongodb.event.CommandStartedEvent; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import java.util.HashSet; import java.util.Set; @@ -18,13 +19,15 @@ class MongoAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, CommandStartedEvent event) { + public void onStart( + AttributesBuilder attributes, Context parentContext, CommandStartedEvent event) { set(attributes, DB_MONGODB_COLLECTION, collectionName(event)); } @Override public void onEnd( AttributesBuilder attributes, + Context context, CommandStartedEvent event, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExperimentalAttributesExtractor.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExperimentalAttributesExtractor.java index b124621a0709..d091737faa25 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExperimentalAttributesExtractor.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExperimentalAttributesExtractor.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import java.util.Date; import javax.annotation.Nullable; @@ -19,7 +20,8 @@ class RabbitDeliveryExperimentalAttributesExtractor AttributeKey.longKey("rabbitmq.record.queue_time_ms"); @Override - public void onStart(AttributesBuilder attributes, DeliveryRequest request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, DeliveryRequest request) { Date timestamp = request.getProperties().getTimestamp(); if (timestamp != null) { // this will be set if the sender sets the timestamp, @@ -37,6 +39,7 @@ public void onStart(AttributesBuilder attributes, DeliveryRequest request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, DeliveryRequest request, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExtraAttributesExtractor.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExtraAttributesExtractor.java index 7042b2d13207..b1ca8d2044fa 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExtraAttributesExtractor.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitDeliveryExtraAttributesExtractor.java @@ -7,6 +7,7 @@ import com.rabbitmq.client.Envelope; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; @@ -14,7 +15,8 @@ class RabbitDeliveryExtraAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, DeliveryRequest request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, DeliveryRequest request) { Envelope envelope = request.getEnvelope(); String routingKey = envelope.getRoutingKey(); if (routingKey != null && !routingKey.isEmpty()) { @@ -25,6 +27,7 @@ public void onStart(AttributesBuilder attributes, DeliveryRequest request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, DeliveryRequest request, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveExperimentalAttributesExtractor.java b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveExperimentalAttributesExtractor.java index ff39df98b735..8163f0554a99 100644 --- a/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveExperimentalAttributesExtractor.java +++ b/instrumentation/rabbitmq-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/RabbitReceiveExperimentalAttributesExtractor.java @@ -10,6 +10,7 @@ import com.rabbitmq.client.GetResponse; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; @@ -19,7 +20,8 @@ class RabbitReceiveExperimentalAttributesExtractor AttributeKey.stringKey("rabbitmq.queue"); @Override - public void onStart(AttributesBuilder attributes, ReceiveRequest receiveRequest) { + public void onStart( + AttributesBuilder attributes, Context parentContext, ReceiveRequest receiveRequest) { set(attributes, RABBITMQ_COMMAND, "basic.get"); set(attributes, RABBITMQ_QUEUE, receiveRequest.getQueue()); } @@ -27,6 +29,7 @@ public void onStart(AttributesBuilder attributes, ReceiveRequest receiveRequest) @Override public void onEnd( AttributesBuilder attributes, + Context context, ReceiveRequest receiveRequest, @Nullable GetResponse response, @Nullable Throwable error) {} diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerExperimentalAttributeExtractor.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerExperimentalAttributeExtractor.java index 0c2110004d26..360af86a0467 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerExperimentalAttributeExtractor.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqConsumerExperimentalAttributeExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import org.apache.rocketmq.common.message.MessageExt; @@ -23,7 +24,7 @@ class RockerMqConsumerExperimentalAttributeExtractor AttributeKey.stringKey("messaging.rocketmq.broker_address"); @Override - public void onStart(AttributesBuilder attributes, MessageExt msg) { + public void onStart(AttributesBuilder attributes, Context parentContext, MessageExt msg) { set(attributes, MESSAGING_ROCKETMQ_TAGS, msg.getTags()); set(attributes, MESSAGING_ROCKETMQ_QUEUE_ID, (long) msg.getQueueId()); set(attributes, MESSAGING_ROCKETMQ_QUEUE_OFFSET, msg.getQueueOffset()); @@ -42,6 +43,7 @@ private static String getBrokerHost(MessageExt msg) { @Override public void onEnd( AttributesBuilder attributes, + Context context, MessageExt consumeMessageContext, @Nullable Void unused, @Nullable Throwable error) {} diff --git a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java index 3578cebbbc3f..138b334fbf71 100644 --- a/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java +++ b/instrumentation/rocketmq-client-4.8/library/src/main/java/io/opentelemetry/instrumentation/rocketmq/RockerMqProducerExperimentalAttributeExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import org.apache.rocketmq.client.hook.SendMessageContext; @@ -21,7 +22,8 @@ class RockerMqProducerExperimentalAttributeExtractor AttributeKey.stringKey("messaging.rocketmq.send_result"); @Override - public void onStart(AttributesBuilder attributes, SendMessageContext request) { + public void onStart( + AttributesBuilder attributes, Context parentContext, SendMessageContext request) { if (request.getMessage() != null) { set(attributes, MESSAGING_ROCKETMQ_TAGS, request.getMessage().getTags()); } @@ -31,6 +33,7 @@ public void onStart(AttributesBuilder attributes, SendMessageContext request) { @Override public void onEnd( AttributesBuilder attributes, + Context context, SendMessageContext request, @Nullable Void unused, @Nullable Throwable error) { diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAdditionalAttributesExtractor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAdditionalAttributesExtractor.java index c4430c0f8995..17f4a7124124 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAdditionalAttributesExtractor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletAdditionalAttributesExtractor.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -30,11 +31,14 @@ public ServletAdditionalAttributesExtractor(ServletAccessor a @Override public void onStart( - AttributesBuilder attributes, ServletRequestContext requestContext) {} + AttributesBuilder attributes, + Context parentContext, + ServletRequestContext requestContext) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, ServletRequestContext requestContext, @Nullable ServletResponseContext responseContext, @Nullable Throwable error) { diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java index 7b30071af387..887ac17ddcbd 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletRequestParametersExtractor.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.config.Config; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import java.util.List; @@ -51,11 +52,14 @@ public void setAttributes( @Override public void onStart( - AttributesBuilder attributes, ServletRequestContext requestContext) {} + AttributesBuilder attributes, + Context parentContext, + ServletRequestContext requestContext) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, ServletRequestContext requestContext, @Nullable ServletResponseContext responseContext, @Nullable Throwable error) { diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/ExperimentalAttributesExtractor.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/ExperimentalAttributesExtractor.java index 15798bb8c468..cc17d22442d1 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/ExperimentalAttributesExtractor.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/server/ExperimentalAttributesExtractor.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; import org.springframework.web.method.HandlerMethod; @@ -17,13 +18,14 @@ public class ExperimentalAttributesExtractor implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, HttpServletRequest httpServletRequest) {} + public void onStart( + AttributesBuilder attributes, Context parentContext, HttpServletRequest httpServletRequest) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, HttpServletRequest httpServletRequest, @Nullable HttpServletResponse response, @Nullable Throwable error) { diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatAdditionalAttributesExtractor.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatAdditionalAttributesExtractor.java index 28c6b76a21c0..81738102759a 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatAdditionalAttributesExtractor.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatAdditionalAttributesExtractor.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.common; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.javaagent.instrumentation.servlet.ServletAccessor; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @@ -27,11 +28,12 @@ public TomcatAdditionalAttributesExtractor( } @Override - public void onStart(AttributesBuilder attributes, Request request) {} + public void onStart(AttributesBuilder attributes, Context parentContext, Request request) {} @Override public void onEnd( AttributesBuilder attributes, + Context context, Request request, @Nullable Response response, @Nullable Throwable error) { diff --git a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioExperimentalAttributesExtractor.java b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioExperimentalAttributesExtractor.java index d30f7df3ba1a..191ae31fb540 100644 --- a/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioExperimentalAttributesExtractor.java +++ b/instrumentation/twilio-6.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioExperimentalAttributesExtractor.java @@ -10,6 +10,7 @@ import com.twilio.rest.api.v2010.account.Call; import com.twilio.rest.api.v2010.account.Message; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import java.lang.reflect.Method; import java.util.concurrent.TimeUnit; @@ -23,11 +24,15 @@ class TwilioExperimentalAttributesExtractor implements AttributesExtractor