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.
Add producers for Otel Span and Baggage
- Loading branch information
Showing
4 changed files
with
154 additions
and
0 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
47 changes: 47 additions & 0 deletions
47
.../opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryInjectionsTest.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,47 @@ | ||
package io.quarkus.it.opentelemetry; | ||
|
||
import static io.restassured.RestAssured.get; | ||
import static io.restassured.RestAssured.given; | ||
import static java.net.HttpURLConnection.HTTP_OK; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.common.mapper.TypeRef; | ||
|
||
@QuarkusTest | ||
public class OpenTelemetryInjectionsTest { | ||
|
||
@AfterEach | ||
void reset() { | ||
given().get("/reset").then().statusCode(HTTP_OK); | ||
await().atMost(5, SECONDS).until(() -> getSpans().size() == 0); | ||
} | ||
|
||
private List<Map<String, Object>> getSpans() { | ||
return get("/export").body().as(new TypeRef<>() { | ||
}); | ||
} | ||
|
||
@Test | ||
public void testOTelInjections() { | ||
given() | ||
.when().get("/otel/injection") | ||
.then() | ||
.statusCode(200); | ||
} | ||
|
||
@Test | ||
public void testOTelInjectionsAsync() { | ||
given() | ||
.when().get("/otel/injection/async") | ||
.then() | ||
.statusCode(200); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/util/InjectionResource.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,58 @@ | ||
package io.quarkus.it.opentelemetry.util; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.baggage.Baggage; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Path("/otel/injection") | ||
@RequestScoped | ||
public class InjectionResource { | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Inject | ||
Tracer tracer; | ||
|
||
@Inject | ||
Span span; | ||
|
||
@Inject | ||
Baggage baggage; | ||
|
||
@GET | ||
public Response verifyOTelInjections() { | ||
verifyInjections(); | ||
return Response.ok().build(); | ||
} | ||
|
||
@GET | ||
@Path("/async") | ||
public Uni<Response> verifyOTelInjectionsAsync() { | ||
verifyInjections(); | ||
return Uni.createFrom().item(Response.ok().build()); | ||
} | ||
|
||
private void verifyInjections() { | ||
Assertions.assertNotNull(openTelemetry, "OpenTelemetry cannot be injected"); | ||
Assertions.assertNotNull(tracer, "Tracer cannot be injected"); | ||
Assertions.assertNotNull(span, "Span cannot be injected"); | ||
Assertions.assertNotNull(openTelemetry, "Baggage cannot be injected"); | ||
|
||
Assertions.assertEquals(GlobalOpenTelemetry.get(), openTelemetry); | ||
Assertions.assertEquals(Span.current().getSpanContext(), span.getSpanContext()); | ||
Assertions.assertEquals(Baggage.current().size(), baggage.size()); | ||
baggage.asMap().forEach((s, baggageEntry) -> Assertions.assertEquals(baggageEntry, baggage.asMap().get(s))); | ||
} | ||
} |