Skip to content

Commit

Permalink
[exporter/awsxray] Fix X-Ray Segment status code (open-telemetry#24381)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
The conversion from HTTP spans to X-Ray segments did not accurately
capture the HTTP status code during the translation of the cause. As a
result, some failed HTTP requests with 4xx and 5xx status codes were
displayed as having an "OK" status in the X-Ray console. Also, add
remote attribute in Exception for X-Ray remote segments.

**Link to tracking Issue:** <Issue number if applicable>
N/A

**Testing:** <Describe what testing was performed and which tests were
added.>
unit test
**Documentation:** <Describe the documentation added.>
N/A
  • Loading branch information
mxiamxia authored Aug 2, 2023
1 parent 619ae4a commit d35fd1d
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 38 deletions.
20 changes: 20 additions & 0 deletions .chloggen/fix-xray-segment-status-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# 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: 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]

# (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:
36 changes: 28 additions & 8 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 @@ -117,24 +121,35 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
val, ok := span.Attributes().Get(conventions.AttributeHTTPStatusCode)

switch {
case status.Code() != ptrace.StatusCodeError:
isError = false
isThrottle = false
isFault = false
// The segment status for http spans will be based on their http.statuscode as we found some http
// spans does not fill with status.Code() but always filled with http.statuscode
case ok:
code := val.Int()
// We only differentiate between faults (server errors) and errors (client errors) for HTTP spans.
if code >= 400 && code <= 499 {
switch {
case code >= 400 && code <= 499:
isError = true
isFault = false
if code == 429 {
isThrottle = true
}
} else {
case code >= 500 && code <= 599:
isError = false
isThrottle = false
isFault = true
case status.Code() == ptrace.StatusCodeError:
isError = false
isThrottle = false
isFault = true
default:
isError = false
isThrottle = false
isFault = false
}
case status.Code() != ptrace.StatusCodeError:
isError = false
isThrottle = false
isFault = false
default:
isError = false
isThrottle = false
Expand All @@ -144,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 @@ -181,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 @@ -248,6 +265,7 @@ func fillJavaStacktrace(stacktrace string, exceptions []awsxray.Exception) []aws
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 @@ -287,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 @@ -344,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 d35fd1d

Please sign in to comment.