Skip to content

Commit

Permalink
camel: add stable semconv (#9346)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Aug 30, 2023
1 parent b2e1fab commit f37386b
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@

package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource;
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
import javax.annotation.Nullable;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
Expand All @@ -39,6 +47,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {

private static final String POST_METHOD = "POST";
private static final String GET_METHOD = "GET";
private static final Set<String> knownMethods = CommonConfig.get().getKnownHttpRequestMethods();

protected String getProtocol() {
return "http";
Expand Down Expand Up @@ -91,10 +100,27 @@ public void pre(

String httpUrl = getHttpUrl(exchange, endpoint);
if (httpUrl != null) {
attributes.put(SemanticAttributes.HTTP_URL, httpUrl);
if (SemconvStability.emitStableHttpSemconv()) {
internalSet(attributes, UrlAttributes.URL_FULL, httpUrl);
}

if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl);
}
}

attributes.put(SemanticAttributes.HTTP_METHOD, getHttpMethod(exchange, endpoint));
String method = getHttpMethod(exchange, endpoint);
if (SemconvStability.emitStableHttpSemconv()) {
if (method == null || knownMethods.contains(method)) {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method);
} else {
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER);
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
}
}
if (SemconvStability.emitOldHttpSemconv()) {
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
}
}

private static boolean shouldAppendHttpRoute(CamelDirection camelDirection) {
Expand Down

0 comments on commit f37386b

Please sign in to comment.