Description
In PR #7402 , trace ID support was added to analytics records via SuccessHandler.addTraceIDTag(). This appends a trace-id-{traceID} tag to analytics records for successful requests.
However, error responses (e.g. 401 authentication failures) are recorded through a separate handler ErrorHandler.HandleError() in handler_error.go, which never calls addTraceIDTag(). As a result, analytics records for failed requests are missing the trace-id tag entirely, even when OpenTelemetry is enabled.
Steps to reproduce:
- Enable OpenTelemetry in tyk.conf
- Make a request that triggers a 401 (e.g. missing or invalid Authorization header) or other error that will be handled by handler_error.go
- Inspect the analytics record where the tags array has no trace-id-* entry
Expected: trace-id-{traceID} tag present in analytics records for all requests regardless of response code
Actual: trace-id-{traceID} tag only present in analytics records for successful requests (2xx)
Motivation and Context
Having the trace-id tag on analytics records provides a direct correlation between a specific request logged by Tyk and its corresponding distributed trace. This of course is especially important when investigating requests that resulted in an error. So adding the tag to error responses as well improves the ability to quickly debug any issues.
Suggested fix
Move addTraceIDTag from a method on SuccessHandler to a package-level function, and call it from ErrorHandler.HandleError() after the tags are built in the same way it is called in SuccessHandler.RecordHit().
Description
In PR #7402 , trace ID support was added to analytics records via SuccessHandler.addTraceIDTag(). This appends a trace-id-{traceID} tag to analytics records for successful requests.
However, error responses (e.g. 401 authentication failures) are recorded through a separate handler ErrorHandler.HandleError() in handler_error.go, which never calls addTraceIDTag(). As a result, analytics records for failed requests are missing the trace-id tag entirely, even when OpenTelemetry is enabled.
Steps to reproduce:
Expected: trace-id-{traceID} tag present in analytics records for all requests regardless of response code
Actual: trace-id-{traceID} tag only present in analytics records for successful requests (2xx)
Motivation and Context
Having the trace-id tag on analytics records provides a direct correlation between a specific request logged by Tyk and its corresponding distributed trace. This of course is especially important when investigating requests that resulted in an error. So adding the tag to error responses as well improves the ability to quickly debug any issues.
Suggested fix
Move addTraceIDTag from a method on SuccessHandler to a package-level function, and call it from ErrorHandler.HandleError() after the tags are built in the same way it is called in SuccessHandler.RecordHit().