-
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.
Fix OpenTelemetry service name priorities
- Loading branch information
1 parent
f6f0849
commit 78cd5b7
Showing
4 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...c/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryResourceAttrSvcNameTest.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.asset.StringAsset; | ||
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; | ||
|
||
public class OpenTelemetryResourceAttrSvcNameTest { | ||
|
||
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(new StringAsset("" + | ||
"quarkus.otel.traces.exporter=test-span-exporter\n" + | ||
"quarkus.otel.bsp.schedule.delay=50\n"), "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.resource.attributes", "service.name=" + SERVICE_NAME); | ||
|
||
@Inject | ||
TestSpanExporter spanExporter; | ||
|
||
@Test | ||
void testResourceAttrSvcNameHasPriorityOverAppName() { | ||
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
68 changes: 68 additions & 0 deletions
68
.../java/io/quarkus/opentelemetry/deployment/OpenTelemetrySvcNameAndNoResourceAttrsTest.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.asset.StringAsset; | ||
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; | ||
|
||
public class OpenTelemetrySvcNameAndNoResourceAttrsTest { | ||
|
||
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(new StringAsset("" + | ||
"quarkus.otel.traces.exporter=test-span-exporter\n" + | ||
"quarkus.otel.bsp.schedule.delay=50\n"), "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 | ||
TestSpanExporter spanExporter; | ||
|
||
@Test | ||
void testSvcNameHasPriorityOverAppNameWhenNoResourceAttrs() { | ||
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