Skip to content

Commit

Permalink
fix regressions from dev mode reload
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Dec 21, 2022
1 parent 1089e43 commit 68c6abb
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
import java.util.Set;
import java.util.function.Predicate;

import io.opentelemetry.api.OpenTelemetry;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.opentelemetry.deployment.tracing.TracerIdGeneratorBuildItem;
import io.quarkus.opentelemetry.deployment.tracing.TracerResourceBuildItem;
import io.quarkus.opentelemetry.deployment.tracing.TracerSamplerBuildItem;
import io.quarkus.opentelemetry.deployment.tracing.TracerSpanExportersBuildItem;
import io.quarkus.opentelemetry.deployment.tracing.TracerSpanProcessorsBuildItem;
import io.quarkus.opentelemetry.runtime.config.build.OtelBuildConfig;
import io.quarkus.opentelemetry.runtime.config.runtime.OtelRuntimeConfig;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.InstrumentationRecorder;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
Expand Down Expand Up @@ -193,11 +182,7 @@ void createOpenTelemetry(
RuntimeValue<OpenTelemetry> openTelemetry = recorder.createOpenTelemetry(shutdownContextBuildItem);

recorder.eagerlyCreateContextStorage();

// just checking for live reload would bypass the OpenTelemetryDevModeTest
if (launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) {
instrumentationRecorder.setTracerDevMode(instrumentationRecorder.createTracers());
}
recorder.storeVertxOnContextStorage(vertx.getVertx());

instrumentationRecorder.setTracerDevMode(instrumentationRecorder.createTracers(openTelemetry));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.grpc.GrpcTracingServerInterceptor;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.reactivemessaging.ReactiveMessagingTracingDecorator;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.restclient.OpenTelemetryClientFilter;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.vertx.core.deployment.VertxOptionsConsumerBuildItem;
import io.vertx.core.VertxOptions;

Expand Down Expand Up @@ -103,12 +102,13 @@ VertxOptionsConsumerBuildItem vertxTracingOptions(
InstrumentationRecorder recorder,
LaunchModeBuildItem launchMode) {
Consumer<VertxOptions> vertxTracingOptions;
if (launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) {
// tracers are set in the OpenTelemetryProcessor
vertxTracingOptions = recorder.getVertxTracingOptionsDevMode();
} else {
vertxTracingOptions = recorder.getVertxTracingOptionsProd(recorder.createTracers());
}
// if (launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT) {
// // tracers are set in the OpenTelemetryProcessor
// vertxTracingOptions = recorder.getVertxTracingOptionsDevMode();
// } else {
// vertxTracingOptions = recorder.getVertxTracingOptionsProd(recorder.createTracers());
// }
vertxTracingOptions = recorder.getVertxTracingOptionsDevMode();
return new VertxOptionsConsumerBuildItem(
vertxTracingOptions,
LIBRARY_AFTER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package io.quarkus.opentelemetry.deployment;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;

import java.lang.reflect.InvocationTargetException;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.contrib.awsxray.AwsXrayIdGenerator;
// import io.opentelemetry.contrib.awsxray.AwsXrayIdGenerator;
import io.opentelemetry.sdk.trace.IdGenerator;
import io.quarkus.opentelemetry.deployment.common.TestUtil;
import io.quarkus.test.QuarkusUnitTest;
Expand All @@ -32,15 +27,15 @@ public class OpenTelemetryIdGeneratorTest {
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
IdGenerator idGenerator = TestUtil.getIdGenerator(openTelemetry);

assertThat(idGenerator, instanceOf(AwsXrayIdGenerator.class));
// assertThat(idGenerator, instanceOf(AwsXrayIdGenerator.class));
}

@ApplicationScoped
public static class OtelConfiguration {

@Produces
public IdGenerator idGenerator() {
return AwsXrayIdGenerator.getInstance();
}
}
// @ApplicationScoped
// public static class OtelConfiguration {
//
// @Produces
// public IdGenerator idGenerator() {
// return AwsXrayIdGenerator.getInstance();
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package io.quarkus.opentelemetry.deployment;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.ArrayMatching.arrayContainingInAnyOrder;

import javax.inject.Inject;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.awsxray.propagator.AwsXrayPropagator;
import io.quarkus.opentelemetry.deployment.common.TestUtil;
import io.quarkus.test.QuarkusUnitTest;

@Disabled("We need to remove the AWS dependency")
public class OpenTelemetryPropagatorsTest {
@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
Expand All @@ -28,7 +25,7 @@ public class OpenTelemetryPropagatorsTest {
void test() throws NoSuchFieldException, IllegalAccessException {
TextMapPropagator[] textMapPropagators = TestUtil.getTextMapPropagators(openTelemetry);

assertThat(textMapPropagators, arrayContainingInAnyOrder(W3CTraceContextPropagator.getInstance(),
AwsXrayPropagator.getInstance()));
// assertThat(textMapPropagators, arrayContainingInAnyOrder(W3CTraceContextPropagator.getInstance(),
// AwsXrayPropagator.getInstance()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -56,6 +57,7 @@
import io.quarkus.opentelemetry.deployment.StreamingGrpc;
import io.quarkus.opentelemetry.deployment.StreamingProto;
import io.quarkus.opentelemetry.deployment.common.TestSpanExporter;
import io.quarkus.opentelemetry.deployment.common.TestSpanExporterProvider;
import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Multi;
Expand All @@ -64,7 +66,7 @@ public class GrpcOpenTelemetryTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestSpanExporter.class)
.addClasses(TestSpanExporter.class, TestSpanExporterProvider.class)
.addClasses(HelloService.class)
.addClasses(GreeterGrpc.class, MutinyGreeterGrpc.class,
Greeter.class, GreeterBean.class, GreeterClient.class,
Expand All @@ -73,7 +75,12 @@ public class GrpcOpenTelemetryTest {
.addClasses(StreamingService.class)
.addClasses(StreamingGrpc.class, MutinyStreamingGrpc.class,
Streaming.class, StreamingBean.class, StreamingClient.class,
StreamingProto.class, Item.class, ItemOrBuilder.class))
StreamingProto.class, Item.class, ItemOrBuilder.class)
.addAsResource(new StringAsset(TestSpanExporterProvider.class.getCanonicalName()),
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider"))
.overrideConfigKey("quarkus.otel.traces.exporter", "test-span-exporter")
.overrideConfigKey("quarkus.otel.bsp.schedule.delay", "50")
.overrideConfigKey("quarkus.otel.bsp.export.timeout", "1s")
.overrideConfigKey("quarkus.grpc.clients.greeter.host", "localhost")
.overrideConfigKey("quarkus.grpc.clients.greeter.port", "9001")
.overrideConfigKey("quarkus.grpc.clients.streaming.host", "localhost")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingAttributesGetter;
import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingSpanNameExtractor;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.vertx.wrapper.OpenTelemetryWrapper;
import io.vertx.core.eventbus.Message;
import io.vertx.core.spi.tracing.TagExtractor;

@SuppressWarnings("rawtypes")
public class EventBusInstrumenterVertxTracer implements InstrumenterVertxTracer<Message, Message> {
private Instrumenter<Message, Message> consumerInstrumenter;
private Instrumenter<Message, Message> producerInstrumenter;
private OpenTelemetryWrapper openTelemetryWapper;
private final Instrumenter<Message, Message> consumerInstrumenter;
private final Instrumenter<Message, Message> producerInstrumenter;

public EventBusInstrumenterVertxTracer(final OpenTelemetryWrapper openTelemetryWapper) {
this.openTelemetryWapper = openTelemetryWapper;
setupInstrumenters();
public EventBusInstrumenterVertxTracer(final OpenTelemetry openTelemetry) {
this.consumerInstrumenter = getConsumerInstrumenter(openTelemetry);
this.producerInstrumenter = getProducerInstrumenter(openTelemetry);
}

@Override
Expand All @@ -33,41 +31,24 @@ public <R> boolean canHandle(final R request, final TagExtractor<R> tagExtractor

@Override
public Instrumenter<Message, Message> getReceiveRequestInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return consumerInstrumenter;
}

@Override
public Instrumenter<Message, Message> getSendResponseInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return consumerInstrumenter;
}

@Override
public Instrumenter<Message, Message> getSendRequestInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return producerInstrumenter;
}

@Override
public Instrumenter<Message, Message> getReceiveResponseInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return producerInstrumenter;
}

private void setupInstrumenters() {
this.consumerInstrumenter = getConsumerInstrumenter(openTelemetryWapper.get());
this.producerInstrumenter = getProducerInstrumenter(openTelemetryWapper.get());
}

private static Instrumenter<Message, Message> getConsumerInstrumenter(final OpenTelemetry openTelemetry) {
InstrumenterBuilder<Message, Message> serverBuilder = Instrumenter.builder(
openTelemetry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.vertx.wrapper.OpenTelemetryWrapper;
import io.vertx.core.Context;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpHeaders;
Expand All @@ -45,13 +44,12 @@
import io.vertx.core.spi.tracing.TagExtractor;

public class HttpInstrumenterVertxTracer implements InstrumenterVertxTracer<HttpRequest, HttpResponse> {
private Instrumenter<HttpRequest, HttpResponse> serverInstrumenter;
private Instrumenter<HttpRequest, HttpResponse> clientInstrumenter;
private OpenTelemetryWrapper openTelemetryWapper;
private final Instrumenter<HttpRequest, HttpResponse> serverInstrumenter;
private final Instrumenter<HttpRequest, HttpResponse> clientInstrumenter;

public HttpInstrumenterVertxTracer(final OpenTelemetryWrapper openTelemetryWapper) {
this.openTelemetryWapper = openTelemetryWapper;
setupInstrumenters();
public HttpInstrumenterVertxTracer(final OpenTelemetry openTelemetry) {
serverInstrumenter = getServerInstrumenter(openTelemetry);
clientInstrumenter = getClientInstrumenter(openTelemetry);
}

@Override
Expand All @@ -61,33 +59,21 @@ public <R> boolean canHandle(final R request, final TagExtractor<R> tagExtractor

@Override
public Instrumenter<HttpRequest, HttpResponse> getReceiveRequestInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return serverInstrumenter;
}

@Override
public Instrumenter<HttpRequest, HttpResponse> getSendResponseInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return serverInstrumenter;
}

@Override
public Instrumenter<HttpRequest, HttpResponse> getSendRequestInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return clientInstrumenter;
}

@Override
public Instrumenter<HttpRequest, HttpResponse> getReceiveResponseInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenters();
}
return clientInstrumenter;
}

Expand Down Expand Up @@ -121,11 +107,6 @@ public HttpRequest writableHeaders(
return WriteHeadersHttpRequest.request(request, headers);
}

private void setupInstrumenters() {
serverInstrumenter = getServerInstrumenter(openTelemetryWapper.get());
clientInstrumenter = getClientInstrumenter(openTelemetryWapper.get());
}

private static Instrumenter<HttpRequest, HttpResponse> getServerInstrumenter(final OpenTelemetry openTelemetry) {
ServerAttributesExtractor serverAttributesExtractor = new ServerAttributesExtractor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,23 @@
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.db.SqlClientAttributesExtractor;
import io.quarkus.opentelemetry.runtime.tracing.intrumentation.vertx.wrapper.OpenTelemetryWrapper;
import io.vertx.core.Context;
import io.vertx.core.spi.tracing.SpanKind;
import io.vertx.core.spi.tracing.TagExtractor;
import io.vertx.core.tracing.TracingPolicy;

public class SqlClientInstrumenterVertxTracer implements
InstrumenterVertxTracer<SqlClientInstrumenterVertxTracer.QueryTrace, SqlClientInstrumenterVertxTracer.QueryTrace> {
private Instrumenter<QueryTrace, QueryTrace> sqlClientInstrumenter;
private OpenTelemetryWrapper openTelemetryWapper;
private final Instrumenter<QueryTrace, QueryTrace> sqlClientInstrumenter;

public SqlClientInstrumenterVertxTracer(final OpenTelemetryWrapper openTelemetryWapper) {
this.openTelemetryWapper = openTelemetryWapper;
setupInstrumenter();
}

private void setupInstrumenter() {
this.sqlClientInstrumenter = getInstrumenter(openTelemetryWapper.get());
}

private Instrumenter<QueryTrace, QueryTrace> getInstrumenter(OpenTelemetry openTelemetry) {
public SqlClientInstrumenterVertxTracer(final OpenTelemetry openTelemetry) {
SqlClientAttributesGetter sqlClientAttributesGetter = new SqlClientAttributesGetter();

InstrumenterBuilder<QueryTrace, QueryTrace> serverBuilder = Instrumenter.builder(
openTelemetry,
INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(sqlClientAttributesGetter));

return serverBuilder
this.sqlClientInstrumenter = serverBuilder
.addAttributesExtractor(SqlClientAttributesExtractor.create(sqlClientAttributesGetter))
.buildClientInstrumenter((queryTrace, key, value) -> {
});
Expand Down Expand Up @@ -90,17 +79,11 @@ public Instrumenter<QueryTrace, QueryTrace> getSendResponseInstrumenter() {

@Override
public Instrumenter<QueryTrace, QueryTrace> getSendRequestInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenter();
}
return sqlClientInstrumenter;
}

@Override
public Instrumenter<QueryTrace, QueryTrace> getReceiveResponseInstrumenter() {
if (openTelemetryWapper.resetIfChanged()) {
setupInstrumenter();
}
return sqlClientInstrumenter;
}

Expand Down
Loading

0 comments on commit 68c6abb

Please sign in to comment.