-
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.
OpenTelemetry service name has the highest priority
- Loading branch information
1 parent
6fde192
commit be6dea7
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...yment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryServiceNameTest.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,68 @@ | ||
package io.quarkus.opentelemetry.deployment; | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.SERVER; | ||
import static io.quarkus.opentelemetry.deployment.common.TestSpanExporter.getSpanByKindAndParentId; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.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.api.common.AttributeKey; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporter; | ||
import io.quarkus.opentelemetry.deployment.common.TestSpanExporterProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.config.SmallRyeConfig; | ||
|
||
public class OpenTelemetryServiceNameTest { | ||
|
||
private static final String SERVICE_NAME = "FrankBullitt"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TestSpanExporter.class) | ||
.addClass(TestSpanExporterProvider.class) | ||
.addAsResource("resource-config/application.properties", "application.properties") | ||
.addAsResource( | ||
"META-INF/services-config/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider", | ||
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider")) | ||
.overrideRuntimeConfigKey("quarkus.otel.service.name", SERVICE_NAME); | ||
|
||
@Inject | ||
SmallRyeConfig config; | ||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@Test | ||
void testSvcNameHasPriorityOverAppNameAndResourceAttr() { | ||
RestAssured.when() | ||
.get("/hello").then() | ||
.statusCode(200) | ||
.body(is("hello")); | ||
|
||
List<SpanData> spans = spanExporter.getFinishedSpanItems(1); | ||
|
||
final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000"); | ||
assertEquals("GET /hello", server.getName()); | ||
assertEquals(SERVICE_NAME, server.getResource().getAttribute(AttributeKey.stringKey("service.name"))); | ||
} | ||
|
||
@Path("/hello") | ||
public static class HelloResource { | ||
@GET | ||
public String hello() { | ||
return "hello"; | ||
} | ||
} | ||
} |
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