Skip to content

fix(ext/otel): remove panicking unwraps in telemetry code#32557

Merged
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:fix/otel-unwrap-panics
Mar 9, 2026
Merged

fix(ext/otel): remove panicking unwraps in telemetry code#32557
bartlomieju merged 1 commit intodenoland:mainfrom
bartlomieju:fix/otel-unwrap-panics

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Replace .unwrap() calls on OTEL_GLOBALS.get() and isolate slot accesses
    with graceful error handling throughout ext/telemetry/lib.rs
  • GC prologue/epilogue callbacks now return early if the isolate slot is missing
    (can happen during isolate teardown in watch mode restarts)
  • op_otel_enable_isolate_metrics / op_otel_collect_isolate_metrics return
    early if globals or slots are not available
  • OtelTracer::builtin(), OtelTracer::start_span(),
    OtelTracer::start_span_foreign(), and OtelMeter::new() return JS errors
    instead of panicking

Context

These unwraps could panic in watch mode when:

  1. V8 GC callbacks fire during isolate teardown after slots have been cleaned up
  2. OTEL globals are accessed before initialization completes

Refs: #29478
Refs: #30567

Test plan

  • Existing otel spec tests pass (confirmed no regressions in passing tests)
  • Manual testing with OTEL_DENO=true deno run --watch + rapid file changes shows no panics

Replace `.unwrap()` calls on `OTEL_GLOBALS.get()` and isolate slot
accesses with graceful error handling. These unwraps could panic
during watch mode restarts when the isolate is being torn down
(GC callbacks fire after slots are cleaned up) or if OTEL globals
are not yet initialized.

- GC prologue/epilogue callbacks: return early if isolate slot is gone
- op_otel_enable_isolate_metrics: return early if OTEL_GLOBALS unset
- op_otel_collect_isolate_metrics: return early if slot is gone
- OtelTracer/OtelMeter constructors: return JS errors instead of panicking

Refs: denoland#29478
Refs: denoland#30567

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@kajukitli kajukitli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm — good defensive fix for watch mode crashes

all the changes are straightforward:

  • .unwrap().ok_or_else() with proper JS error for ops
  • .unwrap() → early return for GC callbacks (can't propagate errors from V8 callbacks anyway)
  • isolate slot access now guards against teardown race conditions

the GC callbacks returning early is the right approach since they're called from V8 and can't meaningfully report errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants