Skip to content

Allow overriding or customizing span.RecordError() behavior globally #6754

Open
@Bhogayata-Keval

Description

@Bhogayata-Keval

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked:specificationWaiting on clarification of the OpenTelemetry specification before progress can be madeenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions