-
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.
- Loading branch information
Showing
8 changed files
with
509 additions
and
2 deletions.
There are no files selected for viewing
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
128 changes: 128 additions & 0 deletions
128
...loyment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryTracelessTest.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,128 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
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.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.opentelemetry.deployment.common.traces.TracelessClassLevelResource; | ||
import io.quarkus.opentelemetry.deployment.common.traces.TracelessHelloResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class OpenTelemetryTracelessTest { | ||
@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(TracelessHelloResource.class, TracelessClassLevelResource.class, TraceMeResource.class)); | ||
|
||
@Inject | ||
InMemoryExporter exporter; | ||
|
||
@BeforeEach | ||
void setup() { | ||
exporter.reset(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the method @Path uses @PathParam") | ||
void testingWithPathParam() { | ||
RestAssured.when() | ||
.get("/hello/mask/1").then() | ||
.statusCode(200) | ||
.body(is("mask-1")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
exporter.getSpanExporter().getFinishedSpanItems(1); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the annotation @Traceless is at method level") | ||
void testingTracelessHelloHi() { | ||
|
||
RestAssured.when() | ||
.get("/hello").then() | ||
.statusCode(200) | ||
.body(is("hello")); | ||
|
||
RestAssured.when() | ||
.get("/hello/hi").then() | ||
.statusCode(200) | ||
.body(is("hi")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
// should have only one | ||
exporter.getSpanExporter().getFinishedSpanItems(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the method @Path is without '/'") | ||
void testingHelloNoSlash() { | ||
RestAssured.when() | ||
.get("/hello/no-slash").then() | ||
.statusCode(200) | ||
.body(is("no-slash")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
// should have only one | ||
exporter.getSpanExporter().getFinishedSpanItems(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("Should not trace when the annotation is at class level") | ||
void testingTracelessAtClassLevel() { | ||
|
||
RestAssured.when() | ||
.get("class-level").then() | ||
.statusCode(200) | ||
.body(is("class-level")); | ||
|
||
RestAssured.when() | ||
.get("/class-level/first-method").then() | ||
.statusCode(200) | ||
.body(is("first-method")); | ||
|
||
RestAssured.when() | ||
.get("/class-level/second-method").then() | ||
.statusCode(200) | ||
.body(is("second-method")); | ||
|
||
RestAssured.when() | ||
.get("/trace-me").then() | ||
.statusCode(200) | ||
.body(is("trace-me")); | ||
|
||
// should have only one | ||
exporter.getSpanExporter().getFinishedSpanItems(1); | ||
} | ||
} |
Oops, something went wrong.