-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[exporter/awsxray] Add aws sdk http error events to x-ray subsegment and strip prefix AWS.SDK.
from aws remote service name
#27232
Changes from 1 commit
7c037ad
e846069
1c22163
7a8d8a6
bfbafbe
c2cf435
d0f2f34
dc08418
2b09464
52a45ff
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: awsxrayexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Convert individual HTTP error events into exceptions within subsegments for AWS SDK spans and strip AWS.SDK prefix from remote aws service name | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [27232] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ import ( | |
// ExceptionEventName the name of the exception event. | ||
// TODO: Remove this when collector defines this semantic convention. | ||
const ExceptionEventName = "exception" | ||
const AwsIndividualHTTPEventName = "HTTP request failure" | ||
const AwsIndividualHTTPErrorEventType = "aws.http.error.event" | ||
const AwsIndividualHTTPErrorCodeAttr = "http.response.status_code" | ||
const AwsIndividualHTTPErrorMsgAttr = "aws.http.error_message" | ||
|
||
func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource pcommon.Resource) (isError, isFault, isThrottle bool, | ||
filtered map[string]pcommon.Value, cause *awsxray.CauseData) { | ||
|
@@ -34,17 +38,23 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p | |
errorKind string | ||
) | ||
|
||
isAwsSdkSpan := isAwsSdkSpan(span) | ||
hasExceptions := false | ||
hasAwsIndividualHTTPError := false | ||
for i := 0; i < span.Events().Len(); i++ { | ||
event := span.Events().At(i) | ||
if event.Name() == ExceptionEventName { | ||
hasExceptions = true | ||
break | ||
} | ||
if isAwsSdkSpan && event.Name() == AwsIndividualHTTPEventName { | ||
hasAwsIndividualHTTPError = true | ||
break | ||
} | ||
} | ||
|
||
switch { | ||
case hasExceptions: | ||
case hasExceptions || hasAwsIndividualHTTPError: | ||
language := "" | ||
if val, ok := resource.Attributes().Get(conventions.AttributeTelemetrySDKLanguage); ok { | ||
language = val.Str() | ||
|
@@ -76,6 +86,22 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p | |
|
||
parsed := parseException(exceptionType, message, stacktrace, isRemote, language) | ||
exceptions = append(exceptions, parsed...) | ||
} else if isAwsSdkSpan && event.Name() == AwsIndividualHTTPEventName { | ||
errorCode, ok1 := event.Attributes().Get(AwsIndividualHTTPErrorCodeAttr) | ||
errorMessage, ok2 := event.Attributes().Get(AwsIndividualHTTPErrorMsgAttr) | ||
if ok1 && ok2 { | ||
timestamp := event.Timestamp().String() | ||
strs := []string{errorCode.AsString(), timestamp, errorMessage.Str()} | ||
message = strings.Join(strs, "@") | ||
segmentID := newSegmentID() | ||
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. Is this segment id meaningless? 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. On line 98 we do use it the ID of the exception, since X-Ray exceptions require an ID. I am not aware of any constraints or validations on the ID (for example, whether it needs to be a segment ID format vs. any unique string) |
||
exception := awsxray.Exception{ | ||
ID: aws.String(hex.EncodeToString(segmentID[:])), | ||
Type: aws.String(AwsIndividualHTTPErrorEventType), | ||
Remote: aws.Bool(true), | ||
Message: aws.String(message), | ||
} | ||
exceptions = append(exceptions, exception) | ||
} | ||
} | ||
} | ||
cause = &awsxray.CauseData{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,14 @@ func MakeSegmentDocumentString(span ptrace.Span, resource pcommon.Resource, inde | |
return jsonStr, nil | ||
} | ||
|
||
func isAwsSdkSpan(span ptrace.Span) bool { | ||
attributes := span.Attributes() | ||
if rpcSystem, ok := attributes.Get(conventions.AttributeRPCSystem); ok { | ||
return rpcSystem.Str() == "aws-api" | ||
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. const aws-api 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. I will define the string as a const |
||
} | ||
return false | ||
} | ||
|
||
// MakeSegment converts an OpenTelemetry Span to an X-Ray Segment | ||
func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []string, indexAllAttrs bool, logGroupNames []string, skipTimestampValidation bool) (*awsxray.Segment, error) { | ||
var segmentType string | ||
|
@@ -130,6 +138,10 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str | |
if span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer { | ||
if remoteServiceName, ok := attributes.Get(awsRemoteService); ok { | ||
name = remoteServiceName.Str() | ||
// only strip the prefix for AWS spans | ||
if isAwsSdkSpan(span) && strings.HasPrefix(name, "AWS.SDK.") { | ||
name = strings.TrimPrefix(name, "AWS.SDK.") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -142,10 +154,8 @@ func MakeSegment(span ptrace.Span, resource pcommon.Resource, indexedAttrs []str | |
} | ||
|
||
if namespace == "" { | ||
if rpcSystem, ok := attributes.Get(conventions.AttributeRPCSystem); ok { | ||
if rpcSystem.Str() == "aws-api" { | ||
namespace = conventions.AttributeCloudProviderAWS | ||
} | ||
if isAwsSdkSpan(span) { | ||
namespace = conventions.AttributeCloudProviderAWS | ||
} | ||
} | ||
|
||
|
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.
Does hasExceptions must be true when hasAwsIndividualHTTPError is true? If not, is it better to move hasAwsIndividualHTTPError to a new case?
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.
To my knowledge, they are independent of each other. None, either, or both may be
true
.A separate
case
would create different logic though. If the cases are separate, then the code is mutually exclusive.Current: a span will create X-Ray exceptions for both
exception
andHTTP request failure
eventsIf we move to a separate case: a span will only create X-Ray exceptions from
exception
events, unless noexception events
exist, then the span may create X-Ray exceptions fromHTTP request failure
eventsSo I am in favor of the current structure