Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.opentelemetry.semconv</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>${version.opentelemetry-semconv}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-opentelemetry-embedded-metrics-sdk</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> HTTP_URL = getAttribute("HTTP_URL");
public static final AttributeKey<Long> HTTP_STATUS_CODE = getAttribute("HTTP_STATUS_CODE");
public static final AttributeKey<String> HTTP_METHOD = getAttribute("HTTP_METHOD");
public static final AttributeKey<Long> NET_PEER_PORT = getAttribute("NET_PEER_PORT");
public static final AttributeKey<String> NET_PEER_IP = getAttribute("NET_PEER_IP");

@SuppressWarnings("unchecked")
private static <T> AttributeKey<T> 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<T>) attribClass.getField(name).get(null);
}catch (Exception e) {
throw new IllegalStateException(e);
}
}
public static final AttributeKey<String> HTTP_URL = AttributeKey.stringKey("HTTP_URL");
public static final AttributeKey<Long> HTTP_STATUS_CODE = AttributeKey.longKey("HTTP_STATUS_CODE");
public static final AttributeKey<String> HTTP_METHOD = AttributeKey.stringKey("HTTP_METHOD");
public static final AttributeKey<Long> NET_PEER_PORT = AttributeKey.longKey("NET_PEER_PORT");
public static final AttributeKey<String> NET_PEER_IP = AttributeKey.stringKey("NET_PEER_IP");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down Expand Up @@ -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<String,OTelSpan> createSpanWithKind = k -> {
Function<String, OTelSpan> 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);
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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)));
}

Expand Down
2 changes: 1 addition & 1 deletion apm-agent-plugins/apm-opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
to make sure that in the future we stay compatible with the previous version.
-->
<version.opentelemetry>1.32.0</version.opentelemetry>
<version.opentelemetry-semconv>1.29.0-alpha</version.opentelemetry-semconv>
<version.opentelemetry-semconv>1.30.0-rc.1</version.opentelemetry-semconv>

<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
Expand Down