2323
2424package 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+
2629import io .opentelemetry .api .common .AttributesBuilder ;
2730import io .opentelemetry .context .Context ;
2831import io .opentelemetry .instrumentation .api .instrumenter .http .HttpServerRoute ;
2932import 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 ;
3037import io .opentelemetry .javaagent .instrumentation .apachecamel .CamelDirection ;
3138import io .opentelemetry .semconv .trace .attributes .SemanticAttributes ;
3239import java .net .MalformedURLException ;
3340import java .net .URL ;
41+ import java .util .Set ;
3442import javax .annotation .Nullable ;
3543import org .apache .camel .Endpoint ;
3644import 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