-
Notifications
You must be signed in to change notification settings - Fork 158
[aws-xray] Update SamplerRulesApplier to recognize new HTTP/URL semconv. #1959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
761d996
7bb457c
9f5c983
fd8fd81
846657b
cde8df7
1649fc0
a12a706
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ | |
import io.opentelemetry.sdk.trace.samplers.Sampler; | ||
import io.opentelemetry.sdk.trace.samplers.SamplingDecision; | ||
import io.opentelemetry.sdk.trace.samplers.SamplingResult; | ||
import io.opentelemetry.semconv.HttpAttributes; | ||
import io.opentelemetry.semconv.ServerAttributes; | ||
import io.opentelemetry.semconv.UrlAttributes; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
|
@@ -57,6 +60,10 @@ final class SamplingRuleApplier { | |
|
||
private static final Map<String, String> XRAY_CLOUD_PLATFORM; | ||
|
||
// _OTHER request method: | ||
// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/http.md?plain=1#L96 | ||
private static final String _OTHER_REQUEST_METHOD = "_OTHER"; | ||
|
||
static { | ||
Map<String, String> xrayCloudPlatform = new HashMap<>(); | ||
xrayCloudPlatform.put(AWS_EC2, "AWS::EC2::Instance"); | ||
|
@@ -181,15 +188,24 @@ boolean matches(Attributes attributes, Resource resource) { | |
String host = null; | ||
|
||
for (Map.Entry<AttributeKey<?>, Object> entry : attributes.asMap().entrySet()) { | ||
if (entry.getKey().equals(HTTP_TARGET)) { | ||
if (entry.getKey().equals(HTTP_TARGET) || entry.getKey().equals(UrlAttributes.URL_PATH)) { | ||
httpTarget = (String) entry.getValue(); | ||
} else if (entry.getKey().equals(HTTP_URL)) { | ||
} else if (entry.getKey().equals(HTTP_URL) || entry.getKey().equals(UrlAttributes.URL_FULL)) { | ||
httpUrl = (String) entry.getValue(); | ||
} else if (entry.getKey().equals(HTTP_METHOD)) { | ||
} else if (entry.getKey().equals(HTTP_METHOD) | ||
|| entry.getKey().equals(HttpAttributes.HTTP_REQUEST_METHOD)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me take a look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added logic to check for _OTHER and to use |
||
httpMethod = (String) entry.getValue(); | ||
} else if (entry.getKey().equals(NET_HOST_NAME)) { | ||
// according to semantic conventions, if the HTTP request method is not known to | ||
// instrumentation, it must be set to _OTHER and the | ||
// HTTP_REQUEST_METHOD_ORIGINAL should contain the original method | ||
if (httpMethod.equals(_OTHER_REQUEST_METHOD)) { | ||
httpMethod = attributes.get(HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL); | ||
} | ||
} else if (entry.getKey().equals(NET_HOST_NAME) | ||
|| entry.getKey().equals(ServerAttributes.SERVER_ADDRESS)) { | ||
host = (String) entry.getValue(); | ||
} else if (entry.getKey().equals(HTTP_HOST)) { | ||
} else if (entry.getKey().equals(HTTP_HOST) | ||
|| entry.getKey().equals(ServerAttributes.SERVER_ADDRESS)) { | ||
// TODO (trask) remove support for deprecated http.host attribute | ||
host = (String) entry.getValue(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server instrumentations don't fill
url.full
, would that be an issue?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be fine. It's there incase URL_PATH isn't being populated and the idea here is to then extract the path from URL_FULL.