-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add annotation and cofiguration for disabling tracing
- Loading branch information
Showing
21 changed files
with
1,257 additions
and
2 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
19 changes: 19 additions & 0 deletions
19
...c/main/java/io/quarkus/opentelemetry/deployment/tracing/DropApplicationUrisBuildItem.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,19 @@ | ||
package io.quarkus.opentelemetry.deployment.tracing; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* Represents an application uri that must be ignored for tracing. | ||
*/ | ||
public final class DropApplicationUrisBuildItem extends MultiBuildItem { | ||
|
||
private final String uri; | ||
|
||
public DropApplicationUrisBuildItem(String uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public String uri() { | ||
return uri; | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...t/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetrySuppressAppUrisTest.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,87 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.opentelemetry.deployment.common.TracerRouter; | ||
import io.quarkus.opentelemetry.deployment.common.exporter.InMemoryExporter; | ||
import io.quarkus.opentelemetry.deployment.common.exporter.InMemoryMetricExporterProvider; | ||
import io.quarkus.opentelemetry.deployment.common.traces.TraceMeResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class OpenTelemetrySuppressAppUrisTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addPackage(InMemoryExporter.class.getPackage()) | ||
.addAsResource("resource-config/application.properties", "application.properties") | ||
.addAsResource( | ||
"META-INF/services-config/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider", | ||
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider") | ||
.addAsResource(new StringAsset(InMemoryMetricExporterProvider.class.getCanonicalName()), | ||
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider") | ||
.addClasses(TracerRouter.class, TraceMeResource.class)) | ||
.overrideConfigKey("quarkus.otel.traces.suppress-application-uris", "tracer,/hello/Itachi"); | ||
|
||
@Inject | ||
InMemoryExporter exporter; | ||
|
||
@BeforeEach | ||
void setup() { | ||
exporter.reset(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the using configuration quarkus.otel.traces.suppress-application-uris without slash") | ||
void testingSuppressAppUrisWithoutSlash() { | ||
RestAssured.when() | ||
.get("/tracer").then() | ||
.statusCode(200) | ||
.body(is("Hello Tracer!")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
List<SpanData> spans = exporter.getSpanExporter().getFinishedSpanItems(1); | ||
|
||
assertThat(spans) | ||
.hasSize(1) | ||
.satisfiesOnlyOnce(span -> assertThat(span.getName()).containsOnlyOnce("trace-me")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the using configuration quarkus.otel.traces.suppress-application-uris with slash") | ||
void testingSuppressAppUrisWithSlash() { | ||
RestAssured.when() | ||
.get("/hello/Itachi").then() | ||
.statusCode(200) | ||
.body(is("Amaterasu!")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
List<SpanData> spans = exporter.getSpanExporter().getFinishedSpanItems(1); | ||
|
||
assertThat(spans) | ||
.hasSize(1) | ||
.satisfiesOnlyOnce(span -> assertThat(span.getName()).containsOnlyOnce("trace-me")); | ||
} | ||
} |
Oops, something went wrong.