-
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
16 changed files
with
353 additions
and
194 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
45 changes: 45 additions & 0 deletions
45
...yment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryIdGeneratorTest.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,45 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.instanceOf; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
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.api.OpenTelemetry; | ||
import io.opentelemetry.sdk.extension.aws.trace.AwsXrayIdGenerator; | ||
import io.opentelemetry.sdk.trace.IdGenerator; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenTelemetryIdGeneratorTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(TestUtil.class)); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
IdGenerator idGenerator = TestUtil.getIdGenerator(openTelemetry); | ||
|
||
MatcherAssert.assertThat(idGenerator, instanceOf(AwsXrayIdGenerator.class)); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class OtelConfiguration { | ||
|
||
@Produces | ||
public IdGenerator idGenerator() { | ||
return AwsXrayIdGenerator.getInstance(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...yment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryPropagatorsTest.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,35 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.collection.ArrayMatching; | ||
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.api.OpenTelemetry; | ||
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; | ||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.extension.aws.AwsXrayPropagator; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenTelemetryPropagatorsTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.opentelemetry.propagators", "tracecontext,xray") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(TestUtil.class)); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException { | ||
TextMapPropagator[] textMapPropagators = TestUtil.getTextMapPropagators(openTelemetry); | ||
|
||
MatcherAssert.assertThat(textMapPropagators, | ||
ArrayMatching.arrayContainingInAnyOrder(W3CTraceContextPropagator.getInstance(), | ||
AwsXrayPropagator.getInstance())); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryResourceTest.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,37 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.emptyOrNullString; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.hamcrest.MatcherAssert; | ||
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.api.OpenTelemetry; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenTelemetryResourceTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.resources", "os") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(TestUtil.class)); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Resource resource = TestUtil.getResource(openTelemetry); | ||
|
||
MatcherAssert.assertThat(resource.getAttributes().get(ResourceAttributes.OS_TYPE), | ||
CoreMatchers.not(emptyOrNullString())); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...eployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetrySamplerTest.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,44 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.instanceOf; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
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.api.OpenTelemetry; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenTelemetrySamplerTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(TestUtil.class)); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Sampler sampler = TestUtil.getSampler(openTelemetry); | ||
|
||
MatcherAssert.assertThat(sampler, instanceOf(Sampler.alwaysOff().getClass())); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class OtelConfiguration { | ||
|
||
@Produces | ||
public Sampler idGenerator() { | ||
return Sampler.alwaysOff(); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/TestUtil.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,64 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.trace.TracerProvider; | ||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.trace.IdGenerator; | ||
import io.opentelemetry.sdk.trace.SdkTracerProvider; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import io.quarkus.arc.Unremovable; | ||
|
||
@Unremovable | ||
public final class TestUtil { | ||
private TestUtil() { | ||
} | ||
|
||
public static Object getSharedState(OpenTelemetry openTelemetry) | ||
throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { | ||
TracerProvider tracerProvider = openTelemetry.getTracerProvider(); | ||
Method unobfuscateMethod = tracerProvider.getClass().getDeclaredMethod("unobfuscate"); | ||
unobfuscateMethod.setAccessible(true); | ||
SdkTracerProvider sdkTracerProvider = (SdkTracerProvider) unobfuscateMethod.invoke(tracerProvider); | ||
Field privateSharedStateField = sdkTracerProvider.getClass().getDeclaredField("sharedState"); | ||
privateSharedStateField.setAccessible(true); | ||
return privateSharedStateField.get(sdkTracerProvider); | ||
} | ||
|
||
public static IdGenerator getIdGenerator(OpenTelemetry openTelemetry) | ||
throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Object sharedState = getSharedState(openTelemetry); | ||
Field privateIdGeneratorField = sharedState.getClass().getDeclaredField("idGenerator"); | ||
privateIdGeneratorField.setAccessible(true); | ||
return (IdGenerator) privateIdGeneratorField.get(sharedState); | ||
} | ||
|
||
public static Resource getResource(OpenTelemetry openTelemetry) | ||
throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Object sharedState = getSharedState(openTelemetry); | ||
Field privateResourceField = sharedState.getClass().getDeclaredField("resource"); | ||
privateResourceField.setAccessible(true); | ||
return (Resource) privateResourceField.get(sharedState); | ||
} | ||
|
||
public static Sampler getSampler(OpenTelemetry openTelemetry) | ||
throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Object sharedState = getSharedState(openTelemetry); | ||
Field privateSamplerField = sharedState.getClass().getDeclaredField("sampler"); | ||
privateSamplerField.setAccessible(true); | ||
return (Sampler) privateSamplerField.get(sharedState); | ||
} | ||
|
||
public static TextMapPropagator[] getTextMapPropagators(OpenTelemetry openTelemetry) | ||
throws NoSuchFieldException, IllegalAccessException { | ||
TextMapPropagator textMapPropagator = openTelemetry.getPropagators().getTextMapPropagator(); | ||
System.out.println(textMapPropagator); | ||
Field privatePropagatorsField = textMapPropagator.getClass().getDeclaredField("textPropagators"); | ||
privatePropagatorsField.setAccessible(true); | ||
return (TextMapPropagator[]) privatePropagatorsField.get(textMapPropagator); | ||
} | ||
} |
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
Oops, something went wrong.