-
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 exclusion of non-application URIs if custom Sampler is used
- Loading branch information
Showing
3 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...elemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/TracerUtilTest.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,63 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.data.LinkData; | ||
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import io.opentelemetry.sdk.trace.samplers.SamplingResult; | ||
import io.quarkus.opentelemetry.runtime.tracing.DropNamesSampler; | ||
import io.quarkus.opentelemetry.runtime.tracing.TracerRuntimeConfig; | ||
import io.quarkus.opentelemetry.runtime.tracing.TracerUtil; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class TracerUtilTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClass(TestSampler.class)); | ||
private static final String TEST_SAMPLER = "testSampler"; | ||
|
||
@Test | ||
void testEnhanceExistingSampler() { | ||
TracerRuntimeConfig.SamplerConfig samplerConfig = new TracerRuntimeConfig.SamplerConfig(); | ||
samplerConfig.parentBased = false; | ||
samplerConfig.samplerName = "on"; | ||
Sampler sampler = TracerUtil.mapSampler(samplerConfig, List.of("test")); | ||
assertEquals(TEST_SAMPLER, sampler.getDescription()); | ||
assertEquals(DropNamesSampler.class, sampler.getClass()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class SamplerConfiguration { | ||
|
||
@Produces | ||
public TestSampler sampler() { | ||
return new TestSampler(); | ||
} | ||
} | ||
|
||
static class TestSampler implements Sampler { | ||
|
||
@Override | ||
public SamplingResult shouldSample(Context context, String s, String s1, SpanKind spanKind, Attributes attributes, | ||
List<LinkData> list) { | ||
return SamplingResult.recordAndSample(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return TEST_SAMPLER; | ||
} | ||
} | ||
|
||
} |
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