-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable tracing of /q endpoints by default
Resolves #17119
- Loading branch information
1 parent
d9c7bdc
commit 30c1711
Showing
8 changed files
with
164 additions
and
2 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
52 changes: 52 additions & 0 deletions
52
...oyment/src/test/java/io/quarkus/opentelemetry/deployment/NonAppEndpointsDisabledTest.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,52 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class NonAppEndpointsDisabledTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TracerRouter.class) | ||
.addClass(TestSpanExporter.class)); | ||
|
||
@Inject | ||
TestSpanExporter testSpanExporter; | ||
|
||
@Test | ||
void testHealthEndpointNotTraced() throws InterruptedException { | ||
RestAssured.when().get("/q/health").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/q/health/live").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/q/health/ready").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/tracer").then() | ||
.statusCode(200) | ||
.body(is("Hello Tracer!")); | ||
|
||
List<SpanData> spans = testSpanExporter.getFinishedSpanItems(); | ||
|
||
Assertions.assertEquals(2, spans.size()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...loyment/src/test/java/io/quarkus/opentelemetry/deployment/NonAppEndpointsEnabledTest.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,53 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class NonAppEndpointsEnabledTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.opentelemetry.tracer.suppress-non-application-uris", "false") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TracerRouter.class) | ||
.addClass(TestSpanExporter.class)); | ||
|
||
@Inject | ||
TestSpanExporter testSpanExporter; | ||
|
||
@Test | ||
void testHealthEndpointNotTraced() throws InterruptedException { | ||
RestAssured.when().get("/q/health").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/q/health/live").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/q/health/ready").then() | ||
.statusCode(200) | ||
.body(containsString("\"status\": \"UP\"")); | ||
|
||
RestAssured.when().get("/tracer").then() | ||
.statusCode(200) | ||
.body(is("Hello Tracer!")); | ||
|
||
List<SpanData> spans = testSpanExporter.getFinishedSpanItems(); | ||
|
||
Assertions.assertEquals(5, spans.size()); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...src/main/java/io/quarkus/opentelemetry/runtime/tracing/NonApplicationEndpointSampler.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.runtime.tracing; | ||
|
||
import java.util.List; | ||
|
||
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.SamplingDecision; | ||
import io.opentelemetry.sdk.trace.samplers.SamplingResult; | ||
|
||
public class NonApplicationEndpointSampler implements Sampler { | ||
private static final SamplingResult NEGATIVE_SAMPLING_RESULT = SamplingResult.create(SamplingDecision.DROP); | ||
|
||
private final Sampler root; | ||
|
||
public NonApplicationEndpointSampler(Sampler root) { | ||
this.root = root; | ||
} | ||
|
||
@Override | ||
public SamplingResult shouldSample(Context parentContext, String traceId, String name, SpanKind spanKind, | ||
Attributes attributes, List<LinkData> parentLinks) { | ||
if (name.startsWith("q/") && spanKind == SpanKind.SERVER) { | ||
return NEGATIVE_SAMPLING_RESULT; | ||
} | ||
return root.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "NonApplicationEndpointBased{/q}"; | ||
} | ||
} |
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