diff --git a/sdk-tests/pom.xml b/sdk-tests/pom.xml index 609d6d5d8..0567b615a 100644 --- a/sdk-tests/pom.xml +++ b/sdk-tests/pom.xml @@ -20,7 +20,7 @@ ${project.basedir}/proto 1.59.0 3.17.3 - 0.14.0 + 1.39.0 3.0.13 @@ -103,7 +103,12 @@ io.opentelemetry opentelemetry-sdk-metrics - ${opentelemetry.version}-alpha + ${opentelemetry.version} + + + io.opentelemetry + opentelemetry-exporter-common + ${opentelemetry.version} io.opentelemetry @@ -115,6 +120,17 @@ opentelemetry-exporter-zipkin ${opentelemetry.version} + + + io.zipkin.reporter2 + zipkin-reporter + 3.4.0 + + + io.zipkin.reporter2 + zipkin-sender-okhttp3 + 3.4.0 + io.dapr dapr-sdk diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/OpenTelemetry.java b/sdk-tests/src/test/java/io/dapr/it/tracing/OpenTelemetry.java index bae97e7a6..08a6ea88f 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/OpenTelemetry.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/OpenTelemetry.java @@ -14,11 +14,10 @@ package io.dapr.it.tracing; import io.dapr.utils.NetworkUtils; -import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.trace.SdkTracerProvider; @@ -41,11 +40,7 @@ public class OpenTelemetry { public static io.opentelemetry.api.OpenTelemetry createOpenTelemetry(String serviceName) throws InterruptedException { waitForZipkin(); String httpUrl = String.format("http://localhost:%d", ZIPKIN_PORT); - ZipkinSpanExporter zipkinExporter = - ZipkinSpanExporter.builder() - .setEndpoint(httpUrl + ENDPOINT_V2_SPANS) - .setServiceName(serviceName) - .build(); + ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).build(); SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor(SimpleSpanProcessor.create(zipkinExporter)) @@ -54,15 +49,15 @@ public static io.opentelemetry.api.OpenTelemetry createOpenTelemetry(String serv return OpenTelemetrySdk.builder() .setTracerProvider(sdkTracerProvider) .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) - .buildAndRegisterGlobal(); + .build(); } /** * Converts current OpenTelemetry's context into Reactor's context. * @return Reactor's context. */ - public static reactor.util.context.Context getReactorContext() { - return getReactorContext(Context.current()); + public static reactor.util.context.Context getReactorContext(io.opentelemetry.api.OpenTelemetry openTelemetry) { + return getReactorContext(openTelemetry, Context.current()); } /** @@ -70,12 +65,12 @@ public static reactor.util.context.Context getReactorContext() { * @param context OpenTelemetry's context. * @return Reactor's context. */ - public static reactor.util.context.Context getReactorContext(Context context) { + public static reactor.util.context.Context getReactorContext(io.opentelemetry.api.OpenTelemetry openTelemetry, + Context context) { Map map = new HashMap<>(); - TextMapPropagator.Setter> setter = - (carrier, key, value) -> map.put(key, value); + TextMapSetter> setter = (carrier, key, value) -> map.put(key, value); - GlobalOpenTelemetry.getPropagators().getTextMapPropagator().inject(context, map, setter); + openTelemetry.getPropagators().getTextMapPropagator().inject(context, map, setter); reactor.util.context.Context reactorContext = reactor.util.context.Context.empty(); for (Map.Entry entry : map.entrySet()) { reactorContext = reactorContext.put(entry.getKey(), entry.getValue()); diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java b/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java index e1f4c729f..76df40044 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java @@ -9,9 +9,9 @@ import io.dapr.it.tracing.Validation; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Scope; -import io.opentelemetry.sdk.OpenTelemetrySdk; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,23 +42,22 @@ public void setup() throws Exception { @Test public void testInvoke() throws Exception { - final OpenTelemetry openTelemetry = createOpenTelemetry("service over grpc"); - final Tracer tracer = openTelemetry.getTracer("grpc integration test tracer"); - - final String spanName = UUID.randomUUID().toString(); - Span span = tracer.spanBuilder(spanName).setSpanKind(Span.Kind.CLIENT).startSpan(); + OpenTelemetry openTelemetry = createOpenTelemetry("service over grpc"); + Tracer tracer = openTelemetry.getTracer("grpc integration test tracer"); + String spanName = UUID.randomUUID().toString(); + Span span = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan(); try (DaprClient client = new DaprClientBuilder().build()) { client.waitForSidecar(10000).block(); try (Scope scope = span.makeCurrent()) { SleepRequest req = SleepRequest.newBuilder().setSeconds(1).build(); client.invokeMethod(daprRun.getAppName(), "sleepOverGRPC", req.toByteArray(), HttpExtension.POST) - .contextWrite(getReactorContext()) + .contextWrite(getReactorContext(openTelemetry)) .block(); } } + span.end(); - OpenTelemetrySdk.getGlobalTracerManagement().shutdown(); Validation.validate(spanName, "calllocal/tracingitgrpc-service/sleepovergrpc"); } diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java index 646a5f5a5..960dce888 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptor.java @@ -15,6 +15,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.context.Context; +import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; import jakarta.servlet.DispatcherType; import jakarta.servlet.http.HttpServletRequest; @@ -32,9 +33,9 @@ public class OpenTelemetryInterceptor implements HandlerInterceptor { @Autowired private OpenTelemetry openTelemetry; - // implmentation for springboot 3.0, which uses jakarta.servlet instead of javax.servlet - private static final TextMapPropagator.Getter JAKARTA_HTTP_SERVLET_REQUEST_GETTER = - new TextMapPropagator.Getter<>() { + // Implementation for springboot 3.0, which uses jakarta.servlet instead of javax.servlet + private static final TextMapGetter JAKARTA_HTTP_SERVLET_REQUEST_GETTER = + new TextMapGetter<>() { @Override public Iterable keys(HttpServletRequest carrier) { return Collections.list(carrier.getHeaderNames()); @@ -67,9 +68,9 @@ public void postHandle( } - // implmentation for springboot 3.0, which uses jakarta.servlet instead of javax.servlet - private static final TextMapPropagator.Getter JAVA_HTTP_SERVLET_REQUEST_GETTER = - new TextMapPropagator.Getter<>() { + // Implementation for springboot 3.0, which uses jakarta.servlet instead of javax.servlet + private static final TextMapGetter JAVA_HTTP_SERVLET_REQUEST_GETTER = + new TextMapGetter<>() { @Override public Iterable keys(javax.servlet.http.HttpServletRequest carrier) { return Collections.list(carrier.getHeaderNames()); diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java index ce2343013..fe2913649 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/http/OpenTelemetryInterceptorConfig.java @@ -28,4 +28,5 @@ public class OpenTelemetryInterceptorConfig extends WebMvcConfigurationSupport { public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(interceptor); } -} \ No newline at end of file + +} diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java index 8e28159f9..a4c75d140 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java @@ -8,9 +8,9 @@ import io.dapr.it.tracing.Validation; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Scope; -import io.opentelemetry.sdk.OpenTelemetrySdk; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,22 +41,21 @@ public void setup() throws Exception { @Test public void testInvoke() throws Exception { - final OpenTelemetry openTelemetry = createOpenTelemetry(OpenTelemetryConfig.SERVICE_NAME); - final Tracer tracer = openTelemetry.getTracer(OpenTelemetryConfig.TRACER_NAME); - - final String spanName = UUID.randomUUID().toString(); - Span span = tracer.spanBuilder(spanName).setSpanKind(Span.Kind.CLIENT).startSpan(); + OpenTelemetry openTelemetry = createOpenTelemetry(OpenTelemetryConfig.SERVICE_NAME); + Tracer tracer = openTelemetry.getTracer(OpenTelemetryConfig.TRACER_NAME); + String spanName = UUID.randomUUID().toString(); + Span span = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan(); try (DaprClient client = new DaprClientBuilder().build()) { client.waitForSidecar(10000).block(); try (Scope scope = span.makeCurrent()) { client.invokeMethod(daprRun.getAppName(), "sleep", 1, HttpExtension.POST) - .contextWrite(getReactorContext()) + .contextWrite(getReactorContext(openTelemetry)) .block(); } } + span.end(); - OpenTelemetrySdk.getGlobalTracerManagement().shutdown(); Validation.validate(spanName, "calllocal/tracingithttp-service/sleep"); }