camel: add stable semconv (#9346)
This commit is contained in:
parent
b2e1fabc9f
commit
f37386baeb
|
@ -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;
|
||||
|
@ -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";
|
||||
|
@ -91,10 +100,27 @@ class HttpSpanDecorator extends BaseSpanDecorator {
|
|||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue