Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: attempt to add trace context to logs #547

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,6 @@ grit_beta = [
"remote_workflows",
"workflow_server",
# "grit_timing",
# "grit_tracing",
]
grit_timing = []
28 changes: 22 additions & 6 deletions crates/cli/src/tracing_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,28 @@ where
log_record.severity_number = Some(severity_of_level(meta.level()));
log_record.severity_text = Some(meta.level().to_string().into());

// Extract the trace_id & span_id from the opentelemetry extension.
// This isn't really working for us.
// set_trace_context(&mut log_record, &_ctx);

// Not populating ObservedTimestamp, instead relying on OpenTelemetry
// API to populate it with current time.
// Extract the trace_id & span_id from *tracing*, which propagates across async boundaries better
use opentelemetry::trace::TraceContextExt;
use tracing_opentelemetry::OpenTelemetrySpanExt;
let s = tracing::Span::current().context();

if s.has_active_span() {
let sr = s.span();
let sc = sr.span_context();
let trace_id = sc.trace_id();
let span_id = sc.span_id();
log_record.trace_context = Some(opentelemetry::logs::TraceContext::from(
&opentelemetry::trace::SpanContext::new(
trace_id,
span_id,
opentelemetry::trace::TraceFlags::default(),
false,
opentelemetry::trace::TraceState::default(),
),
));
} else {
// eprintln!("no active span");
}

let mut visitor = EventVisitor::default();
visitor.visit_metadata(meta);
Expand Down
Loading