Skip to content

Commit f5d990a

Browse files
committed
update error
1 parent 89e93c9 commit f5d990a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

middleware.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ func Middleware(componentName string) echo.MiddlewareFunc {
6262
if status := c.Response().Status; status >= 0 && status <= 65535 {
6363
ext.HTTPStatusCode.Set(sp, uint16(status))
6464
} else {
65-
// Either use a default value or log the issue
66-
ext.HTTPStatusCode.Set(sp, 0) // Using 0 to indicate invalid status
65+
// Set a valid status code in the trace
66+
ext.HTTPStatusCode.Set(sp, uint16(http.StatusInternalServerError))
67+
68+
// Update the actual response status if it hasn't been sent yet
69+
if !c.Response().Committed {
70+
c.Response().Status = http.StatusInternalServerError
71+
}
72+
73+
// Add error tag to span
74+
sp.SetTag("error.type", "invalid_status_code")
75+
sp.SetTag("error.message", "Invalid HTTP status detected")
6776
}
6877

6978
return nil

0 commit comments

Comments
 (0)