-
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
24 changed files
with
816 additions
and
22 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
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.MatcherAssert.assertThat; | ||
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.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); | ||
|
||
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 static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.collection.ArrayMatching.arrayContainingInAnyOrder; | ||
|
||
import javax.inject.Inject; | ||
|
||
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); | ||
|
||
assertThat(textMapPropagators, arrayContainingInAnyOrder(W3CTraceContextPropagator.getInstance(), | ||
AwsXrayPropagator.getInstance())); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...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,56 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.emptyOrNullString; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
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.resources.OsResource; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class OpenTelemetryResourceTest { | ||
private static final String RESOURCE_ATTRIBUTES = "quarkus.opentelemetry.tracer.resource-attributes"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.resources", "os") | ||
.setBeforeAllCustomizer(() -> System.setProperty(RESOURCE_ATTRIBUTES, "service.name=authservice")) | ||
.setAfterAllCustomizer(() -> System.getProperties().remove(RESOURCE_ATTRIBUTES)) | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TestUtil.class) | ||
.addAsResource("resource-config/application.properties")); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Resource resource = TestUtil.getResource(openTelemetry); | ||
|
||
assertEquals("authservice", resource.getAttributes().get(ResourceAttributes.SERVICE_NAME)); | ||
assertThat(resource.getAttributes().get(ResourceAttributes.OS_TYPE), not(emptyOrNullString())); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class OtelConfiguration { | ||
|
||
@Produces | ||
public Resource resource() { | ||
return OsResource.get(); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...yment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetrySamplerBeanTest.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.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.stringContainsInOrder; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
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 OpenTelemetrySamplerBeanTest { | ||
@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); | ||
|
||
assertThat(sampler.getDescription(), stringContainsInOrder("AlwaysOffSampler")); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class OtelConfiguration { | ||
|
||
@Produces | ||
public Sampler sampler() { | ||
return Sampler.alwaysOff(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ent/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetrySamplerConfigTest.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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import javax.inject.Inject; | ||
|
||
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 OpenTelemetrySamplerConfigTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.sampler", "ratio") | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.sampler.ratio", "0.5") | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.sampler.parent-based", "false") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(TestUtil.class)); | ||
|
||
@Inject | ||
OpenTelemetry openTelemetry; | ||
|
||
@Test | ||
void test() throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { | ||
Sampler sampler = TestUtil.getSampler(openTelemetry); | ||
|
||
assertEquals(String.format("TraceIdRatioBased{%.6f}", 0.5d), sampler.getDescription()); | ||
} | ||
} |
Oops, something went wrong.