Skip to content

Commit

Permalink
fix(unstable): don't unwrap optional state in otel (#27292)
Browse files Browse the repository at this point in the history
otel global state may not be initialized if otel is not enabled, so bail
out instead of panicking.

Fixes: #27272
  • Loading branch information
devsnek authored Dec 9, 2024
1 parent da3a676 commit 1c0f236
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ext/telemetry/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,9 @@ fn op_otel_instrumentation_scope_enter(

#[op2(fast)]
fn op_otel_instrumentation_scope_enter_builtin(state: &mut OpState) {
state.put(InstrumentationScope(
BUILT_IN_INSTRUMENTATION_SCOPE.get().unwrap().clone(),
));
if let Some(scope) = BUILT_IN_INSTRUMENTATION_SCOPE.get() {
state.put(InstrumentationScope(scope.clone()));
}
}

#[op2(fast)]
Expand All @@ -749,6 +749,9 @@ fn op_otel_log(
let Some(Processors { logs, .. }) = OTEL_PROCESSORS.get() else {
return;
};
let Some(instrumentation_scope) = BUILT_IN_INSTRUMENTATION_SCOPE.get() else {
return;
};

// Convert the integer log level that ext/console uses to the corresponding
// OpenTelemetry log severity.
Expand Down Expand Up @@ -776,10 +779,7 @@ fn op_otel_log(
);
}

logs.emit(
&mut log_record,
BUILT_IN_INSTRUMENTATION_SCOPE.get().unwrap(),
);
logs.emit(&mut log_record, instrumentation_scope);
}

fn owned_string<'s>(
Expand Down
1 change: 1 addition & 0 deletions ext/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function submitSpan(
startTime: number,
endTime: number,
) {
if (!TRACING_ENABLED) return;
if (!(traceFlags & TRACE_FLAG_SAMPLED)) return;

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

0 comments on commit 1c0f236

Please sign in to comment.