-
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.
Support OpenTelemetry @WithSpan in CDI
- Loading branch information
Showing
11 changed files
with
450 additions
and
4 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
71 changes: 71 additions & 0 deletions
71
...eployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryHttpCDITest.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,71 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
import static io.opentelemetry.api.trace.SpanKind.SERVER; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.extension.annotations.WithSpan; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class OpenTelemetryHttpCDITest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(HelloResource.class) | ||
.addClass(HelloBean.class) | ||
.addClass(TestSpanExporter.class)); | ||
|
||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@Test | ||
void telemetry() { | ||
RestAssured.when() | ||
.get("/hello").then() | ||
.statusCode(200) | ||
.body(is("hello")); | ||
|
||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(2, spanItems.size()); | ||
assertEquals("HelloBean.hello", spanItems.get(0).getName()); | ||
assertEquals(INTERNAL, spanItems.get(0).getKind()); | ||
assertEquals("hello", spanItems.get(1).getName()); | ||
assertEquals(SERVER, spanItems.get(1).getKind()); | ||
assertEquals(spanItems.get(0).getParentSpanId(), spanItems.get(1).getSpanId()); | ||
} | ||
|
||
@Path("/hello") | ||
public static class HelloResource { | ||
@Inject | ||
HelloBean helloBean; | ||
|
||
@GET | ||
public String hello() { | ||
return helloBean.hello(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class HelloBean { | ||
@WithSpan | ||
public String hello() { | ||
return "hello"; | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...deployment/src/test/java/io/quarkus/opentelemetry/deployment/WithSpanInterceptorTest.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,126 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL; | ||
import static io.opentelemetry.api.trace.SpanKind.SERVER; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.extension.annotations.SpanAttribute; | ||
import io.opentelemetry.extension.annotations.WithSpan; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class WithSpanInterceptorTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClass(SpanBean.class).addClass(TestSpanExporter.class)); | ||
|
||
@Inject | ||
SpanBean spanBean; | ||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
spanExporter.reset(); | ||
} | ||
|
||
@Test | ||
void span() { | ||
spanBean.span(); | ||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(1, spanItems.size()); | ||
assertEquals("SpanBean.span", spanItems.get(0).getName()); | ||
assertEquals(INTERNAL, spanItems.get(0).getKind()); | ||
} | ||
|
||
@Test | ||
void spanName() { | ||
spanBean.spanName(); | ||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(1, spanItems.size()); | ||
assertEquals("name", spanItems.get(0).getName()); | ||
assertEquals(INTERNAL, spanItems.get(0).getKind()); | ||
} | ||
|
||
@Test | ||
void spanKind() { | ||
spanBean.spanKind(); | ||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(1, spanItems.size()); | ||
assertEquals("SpanBean.spanKind", spanItems.get(0).getName()); | ||
assertEquals(SERVER, spanItems.get(0).getKind()); | ||
} | ||
|
||
@Test | ||
void spanArgs() { | ||
spanBean.spanArgs("argument"); | ||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(1, spanItems.size()); | ||
assertEquals("SpanBean.spanArgs", spanItems.get(0).getName()); | ||
assertEquals(INTERNAL, spanItems.get(0).getKind()); | ||
assertEquals("argument", spanItems.get(0).getAttributes().get(AttributeKey.stringKey("arg"))); | ||
} | ||
|
||
@Test | ||
void spanChild() { | ||
spanBean.spanChild(); | ||
List<SpanData> spanItems = spanExporter.getFinishedSpanItems(); | ||
assertEquals(2, spanItems.size()); | ||
|
||
assertEquals("SpanChildBean.spanChild", spanItems.get(0).getName()); | ||
assertEquals("SpanBean.spanChild", spanItems.get(1).getName()); | ||
assertEquals(spanItems.get(0).getParentSpanId(), spanItems.get(1).getSpanId()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class SpanBean { | ||
@WithSpan | ||
public void span() { | ||
|
||
} | ||
|
||
@WithSpan("name") | ||
public void spanName() { | ||
|
||
} | ||
|
||
@WithSpan(kind = SERVER) | ||
public void spanKind() { | ||
|
||
} | ||
|
||
@WithSpan | ||
public void spanArgs(@SpanAttribute(value = "arg") String arg) { | ||
|
||
} | ||
|
||
@Inject | ||
SpanChildBean spanChildBean; | ||
|
||
@WithSpan | ||
public void spanChild() { | ||
spanChildBean.spanChild(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class SpanChildBean { | ||
@WithSpan | ||
public void spanChild() { | ||
|
||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...try/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/cdi/MethodRequest.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,21 @@ | ||
package io.quarkus.opentelemetry.runtime.tracing.cdi; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
final class MethodRequest { | ||
private final Method method; | ||
private final Object[] args; | ||
|
||
public MethodRequest(final Method method, final Object[] args) { | ||
this.method = method; | ||
this.args = args; | ||
} | ||
|
||
public Method getMethod() { | ||
return method; | ||
} | ||
|
||
public Object[] getArgs() { | ||
return args; | ||
} | ||
} |
Oops, something went wrong.