Skip to content

Commit d113364

Browse files
authored
fix double-print to console of tracing events outside spans (#30)
1 parent b79b6d8 commit d113364

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/bridges/tracing.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ where
112112
// Need to emit this as a log, because it is not part of a span and will be lost
113113
// otherwise.
114114
emit_event_as_log_span(tracer, event, &tracing::Span::current());
115-
}
116-
if let Some(writer) = &tracer.console_writer {
115+
} else if let Some(writer) = &tracer.console_writer {
116+
// If it's not being emitted as a top-level log, need to print it to console
117+
// (if it's emitted, the console processor will handle it)
117118
writer.write_tracing_event(event);
118119
}
119120
});
@@ -286,7 +287,7 @@ mod tests {
286287
},
287288
parent_span_id: 0000000000000000,
288289
span_kind: Internal,
289-
name: "event src/bridges/tracing.rs:260",
290+
name: "event src/bridges/tracing.rs:261",
290291
start_time: SystemTime {
291292
tv_sec: 0,
292293
tv_nsec: 0,
@@ -1458,7 +1459,7 @@ mod tests {
14581459
"code.lineno",
14591460
),
14601461
value: I64(
1461-
268,
1462+
269,
14621463
),
14631464
},
14641465
],
@@ -1524,7 +1525,7 @@ mod tests {
15241525
"code.lineno",
15251526
),
15261527
value: I64(
1527-
269,
1528+
270,
15281529
),
15291530
},
15301531
],
@@ -1598,15 +1599,13 @@ mod tests {
15981599

15991600
assert_snapshot!(output, @r#"
16001601
1970-01-01T00:00:00.000000Z INFO logfire::bridges::tracing::tests root event
1601-
1970-01-01T00:00:00.000001Z INFO logfire::bridges::tracing::tests root event
1602-
1970-01-01T00:00:00.000002Z INFO logfire::bridges::tracing::tests root event with value field_value=1
1603-
1970-01-01T00:00:00.000003Z INFO logfire::bridges::tracing::tests root event with value field_value=1
1604-
1970-01-01T00:00:00.000004Z INFO logfire::bridges::tracing::tests root span
1605-
1970-01-01T00:00:00.000005Z INFO logfire::bridges::tracing::tests hello world span
1606-
1970-01-01T00:00:00.000006Z DEBUG logfire::bridges::tracing::tests debug span
1607-
1970-01-01T00:00:00.000007Z DEBUG logfire::bridges::tracing::tests debug span with explicit parent
1608-
1970-01-01T00:00:00.000008Z INFO logfire::bridges::tracing::tests hello world log
1609-
1970-01-01T00:00:00.000009Z INFO logfire::bridges::tracing::tests hello world log with value field_value=1
1602+
1970-01-01T00:00:00.000001Z INFO logfire::bridges::tracing::tests root event with value field_value=1
1603+
1970-01-01T00:00:00.000002Z INFO logfire::bridges::tracing::tests root span
1604+
1970-01-01T00:00:00.000003Z INFO logfire::bridges::tracing::tests hello world span
1605+
1970-01-01T00:00:00.000004Z DEBUG logfire::bridges::tracing::tests debug span
1606+
1970-01-01T00:00:00.000005Z DEBUG logfire::bridges::tracing::tests debug span with explicit parent
1607+
1970-01-01T00:00:00.000006Z INFO logfire::bridges::tracing::tests hello world log
1608+
1970-01-01T00:00:00.000007Z INFO logfire::bridges::tracing::tests hello world log with value field_value=1
16101609
"#);
16111610
}
16121611
}

0 commit comments

Comments
 (0)