Skip to content

Commit

Permalink
Upgrade OTEL to v1.39.0 in integration tests (#1064)
Browse files Browse the repository at this point in the history
* Upgrading OTEL to 1.39.0

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

* Revert timeout for GRPC health

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

---------

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>
Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
  • Loading branch information
artur-ciocanu and Artur Ciocanu authored Jul 1, 2024
1 parent 9afbc3c commit a0ee8d1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
20 changes: 18 additions & 2 deletions sdk-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<protobuf.input.directory>${project.basedir}/proto</protobuf.input.directory>
<grpc.version>1.59.0</grpc.version>
<protobuf.version>3.17.3</protobuf.version>
<opentelemetry.version>0.14.0</opentelemetry.version>
<opentelemetry.version>1.39.0</opentelemetry.version>
<spring-boot.version>3.0.13</spring-boot.version>
</properties>

Expand Down Expand Up @@ -103,7 +103,12 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-metrics</artifactId>
<version>${opentelemetry.version}-alpha</version>
<version>${opentelemetry.version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-common</artifactId>
<version>${opentelemetry.version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
Expand All @@ -115,6 +120,17 @@
<artifactId>opentelemetry-exporter-zipkin</artifactId>
<version>${opentelemetry.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.zipkin.reporter2/zipkin-reporter -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-okhttp3</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk</artifactId>
Expand Down
23 changes: 9 additions & 14 deletions sdk-tests/src/test/java/io/dapr/it/tracing/OpenTelemetry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -54,28 +49,28 @@ 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());
}

/**
* Converts given OpenTelemetry's context into Reactor's context.
* @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<String, String> map = new HashMap<>();
TextMapPropagator.Setter<Map<String, String>> setter =
(carrier, key, value) -> map.put(key, value);
TextMapSetter<Map<String, String>> 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<String, String> entry : map.entrySet()) {
reactorContext = reactorContext.put(entry.getKey(), entry.getValue());
Expand Down
15 changes: 7 additions & 8 deletions sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<HttpServletRequest> 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<HttpServletRequest> JAKARTA_HTTP_SERVLET_REQUEST_GETTER =
new TextMapGetter<>() {
@Override
public Iterable<String> keys(HttpServletRequest carrier) {
return Collections.list(carrier.getHeaderNames());
Expand Down Expand Up @@ -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<javax.servlet.http.HttpServletRequest> 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<javax.servlet.http.HttpServletRequest> JAVA_HTTP_SERVLET_REQUEST_GETTER =
new TextMapGetter<>() {
@Override
public Iterable<String> keys(javax.servlet.http.HttpServletRequest carrier) {
return Collections.list(carrier.getHeaderNames());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public class OpenTelemetryInterceptorConfig extends WebMvcConfigurationSupport {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor);
}
}

}
15 changes: 7 additions & 8 deletions sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit a0ee8d1

Please sign in to comment.