forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#38089 from mkouba/issue-35912
OpenTelemetry: fine-grained instrumentation enablement
- Loading branch information
Showing
12 changed files
with
432 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...quarkus/opentelemetry/deployment/instrumentation/GrpcOpenInstrumentationDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package io.quarkus.opentelemetry.deployment.instrumentation; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
import static io.quarkus.opentelemetry.deployment.common.TestSpanExporter.getSpanByKindAndParentId; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import jakarta.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; | ||
|
||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.grpc.GrpcClient; | ||
import io.quarkus.grpc.GrpcService; | ||
import io.quarkus.opentelemetry.deployment.Greeter; | ||
import io.quarkus.opentelemetry.deployment.GreeterBean; | ||
import io.quarkus.opentelemetry.deployment.GreeterClient; | ||
import io.quarkus.opentelemetry.deployment.GreeterGrpc; | ||
import io.quarkus.opentelemetry.deployment.HelloProto; | ||
import io.quarkus.opentelemetry.deployment.HelloReply; | ||
import io.quarkus.opentelemetry.deployment.HelloReplyOrBuilder; | ||
import io.quarkus.opentelemetry.deployment.HelloRequest; | ||
import io.quarkus.opentelemetry.deployment.HelloRequestOrBuilder; | ||
import io.quarkus.opentelemetry.deployment.MutinyGreeterGrpc; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporter; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporterProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public class GrpcOpenInstrumentationDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(TestSpanExporter.class, TestSpanExporterProvider.class) | ||
.addClasses(HelloService.class) | ||
.addClasses(GreeterGrpc.class, MutinyGreeterGrpc.class, | ||
Greeter.class, GreeterBean.class, GreeterClient.class, | ||
HelloProto.class, HelloRequest.class, HelloRequestOrBuilder.class, | ||
HelloReply.class, HelloReplyOrBuilder.class) | ||
.addAsResource(new StringAsset(TestSpanExporterProvider.class.getCanonicalName()), | ||
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider")) | ||
.withConfigurationResource("application-default.properties") | ||
.overrideConfigKey("quarkus.grpc.clients.hello.host", "localhost") | ||
.overrideConfigKey("quarkus.grpc.clients.hello.port", "9001") | ||
.overrideConfigKey("quarkus.otel.instrument.grpc", "false"); | ||
|
||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@GrpcClient | ||
Greeter hello; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
spanExporter.reset(); | ||
} | ||
|
||
@Test | ||
void testTratestTracingDisabled() { | ||
String response = hello.sayHello( | ||
HelloRequest.newBuilder().setName("ping").build()) | ||
.map(HelloReply::getMessage) | ||
.await().atMost(Duration.ofSeconds(5)); | ||
assertEquals("Hello ping", response); | ||
|
||
List<SpanData> spans = spanExporter.getFinishedSpanItems(1); | ||
assertEquals(1, spans.size()); | ||
|
||
SpanData internal = getSpanByKindAndParentId(spans, INTERNAL, "0000000000000000"); | ||
assertEquals("span.internal", internal.getName()); | ||
assertEquals("value", internal.getAttributes().get(stringKey("grpc.internal"))); | ||
} | ||
|
||
@GrpcService | ||
public static class HelloService implements Greeter { | ||
|
||
@Inject | ||
Tracer tracer; | ||
|
||
@Override | ||
public Uni<HelloReply> sayHello(HelloRequest request) { | ||
Span span = tracer.spanBuilder("span.internal") | ||
.setSpanKind(INTERNAL) | ||
.setAttribute("grpc.internal", "value") | ||
.startSpan(); | ||
span.end(); | ||
return Uni.createFrom().item(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build()); | ||
} | ||
} | ||
|
||
} |
92 changes: 92 additions & 0 deletions
92
...us/opentelemetry/deployment/instrumentation/VertxEventBusInstrumentationDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package io.quarkus.opentelemetry.deployment.instrumentation; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
import static io.quarkus.opentelemetry.deployment.common.TestSpanExporter.getSpanByKindAndParentId; | ||
import static java.net.HttpURLConnection.HTTP_OK; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
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; | ||
|
||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporter; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporterProvider; | ||
import io.quarkus.opentelemetry.deployment.common.TestUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.ConsumeEvent; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.eventbus.EventBus; | ||
import io.vertx.ext.web.Router; | ||
|
||
public class VertxEventBusInstrumentationDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.withApplicationRoot(root -> root | ||
.addClasses(Events.class, TestUtil.class, TestSpanExporter.class, TestSpanExporterProvider.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.metrics.exporter", "none") | ||
.overrideConfigKey("quarkus.otel.logs.exporter", "none") | ||
.overrideConfigKey("quarkus.otel.bsp.schedule.delay", "200") | ||
.overrideConfigKey("quarkus.otel.instrument.vertx-event-bus", "false"); | ||
|
||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
spanExporter.reset(); | ||
} | ||
|
||
@Test | ||
void testTracingDisabled() throws Exception { | ||
|
||
RestAssured.when().get("/hello/event") | ||
.then() | ||
.statusCode(HTTP_OK) | ||
.body(equalTo("BAR")); | ||
|
||
// http request and dummy | ||
List<SpanData> spans = spanExporter.getFinishedSpanItems(2); | ||
assertEquals(2, spans.size()); | ||
|
||
SpanData internal = getSpanByKindAndParentId(spans, INTERNAL, "0000000000000000"); | ||
assertEquals("io.quarkus.vertx.opentelemetry", internal.getName()); | ||
assertEquals("dummy", internal.getAttributes().get(stringKey("test.message"))); | ||
} | ||
|
||
@Singleton | ||
public static class Events { | ||
|
||
@Inject | ||
Tracer tracer; | ||
|
||
@ConsumeEvent("foo") | ||
String echo(String foo) { | ||
tracer.spanBuilder("io.quarkus.vertx.opentelemetry").startSpan() | ||
.setAttribute("test.message", "dummy") | ||
.end(); | ||
return foo.toUpperCase(); | ||
} | ||
|
||
void registerRoutes(@Observes Router router, EventBus eventBus) { | ||
router.get("/hello/event").handler(rc -> { | ||
eventBus.request("foo", "bar").onComplete(r -> rc.end(r.result().body().toString())); | ||
}); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.