diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml index 40c6a12e54..64442e2074 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml @@ -29,13 +29,6 @@ provided - - io.opentelemetry.semconv - opentelemetry-semconv - ${version.opentelemetry-semconv} - test - - ${project.groupId} apm-opentelemetry-embedded-metrics-sdk diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/SemAttributes.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/SemAttributes.java index 7077c599ec..a06ecc1d0c 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/SemAttributes.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/SemAttributes.java @@ -21,29 +21,14 @@ import io.opentelemetry.api.common.AttributeKey; /** - * Bridge for integration tests which use {@link io.opentelemetry.semconv.SemanticAttributes} + * Bridge for integration tests which use semconv attributes * which has been moved from {@code io.opentelemetry.semconv.trace.attributes.SemanticAttributes}. */ public class SemAttributes { - public static final AttributeKey HTTP_URL = getAttribute("HTTP_URL"); - public static final AttributeKey HTTP_STATUS_CODE = getAttribute("HTTP_STATUS_CODE"); - public static final AttributeKey HTTP_METHOD = getAttribute("HTTP_METHOD"); - public static final AttributeKey NET_PEER_PORT = getAttribute("NET_PEER_PORT"); - public static final AttributeKey NET_PEER_IP = getAttribute("NET_PEER_IP"); - - @SuppressWarnings("unchecked") - private static AttributeKey getAttribute(String name) { - try { - Class attribClass; - try { - attribClass = Class.forName("io.opentelemetry.semconv.SemanticAttributes"); - } catch (ClassNotFoundException cnf) { - attribClass = Class.forName("io.opentelemetry.semconv.trace.attributes.SemanticAttributes"); - } - return (AttributeKey) attribClass.getField(name).get(null); - }catch (Exception e) { - throw new IllegalStateException(e); - } - } + public static final AttributeKey HTTP_URL = AttributeKey.stringKey("HTTP_URL"); + public static final AttributeKey HTTP_STATUS_CODE = AttributeKey.longKey("HTTP_STATUS_CODE"); + public static final AttributeKey HTTP_METHOD = AttributeKey.stringKey("HTTP_METHOD"); + public static final AttributeKey NET_PEER_PORT = AttributeKey.longKey("NET_PEER_PORT"); + public static final AttributeKey NET_PEER_IP = AttributeKey.stringKey("NET_PEER_IP"); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java index dea9a4cb24..40ae523a3e 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java @@ -20,7 +20,6 @@ import co.elastic.apm.agent.impl.context.ServiceTargetImpl; import co.elastic.apm.agent.impl.transaction.*; -import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.opentelemetry.global.ElasticOpenTelemetry; import co.elastic.apm.agent.opentelemetry.tracing.ElasticOpenTelemetryTest; import co.elastic.apm.agent.opentelemetry.tracing.OTelSpan; @@ -34,7 +33,6 @@ import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Context; -import io.opentelemetry.semconv.SemanticAttributes; import javax.annotation.Nullable; import java.util.HashMap; @@ -103,7 +101,7 @@ public void bridgedTransactionWithRemoteContextParent() { assertThat(traceContext.getTraceId().toString()).isEqualTo(REMOTE_PARENT_TRACE_ID); } - private Context getRemoteContext(){ + private Context getRemoteContext() { return getOtel().getPropagators() .getTextMapPropagator() .extract(Context.current(), @@ -113,7 +111,7 @@ private Context getRemoteContext(){ } @Given("OTel span is created without parent") - public void createOTelSpanWithoutParent(){ + public void createOTelSpanWithoutParent() { otelSpan = (OTelSpan) getOtel().getTracer("") .spanBuilder("otel span") .setNoParent() // redundant, but makes it explicit @@ -156,14 +154,14 @@ public void otelSpanIsCreatedWithKind(String kind) { // the parent transaction is created by another step definition, thus we reuse the existing state TransactionImpl parentTransaction = state.getTransaction(); - Function createSpanWithKind = k -> { + Function createSpanWithKind = k -> { SpanBuilder spanBuilder = getOtel().getTracer("") .spanBuilder("span") .setSpanKind(SpanKind.valueOf(k)); return (OTelSpan) spanBuilder.startSpan(); }; - if( parentTransaction != null){ + if (parentTransaction != null) { // creating a span as a child of existing transaction try (Scope scope = parentTransaction.activateInScope()) { this.otelSpan = createSpanWithKind.apply(kind); @@ -205,40 +203,19 @@ public void otelSpanAttributes(io.cucumber.datatable.DataTable table) { } private static AttributeKey lookupKey(String name) { + // only doing a simple type mapping to cover existing test cases + // this is not meant to be exhaustive nor to cover up-to-date semconv definitions switch (name) { - case "http.url": - return SemanticAttributes.HTTP_URL; - case "http.scheme": - return SemanticAttributes.HTTP_SCHEME; - case "http.host": - return SemanticAttributes.HTTP_HOST; - case "net.peer.name": - return SemanticAttributes.NET_PEER_NAME; - case "net.peer.ip": - return SemanticAttributes.NET_PEER_IP; case "net.peer.port": - return SemanticAttributes.NET_PEER_PORT; - case "db.system": - return SemanticAttributes.DB_SYSTEM; - case "db.name": - return SemanticAttributes.DB_NAME; - case "messaging.system": - return SemanticAttributes.MESSAGING_SYSTEM; - case "messaging.url": - return SemanticAttributes.MESSAGING_URL; - case "messaging.destination": - return SemanticAttributes.MESSAGING_DESTINATION; - case "rpc.system": - return SemanticAttributes.RPC_SYSTEM; - case "rpc.service": - return SemanticAttributes.RPC_SERVICE; + return AttributeKey.longKey(name); default: - throw new IllegalArgumentException("unknown key for name " + name); + return AttributeKey.stringKey(name); + } } @Then("Elastic bridged (transaction|span) OTel kind is {string}") - public void bridgeObjectKind(String kind){ + public void bridgeObjectKind(String kind) { assertThat(getBridgedAbstractSpan().getOtelKind()) .isEqualTo(OTelSpanKind.valueOf(kind)); } @@ -325,7 +302,7 @@ public void bridgedSpanTargetServiceType(String type, String name) { } @Then("OTel span status set to {string}") - public void setOtelSpanStatus(String status){ + public void setOtelSpanStatus(String status) { otelSpan.setStatus(StatusCode.valueOf(status.toUpperCase(Locale.ROOT))); } diff --git a/apm-agent-plugins/apm-opentelemetry/pom.xml b/apm-agent-plugins/apm-opentelemetry/pom.xml index ac1fb530fb..5f7673ab98 100644 --- a/apm-agent-plugins/apm-opentelemetry/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/pom.xml @@ -20,7 +20,7 @@ to make sure that in the future we stay compatible with the previous version. --> 1.32.0 - 1.29.0-alpha + 1.30.0-rc.1 8 8