Skip to content

Commit 1c0f236

Browse files
authored
fix(unstable): don't unwrap optional state in otel (#27292)
otel global state may not be initialized if otel is not enabled, so bail out instead of panicking. Fixes: #27272
1 parent da3a676 commit 1c0f236

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ext/telemetry/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,9 @@ fn op_otel_instrumentation_scope_enter(
732732

733733
#[op2(fast)]
734734
fn op_otel_instrumentation_scope_enter_builtin(state: &mut OpState) {
735-
state.put(InstrumentationScope(
736-
BUILT_IN_INSTRUMENTATION_SCOPE.get().unwrap().clone(),
737-
));
735+
if let Some(scope) = BUILT_IN_INSTRUMENTATION_SCOPE.get() {
736+
state.put(InstrumentationScope(scope.clone()));
737+
}
738738
}
739739

740740
#[op2(fast)]
@@ -749,6 +749,9 @@ fn op_otel_log(
749749
let Some(Processors { logs, .. }) = OTEL_PROCESSORS.get() else {
750750
return;
751751
};
752+
let Some(instrumentation_scope) = BUILT_IN_INSTRUMENTATION_SCOPE.get() else {
753+
return;
754+
};
752755

753756
// Convert the integer log level that ext/console uses to the corresponding
754757
// OpenTelemetry log severity.
@@ -776,10 +779,7 @@ fn op_otel_log(
776779
);
777780
}
778781

779-
logs.emit(
780-
&mut log_record,
781-
BUILT_IN_INSTRUMENTATION_SCOPE.get().unwrap(),
782-
);
782+
logs.emit(&mut log_record, instrumentation_scope);
783783
}
784784

785785
fn owned_string<'s>(

ext/telemetry/telemetry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ function submitSpan(
220220
startTime: number,
221221
endTime: number,
222222
) {
223+
if (!TRACING_ENABLED) return;
223224
if (!(traceFlags & TRACE_FLAG_SAMPLED)) return;
224225

225226
// TODO(@lucacasonato): `resource` is ignored for now, should we implement it?

0 commit comments

Comments
 (0)