Skip to content

Commit f37386b

Browse files
authored
camel: add stable semconv (#9346)
1 parent b2e1fab commit f37386b

File tree

1 file changed

+28
-2
lines changed
  • instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators

1 file changed

+28
-2
lines changed

instrumentation/camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,22 @@
2323

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

26+
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
27+
import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER;
28+
2629
import io.opentelemetry.api.common.AttributesBuilder;
2730
import io.opentelemetry.context.Context;
2831
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRoute;
2932
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerRouteSource;
33+
import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
34+
import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
35+
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
36+
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
3037
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
3138
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
3239
import java.net.MalformedURLException;
3340
import java.net.URL;
41+
import java.util.Set;
3442
import javax.annotation.Nullable;
3543
import org.apache.camel.Endpoint;
3644
import org.apache.camel.Exchange;
@@ -39,6 +47,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
3947

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

4352
protected String getProtocol() {
4453
return "http";
@@ -91,10 +100,27 @@ public void pre(
91100

92101
String httpUrl = getHttpUrl(exchange, endpoint);
93102
if (httpUrl != null) {
94-
attributes.put(SemanticAttributes.HTTP_URL, httpUrl);
103+
if (SemconvStability.emitStableHttpSemconv()) {
104+
internalSet(attributes, UrlAttributes.URL_FULL, httpUrl);
105+
}
106+
107+
if (SemconvStability.emitOldHttpSemconv()) {
108+
internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl);
109+
}
95110
}
96111

97-
attributes.put(SemanticAttributes.HTTP_METHOD, getHttpMethod(exchange, endpoint));
112+
String method = getHttpMethod(exchange, endpoint);
113+
if (SemconvStability.emitStableHttpSemconv()) {
114+
if (method == null || knownMethods.contains(method)) {
115+
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method);
116+
} else {
117+
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER);
118+
internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
119+
}
120+
}
121+
if (SemconvStability.emitOldHttpSemconv()) {
122+
internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
123+
}
98124
}
99125

100126
private static boolean shouldAppendHttpRoute(CamelDirection camelDirection) {

0 commit comments

Comments
 (0)