Skip to content

Commit

Permalink
Add the missing remote flag for X-Ray remote segment exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mxiamxia committed Jul 21, 2023
1 parent f0cff2f commit 21e9a64
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .chloggen/fix-xray-segment-status-attributes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ change_type: bug_fix
component: awsxrayexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix X-Ray Segment status code for otel http spans.
note: Fix X-Ray Segment status code and exception translations.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24381]
Expand Down
20 changes: 14 additions & 6 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
if val, ok := resource.Attributes().Get(conventions.AttributeTelemetrySDKLanguage); ok {
language = val.Str()
}
isRemote := false
if span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer {
isRemote = true
}

var exceptions []awsxray.Exception
for i := 0; i < span.Events().Len(); i++ {
Expand All @@ -70,7 +74,7 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
stacktrace = val.Str()
}

parsed := parseException(exceptionType, message, stacktrace, language)
parsed := parseException(exceptionType, message, stacktrace, isRemote, language)
exceptions = append(exceptions, parsed...)
}
}
Expand Down Expand Up @@ -155,12 +159,13 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
return isError, isFault, isThrottle, filtered, cause
}

func parseException(exceptionType string, message string, stacktrace string, language string) []awsxray.Exception {
func parseException(exceptionType string, message string, stacktrace string, isRemote bool, language string) []awsxray.Exception {
exceptions := make([]awsxray.Exception, 0, 1)
segmentID := newSegmentID()
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(exceptionType),
Remote: aws.Bool(isRemote),
Message: aws.String(message),
})

Expand Down Expand Up @@ -192,6 +197,7 @@ func fillJavaStacktrace(stacktrace string, exceptions []awsxray.Exception) []aws

// Skip first line containing top level message
exception := &exceptions[0]
isRemote := exception.Remote
_, err := r.ReadLine()
if err != nil {
return exceptions
Expand Down Expand Up @@ -250,16 +256,16 @@ func fillJavaStacktrace(stacktrace string, exceptions []awsxray.Exception) []aws
if strings.HasPrefix(line, "\tat ") && strings.IndexByte(line, '(') >= 0 && line[len(line)-1] == ')' {
// Stack frame (hopefully, user can masquerade since we only have a string), process above.
break
} else {
// String append overhead in this case, but multiline messages should be far less common than single
// line ones.
causeMessage += line
}
// String append overhead in this case, but multiline messages should be far less common than single
// line ones.
causeMessage += line
}
segmentID := newSegmentID()
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(causeType),
Remote: isRemote,
Message: aws.String(causeMessage),
Stack: nil,
})
Expand Down Expand Up @@ -299,6 +305,7 @@ func fillPythonStacktrace(stacktrace string, exceptions []awsxray.Exception) []a
}
line := lines[lineIdx]
exception := &exceptions[0]
isRemote := exception.Remote

exception.Stack = nil
for {
Expand Down Expand Up @@ -356,6 +363,7 @@ func fillPythonStacktrace(stacktrace string, exceptions []awsxray.Exception) []a
exceptions = append(exceptions, awsxray.Exception{
ID: aws.String(hex.EncodeToString(segmentID[:])),
Type: aws.String(causeType),
Remote: isRemote,
Message: aws.String(causeMessage),
})
// when append causes `exceptions` to outgrow its existing
Expand Down
Loading

0 comments on commit 21e9a64

Please sign in to comment.