From 927cc13feebc7df74abc85b06a0766835d7ca171 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 19 Sep 2023 17:09:15 +0100 Subject: [PATCH] Update OTel to 1.29 --- examples/agent/pom.xml | 4 +- examples/library/pom.xml | 6 +- .../cdi/OpenTelemetryProducer.java | 3 +- .../META-INF/microprofile-config.properties | 3 +- .../cdi/WithSpanInterceptorTest.java | 2 - .../rest/OpenTelemetryClientFilter.java | 59 +++++------------- .../rest/OpenTelemetryServerFilter.java | 62 +++++++++---------- pom.xml | 6 +- .../test/ArquillianLifecycle.java | 2 - .../test/HttpServerAttributesFilter.java | 6 +- testsuite/pom.xml | 2 +- testsuite/tck/pom.xml | 2 +- .../tck/ArquillianLifecycle.java | 2 - 13 files changed, 61 insertions(+), 98 deletions(-) diff --git a/examples/agent/pom.xml b/examples/agent/pom.xml index faaa6756..facb2380 100644 --- a/examples/agent/pom.xml +++ b/examples/agent/pom.xml @@ -22,9 +22,9 @@ 5.1.0.Final 6.2.2.Final - 3.1.1 + 3.3.4 - 1.26.0 + 1.29.0 diff --git a/examples/library/pom.xml b/examples/library/pom.xml index cca62f1a..32b68e16 100644 --- a/examples/library/pom.xml +++ b/examples/library/pom.xml @@ -22,10 +22,10 @@ 5.1.0.Final 6.2.2.Final - 3.1.1 + 3.3.4 - 1.26.0 - 1.26.0 + 1.29.0 + 1.29.0 diff --git a/implementation/cdi/src/main/java/io/smallrye/opentelemetry/implementation/cdi/OpenTelemetryProducer.java b/implementation/cdi/src/main/java/io/smallrye/opentelemetry/implementation/cdi/OpenTelemetryProducer.java index 0a6d6d9d..eebc06b2 100644 --- a/implementation/cdi/src/main/java/io/smallrye/opentelemetry/implementation/cdi/OpenTelemetryProducer.java +++ b/implementation/cdi/src/main/java/io/smallrye/opentelemetry/implementation/cdi/OpenTelemetryProducer.java @@ -47,8 +47,7 @@ public OpenTelemetry getOpenTelemetry() { } return builder - .setResultAsGlobal(false) - .registerShutdownHook(false) + .disableShutdownHook() .addPropertiesSupplier(() -> config.properties()) .build() .getOpenTelemetrySdk(); diff --git a/implementation/cdi/src/main/resources/META-INF/microprofile-config.properties b/implementation/cdi/src/main/resources/META-INF/microprofile-config.properties index f087573b..92fe36b1 100644 --- a/implementation/cdi/src/main/resources/META-INF/microprofile-config.properties +++ b/implementation/cdi/src/main/resources/META-INF/microprofile-config.properties @@ -1,2 +1,3 @@ -# We don't support metrics yet. Only Tracing. +# We don't support metrics or logging yet. Only Tracing. otel.metrics.exporter=none +otel.logs.exporter=none diff --git a/implementation/cdi/src/test/java/io/smallrye/opentelemetry/implementation/cdi/WithSpanInterceptorTest.java b/implementation/cdi/src/test/java/io/smallrye/opentelemetry/implementation/cdi/WithSpanInterceptorTest.java index 96accc9a..a5865b47 100644 --- a/implementation/cdi/src/test/java/io/smallrye/opentelemetry/implementation/cdi/WithSpanInterceptorTest.java +++ b/implementation/cdi/src/test/java/io/smallrye/opentelemetry/implementation/cdi/WithSpanInterceptorTest.java @@ -17,7 +17,6 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.opentelemetry.instrumentation.annotations.SpanAttribute; import io.opentelemetry.instrumentation.annotations.WithSpan; import io.opentelemetry.sdk.trace.data.SpanData; @@ -37,7 +36,6 @@ class WithSpanInterceptorTest { void setUp() { spanExporter.reset(); GlobalOpenTelemetry.resetForTest(); - GlobalLoggerProvider.resetForTest(); } @Test diff --git a/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryClientFilter.java b/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryClientFilter.java index 37769599..0c7a02eb 100644 --- a/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryClientFilter.java +++ b/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryClientFilter.java @@ -24,8 +24,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesGetter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @Provider public class OpenTelemetryClientFilter implements ClientRequestFilter, ClientResponseFilter { @@ -48,8 +46,7 @@ public OpenTelemetryClientFilter(final OpenTelemetry openTelemetry) { this.instrumenter = builder .setSpanStatusExtractor(HttpSpanStatusExtractor.create(clientAttributesExtractor)) - .addAttributesExtractor( - HttpClientAttributesExtractor.create(clientAttributesExtractor, new NetClientAttributesExtractor())) + .addAttributesExtractor(HttpClientAttributesExtractor.create(clientAttributesExtractor)) .buildClientInstrumenter(new ClientRequestContextTextMapSetter()); } @@ -103,68 +100,40 @@ private static class ClientAttributesExtractor implements HttpClientAttributesGetter { @Override - public String getUrl(final ClientRequestContext request) { + public String getUrlFull(final ClientRequestContext request) { return request.getUri().toString(); } @Override - public String getMethod(final ClientRequestContext request) { - return request.getMethod(); - } - - @Override - public List getRequestHeader(final ClientRequestContext request, final String name) { - return request.getStringHeaders().getOrDefault(name, emptyList()); - } - - @Override - public Integer getStatusCode(final ClientRequestContext request, final ClientResponseContext response, - final Throwable throwable) { - return response.getStatus(); - } - - @Override - public List getResponseHeader(final ClientRequestContext request, final ClientResponseContext response, - final String name) { - return response.getHeaders().getOrDefault(name, emptyList()); - } - } - - private static class NetClientAttributesExtractor - implements NetClientAttributesGetter { - @Override - public String getTransport(final ClientRequestContext request, final ClientResponseContext response) { - return SemanticAttributes.NetTransportValues.IP_TCP; - } - - @Override - public String getPeerName(final ClientRequestContext request) { + public String getServerAddress(final ClientRequestContext request) { return request.getUri().getHost(); } @Override - public Integer getPeerPort(final ClientRequestContext request) { + public Integer getServerPort(final ClientRequestContext request) { return request.getUri().getPort(); } @Override - public String getSockFamily(final ClientRequestContext request, final ClientResponseContext response) { - return null; + public String getHttpRequestMethod(final ClientRequestContext request) { + return request.getMethod(); } @Override - public String getSockPeerAddr(final ClientRequestContext request, final ClientResponseContext response) { - return null; + public List getHttpRequestHeader(final ClientRequestContext request, final String name) { + return request.getStringHeaders().getOrDefault(name, emptyList()); } @Override - public String getSockPeerName(final ClientRequestContext request, final ClientResponseContext response) { - return null; + public Integer getHttpResponseStatusCode(final ClientRequestContext request, final ClientResponseContext response, + final Throwable throwable) { + return response.getStatus(); } @Override - public Integer getSockPeerPort(final ClientRequestContext request, final ClientResponseContext response) { - return null; + public List getHttpResponseHeader(final ClientRequestContext request, final ClientResponseContext response, + final String name) { + return response.getHeaders().getOrDefault(name, emptyList()); } } } diff --git a/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryServerFilter.java b/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryServerFilter.java index 142bad1c..6859c716 100644 --- a/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryServerFilter.java +++ b/implementation/rest/src/main/java/io/smallrye/opentelemetry/implementation/rest/OpenTelemetryServerFilter.java @@ -30,8 +30,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter; -import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @Provider @@ -58,7 +56,7 @@ public OpenTelemetryServerFilter(final OpenTelemetry openTelemetry) { this.instrumenter = builder .setSpanStatusExtractor(HttpSpanStatusExtractor.create(serverAttributesExtractor)) .addAttributesExtractor(io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor - .create(serverAttributesExtractor, new NetServerAttributesExtractor())) + .create(serverAttributesExtractor, new NetServerAttributesGetter())) .buildServerInstrumenter(new ContainerRequestContextTextMapGetter()); } @@ -119,30 +117,31 @@ public String get(final ContainerRequestContext carrier, final String key) { } } - private static class NetServerAttributesExtractor - extends InetSocketAddressNetServerAttributesGetter { + private static class NetServerAttributesGetter implements + io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter { @Override public String getTransport(final ContainerRequestContext request) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override - public String getProtocolName(final ContainerRequestContext request) { - return (String) request.getProperty(NetAttributes.NET_PROTOCOL_NAME.getKey()); + public String getNetworkProtocolName(final ContainerRequestContext request, final ContainerResponseContext response) { + return (String) request.getProperty(SemanticAttributes.NET_PROTOCOL_NAME.getKey()); } @Override - public String getProtocolVersion(final ContainerRequestContext request) { - return (String) request.getProperty(NetAttributes.NET_PROTOCOL_VERSION.getKey()); + public String getNetworkProtocolVersion(final ContainerRequestContext request, + final ContainerResponseContext response) { + return (String) request.getProperty(SemanticAttributes.NET_PROTOCOL_VERSION.getKey()); } @Override - public String getHostName(final ContainerRequestContext request) { + public String getServerAddress(final ContainerRequestContext request) { return request.getUriInfo().getRequestUri().getHost(); } @Override - public Integer getHostPort(final ContainerRequestContext request) { + public Integer getServerPort(final ContainerRequestContext request) { URI uri = request.getUriInfo().getRequestUri(); if (uri.getPort() > 0) { return uri.getPort(); @@ -155,32 +154,32 @@ public Integer getHostPort(final ContainerRequestContext request) { } @Override - protected InetSocketAddress getPeerSocketAddress(final ContainerRequestContext request) { + public InetSocketAddress getServerInetSocketAddress(final ContainerRequestContext request, + final ContainerResponseContext response) { + String serverAddress = getServerAddress(request); + Integer serverPort = getServerPort(request); + if (serverAddress != null && serverPort != null) { + return new InetSocketAddress(serverAddress, serverPort); + } return null; } - - @Override - protected InetSocketAddress getHostSocketAddress(final ContainerRequestContext request) { - return new InetSocketAddress(getHostName(request), getHostPort(request)); - } } private static class HttpServerAttributesExtractor implements HttpServerAttributesGetter { @Override - public String getTarget(final ContainerRequestContext request) { - URI requestUri = request.getUriInfo().getRequestUri(); - String path = requestUri.getPath(); - String query = requestUri.getQuery(); - if (path != null && query != null && !query.isEmpty()) { - return path + "?" + query; - } - return path; + public String getUrlPath(final ContainerRequestContext request) { + return request.getUriInfo().getRequestUri().getPath(); + } + + @Override + public String getUrlQuery(final ContainerRequestContext request) { + return request.getUriInfo().getRequestUri().getQuery(); } @Override - public String getRoute(final ContainerRequestContext request) { + public String getHttpRoute(final ContainerRequestContext request) { try { // This can throw an IllegalArgumentException when determining the route for a subresource Class resource = (Class) request.getProperty("rest.resource.class"); @@ -203,28 +202,29 @@ public String getRoute(final ContainerRequestContext request) { } @Override - public String getScheme(final ContainerRequestContext request) { + public String getUrlScheme(final ContainerRequestContext request) { return request.getUriInfo().getRequestUri().getScheme(); } @Override - public String getMethod(final ContainerRequestContext request) { + public String getHttpRequestMethod(final ContainerRequestContext request) { return request.getMethod(); } @Override - public List getRequestHeader(final ContainerRequestContext request, final String name) { + public List getHttpRequestHeader(final ContainerRequestContext request, final String name) { return request.getHeaders().getOrDefault(name, emptyList()); } @Override - public Integer getStatusCode(final ContainerRequestContext request, final ContainerResponseContext response, + public Integer getHttpResponseStatusCode(final ContainerRequestContext request, final ContainerResponseContext response, final Throwable throwable) { return response.getStatus(); } @Override - public List getResponseHeader(final ContainerRequestContext request, final ContainerResponseContext response, + public List getHttpResponseHeader(final ContainerRequestContext request, + final ContainerResponseContext response, final String name) { return response.getStringHeaders().getOrDefault(name, emptyList()); } diff --git a/pom.xml b/pom.xml index 9176b3b4..abad99a6 100644 --- a/pom.xml +++ b/pom.xml @@ -15,13 +15,13 @@ http://smallrye.io - 1.26.0 + 1.29.0 1.0 - 3.0.2 + 3.0.3 2.3.0 - 3.1.3 + 3.3.4 diff --git a/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/ArquillianLifecycle.java b/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/ArquillianLifecycle.java index ba6a8f27..845c2b34 100644 --- a/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/ArquillianLifecycle.java +++ b/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/ArquillianLifecycle.java @@ -11,13 +11,11 @@ import org.jboss.arquillian.test.spi.TestClass; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.api.logs.GlobalLoggerProvider; import io.restassured.RestAssured; public class ArquillianLifecycle { public void beforeDeploy(@Observes BeforeDeploy event, TestClass testClass) { GlobalOpenTelemetry.resetForTest(); - GlobalLoggerProvider.resetForTest(); } @Inject diff --git a/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/HttpServerAttributesFilter.java b/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/HttpServerAttributesFilter.java index aefbaa1c..094cec90 100644 --- a/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/HttpServerAttributesFilter.java +++ b/testsuite/extra/src/test/java/io/smallrye/opentelemetry/test/HttpServerAttributesFilter.java @@ -9,7 +9,7 @@ import jakarta.ws.rs.core.Context; import jakarta.ws.rs.ext.Provider; -import io.opentelemetry.instrumentation.api.instrumenter.net.internal.NetAttributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; @Provider @PreMatching @@ -20,8 +20,8 @@ public class HttpServerAttributesFilter implements ContainerRequestFilter, Conta @Override public void filter(final ContainerRequestContext request) { String[] nameAndVersion = httpServletRequest.getProtocol().split("/"); - request.setProperty(NetAttributes.NET_PROTOCOL_NAME.getKey(), nameAndVersion[0]); - request.setProperty(NetAttributes.NET_PROTOCOL_VERSION.getKey(), nameAndVersion[1]); + request.setProperty(SemanticAttributes.NET_PROTOCOL_NAME.getKey(), nameAndVersion[0]); + request.setProperty(SemanticAttributes.NET_PROTOCOL_VERSION.getKey(), nameAndVersion[1]); } @Override diff --git a/testsuite/pom.xml b/testsuite/pom.xml index 840d6eb6..4ac7f5a7 100644 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -38,7 +38,7 @@ extra - diff --git a/testsuite/tck/pom.xml b/testsuite/tck/pom.xml index e94d117e..1838dc53 100644 --- a/testsuite/tck/pom.xml +++ b/testsuite/tck/pom.xml @@ -4,7 +4,7 @@ io.smallrye.opentelemetry smallrye-opentelemetry-testsuite - 2.3.1-SNAPSHOT + 2.4.1-SNAPSHOT smallrye-opentelemetry-tck diff --git a/testsuite/tck/src/test/java/io/smallrye/opentelemetry/tck/ArquillianLifecycle.java b/testsuite/tck/src/test/java/io/smallrye/opentelemetry/tck/ArquillianLifecycle.java index 351c28ff..22c8015b 100644 --- a/testsuite/tck/src/test/java/io/smallrye/opentelemetry/tck/ArquillianLifecycle.java +++ b/testsuite/tck/src/test/java/io/smallrye/opentelemetry/tck/ArquillianLifecycle.java @@ -5,11 +5,9 @@ import org.jboss.arquillian.test.spi.TestClass; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.api.logs.GlobalLoggerProvider; public class ArquillianLifecycle { public void beforeDeploy(@Observes BeforeDeploy event, TestClass testClass) { GlobalOpenTelemetry.resetForTest(); - GlobalLoggerProvider.resetForTest(); } }