Skip to content

Commit

Permalink
Add support to handle 402, 413, 414, 431 http error code as permanent…
Browse files Browse the repository at this point in the history
… errors in OTLP exporter open-telemetry#5674

 - change ifs to a switch statement
  • Loading branch information
mcmho committed Jul 19, 2022
1 parent 2c2c663 commit 15ecbfb
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,29 @@ func (e *exporter) export(ctx context.Context, url string, request []byte) error
}

func isPermanentClientFailure(code int) bool {
// 400 - bad request
if code == http.StatusBadRequest {
return true
}

// 402 - payment required typically means that an auth token isn't valid anymore and as such, we deem it as permanent
if code == http.StatusPaymentRequired {
return true
}

// 413 - request size is too large
if code == http.StatusRequestEntityTooLarge {
return true
}

// 414 - uri is too long
if code == http.StatusRequestURITooLong {
return true
}

// 431 - headers too large
if code == http.StatusRequestHeaderFieldsTooLarge {
return true
}

return false
var isPermanentError bool

switch code {
case http.StatusBadRequest:
// 400 - bad request
isPermanentError = true
case http.StatusPaymentRequired:
// 402 - payment required typically means that an auth token isn't valid anymore and as such, we deem it as permanent
isPermanentError = true
case http.StatusRequestEntityTooLarge:
// 413 - request size is too large
isPermanentError = true
case http.StatusRequestURITooLong:
// 414 - uri is too long
isPermanentError = true
case http.StatusRequestHeaderFieldsTooLarge:
// 431 - headers too large
isPermanentError = true
default:
isPermanentError = false
}

return isPermanentError
}

// Read the response and decode the status.Status from the body.
Expand Down

0 comments on commit 15ecbfb

Please sign in to comment.