23
23
24
24
package io .opentelemetry .javaagent .instrumentation .apachecamel .decorators ;
25
25
26
+ import static io .opentelemetry .instrumentation .api .internal .AttributesExtractorUtil .internalSet ;
27
+ import static io .opentelemetry .instrumentation .api .internal .HttpConstants ._OTHER ;
28
+
26
29
import io .opentelemetry .api .common .AttributesBuilder ;
27
30
import io .opentelemetry .context .Context ;
28
31
import io .opentelemetry .instrumentation .api .instrumenter .http .HttpServerRoute ;
29
32
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 ;
30
37
import io .opentelemetry .javaagent .instrumentation .apachecamel .CamelDirection ;
31
38
import io .opentelemetry .semconv .trace .attributes .SemanticAttributes ;
32
39
import java .net .MalformedURLException ;
33
40
import java .net .URL ;
41
+ import java .util .Set ;
34
42
import javax .annotation .Nullable ;
35
43
import org .apache .camel .Endpoint ;
36
44
import org .apache .camel .Exchange ;
@@ -39,6 +47,7 @@ class HttpSpanDecorator extends BaseSpanDecorator {
39
47
40
48
private static final String POST_METHOD = "POST" ;
41
49
private static final String GET_METHOD = "GET" ;
50
+ private static final Set <String > knownMethods = CommonConfig .get ().getKnownHttpRequestMethods ();
42
51
43
52
protected String getProtocol () {
44
53
return "http" ;
@@ -91,10 +100,27 @@ public void pre(
91
100
92
101
String httpUrl = getHttpUrl (exchange , endpoint );
93
102
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
+ }
95
110
}
96
111
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
+ }
98
124
}
99
125
100
126
private static boolean shouldAppendHttpRoute (CamelDirection camelDirection ) {
0 commit comments