-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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
- Register a metrics callback that panics:
_, err := meter.RegisterCallback(
func(ctx context. Context, observer metric.Observer) error {
// Simulate a panic
panic("unexpected error")
},
instrument,
)- Wait for the periodic reader or metrics pipeline to collect metrics
- 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.