Skip to content

Commit

Permalink
feat: set error field if HTTP status >= 400 (#248)
Browse files Browse the repository at this point in the history
## Short description of the changes

Distinguish between server (status >= 500) and client (500 > status >=
400) errors by noting that in the value for the error field instead of
only marking error as true or false.
  • Loading branch information
robbkidd authored Sep 27, 2023
1 parent 0960d2d commit 18b10b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handlers/libhoney_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ func (handler *libhoneyEventHandler) handleEvent(event assemblers.HttpEvent) {
// response attributes
if event.Response != nil {
ev.AddField(string(semconv.HTTPResponseStatusCodeKey), event.Response.StatusCode)
// We cannot quite follow the OTel spec for HTTP instrumentation and OK/Error Status.
// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.25.0/specification/trace/semantic_conventions/http.md#status
// We don't (yet?) have a way to determine the client-or-server perspective of the event,
// so we'll set the "error" field to the general category of the error status codes.
if event.Response.StatusCode >= 500 {
ev.AddField("error", "HTTP server error")
} else if event.Response.StatusCode >= 400 {
ev.AddField("error", "HTTP client error")
}
ev.AddField(string(semconv.HTTPResponseBodySizeKey), event.Response.ContentLength)

} else {
Expand Down
1 change: 1 addition & 0 deletions handlers/libhoney_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func Test_libhoneyEventHandler_handleEvent(t *testing.T) {
"http.response.timestamp": testReqTime.Add(3 * time.Millisecond),
"http.response.status_code": 418,
"http.response.body.size": int64(84),
"error": "HTTP client error",
"duration_ms": int64(3),
"user_agent.original": "teapot-checker/1.0",
"source.k8s.namespace.name": "unit-tests",
Expand Down

0 comments on commit 18b10b1

Please sign in to comment.