Allow overriding or customizing span.RecordError() behavior globally #6754
Labels
blocked:specification
Waiting on clarification of the OpenTelemetry specification before progress can be made
enhancement
New feature or request
Uh oh!
There was an error while loading. Please reload this page.
Summary
I’d like to propose a mechanism to allow users to override or hook into span.RecordError() globally — for example, to enrich error-related span events with custom attributes consistently across all instrumented libraries.
Motivation
Currently, there is no clean way to globally customize the behavior of span.RecordError().
In my use case, I want to inject an additional attribute (e.g., custom.source = "internal") into every exception span event, regardless of which instrumentation library triggered it (Gin, Mux, Fiber, etc.).
While it’s technically possible to:
Manually call span.AddEvent("exception", ...) with custom attributes, or
Wrap span.RecordError() in user code,
…these solutions are not scalable across large codebases or libraries using auto-instrumentation.
What I tried
SpanProcessor: Can observe exception events in OnEnd(), but cannot mutate span data (it's read-only).
SpanExporter: Allows exporting enriched data, but this requires duplicating span data structures or intercepting and transforming OTLP payloads — which feels heavy-handed for a relatively simple customization.
Proposal
Introduce a hook or registry mechanism (e.g., otel.SetErrorRecorder(...)) where users can globally define how RecordError() enriches the span. This would preserve the default behavior while allowing teams to attach custom tags, redactions, or formatting logic.
The text was updated successfully, but these errors were encountered: