Skip to content

Commit 74f97ed

Browse files
committed
Add nested span in example, use ctx.lookup_current
1 parent 868ca59 commit 74f97ed

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

opentelemetry-appender-tracing/examples/basic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ fn main() {
2323
let layer = layer::OpenTelemetryTracingBridge::new(&provider);
2424
tracing_subscriber::registry().with(layer).init();
2525

26+
info_span!("my-span").in_scope(|| {
27+
info!(target: "my-system", "an info log");
28+
})
29+
2630
error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]");
2731
drop(provider);
2832
}

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where
105105
log_record.severity_text = Some(meta.level().to_string().into());
106106

107107
// Extract the trace_id & span_id from the opentelemetry extension.
108-
if let Some((trace_id, span_id)) = ctx.event_span(event).and_then(|span| {
108+
if let Some((trace_id, span_id)) = ctx.lookup_current().and_then(|span| {
109109
span.extensions()
110110
.get::<OtelData>()
111111
.and_then(|ext| ext.builder.trace_id.zip(ext.builder.span_id))

0 commit comments

Comments
 (0)