Skip to content

trace-id missing in analytics records tags in error responses #7928

@lvielhauer

Description

@lvielhauer

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:

  1. Enable OpenTelemetry in tyk.conf
  2. 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
  3. 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().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions