Skip to content

SDK does not recover from panics in metrics callbacks #7730

@loganrosen

Description

@loganrosen

Description

When registering a metrics callback (e.g., with RegisterCallback or via instrument callback options), the OpenTelemetry Go SDK does not recover from panics within user-provided callback functions. If a panic occurs in a metrics callback, it propagates and can crash the metrics pipeline or the entire application. This behavior is inconsistent with Go's defensive programming practices and can lead to production outages due to non-critical telemetry failures.

Environment

  • OS: Linux
  • Architecture: x86_64
  • Go Version: 1.25.5
  • opentelemetry-go version: v1.39.0

Steps To Reproduce

  1. Register a metrics callback that panics:
_, err := meter.RegisterCallback(
    func(ctx context. Context, observer metric.Observer) error {
        // Simulate a panic
        panic("unexpected error")
    },
    instrument,
)
  1. Wait for the periodic reader or metrics pipeline to collect metrics
  2. Observe that the panic propagates and crashes the process

Expected behavior

Panics in user callbacks should be recovered by the SDK. Panics should be logged (with stack trace), converted to errors in the metrics pipeline, and not crash the application. Other callbacks in the collection cycle should continue to run.

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions