Skip to content

Commit

Permalink
Refactor fault/error logic
Browse files Browse the repository at this point in the history
  • Loading branch information
harrryr committed Sep 13, 2023
1 parent aadfba7 commit 9a32258
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions exporter/awsxrayexporter/internal/translator/cause.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,41 +118,34 @@ func makeCause(span ptrace.Span, attributes map[string]pcommon.Value, resource p
}
}

// The logic to record error and fault should be kept in sync with the ADOT pulse repo whenever possible except for the throttle
// https://github.com/aws-observability/aws-apm-java-instrumentation/blob/main/awsagentprovider/src/main/java/software/amazon/opentelemetry/javaagent/providers/AwsSpanMetricsProcessor.java
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:
var code int64
if ok {
code = val.Int()
}
isThrottle = false
switch {
case !ok || code < 400 || code > 599:
if status.Code() == ptrace.StatusCodeError {
isError = false
isThrottle = false
isFault = true
default:
} else {
isError = false
isThrottle = false
isFault = false
}
case status.Code() != ptrace.StatusCodeError:
isError = false
isThrottle = false
case code >= 400 && code <= 499:
isError = true
isFault = false
default:
if code == 429 {
isThrottle = true
}
case code >= 500 && code <= 599:
isError = false
isThrottle = false
isFault = true
}

Expand Down

0 comments on commit 9a32258

Please sign in to comment.