Skip to content

Commit fd8fd81

Browse files
committed
applied comments
1 parent 9f5c983 commit fd8fd81

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplier.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
2121
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
2222
import io.opentelemetry.semconv.HttpAttributes;
23+
import io.opentelemetry.semconv.ServerAttributes;
2324
import io.opentelemetry.semconv.UrlAttributes;
2425
import java.time.Duration;
2526
import java.util.Collections;
@@ -59,6 +60,9 @@ final class SamplingRuleApplier {
5960

6061
private static final Map<String, String> XRAY_CLOUD_PLATFORM;
6162

63+
// _OTHER request method: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/http.md?plain=1#L96
64+
private static final String _OTHER_REQUEST_METHOD = "_OTHER";
65+
6266
static {
6367
Map<String, String> xrayCloudPlatform = new HashMap<>();
6468
xrayCloudPlatform.put(AWS_EC2, "AWS::EC2::Instance");
@@ -190,9 +194,14 @@ boolean matches(Attributes attributes, Resource resource) {
190194
} else if (entry.getKey().equals(HTTP_METHOD)
191195
|| entry.getKey().equals(HttpAttributes.HTTP_REQUEST_METHOD)) {
192196
httpMethod = (String) entry.getValue();
193-
} else if (entry.getKey().equals(NET_HOST_NAME)) {
197+
// according to semantic conventions, if the HTTP request method is not known to instrumentation
198+
// it must be set to _OTHER and the HTTP_REQUEST_METHOD_ORIGINAL should contain the original method
199+
if (httpMethod.equals(_OTHER_REQUEST_METHOD)) {
200+
httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL);
201+
}
202+
} else if (entry.getKey().equals(NET_HOST_NAME) || (entry.getKey().equals(ServerAttributes.SERVER_ADDRESS))) {
194203
host = (String) entry.getValue();
195-
} else if (entry.getKey().equals(HTTP_HOST)) {
204+
} else if (entry.getKey().equals(HTTP_HOST) || (entry.getKey().equals(ServerAttributes.SERVER_ADDRESS))) {
196205
// TODO (trask) remove support for deprecated http.host attribute
197206
host = (String) entry.getValue();
198207
}

0 commit comments

Comments
 (0)