Skip to content

Commit

Permalink
[exporter/awsxray] Refactor fault/error logic (#26681)
Browse files Browse the repository at this point in the history
**Description:** 
This PR just refactors the logic in the awsxrayexporter as it was hard
to follow the logical flow of the code. No functional changes.
  • Loading branch information
harrryr authored Sep 19, 2023
1 parent 2d45ad6 commit 76687fb
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,29 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p

val, ok := span.Attributes().Get(conventions.AttributeHTTPStatusCode)

switch {
// 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.
switch {
case code >= 400 && code <= 499:
isError = true
isFault = false
if code == 429 {
isThrottle = true
}
case code >= 500 && code <= 599:
isError = false
isThrottle = false
isFault = true
case status.Code() == ptrace.StatusCodeError:
isError = false
isThrottle = false
var code int64
if ok {
code = val.Int()
}

// Default values
isThrottle = false
isError = false
isFault = false

switch {
case !ok || code < 400 || code > 599:
if status.Code() == ptrace.StatusCodeError {
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
case code >= 400 && code <= 499:
isError = true
if code == 429 {
isThrottle = true
}
case code >= 500 && code <= 599:
isFault = true
}

Expand Down

0 comments on commit 76687fb

Please sign in to comment.