Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb2a9b5

Browse files
committedOct 17, 2022
Manually add OTEL context to both root spans
According to open-telemetry/opentelemetry-rust#888 (comment), this works around the issue where the root span is missing from the traces. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
1 parent ee7f609 commit bb2a9b5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎conmon-rs/server/src/server.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use nix::{
2222
sys::signal::Signal,
2323
unistd::{fork, ForkResult},
2424
};
25+
use opentelemetry::trace::FutureExt as OpenTelemetryFutureExt;
2526
use std::{fs::File, io::Write, path::Path, process, str::FromStr, sync::Arc};
2627
use tokio::{
2728
fs,
@@ -32,6 +33,7 @@ use tokio::{
3233
};
3334
use tokio_util::compat::TokioAsyncReadCompatExt;
3435
use tracing::{debug, debug_span, info, Instrument};
36+
use tracing_opentelemetry::OpenTelemetrySpanExt;
3537
use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, prelude::*};
3638
use twoparty::VatNetwork;
3739

@@ -162,19 +164,24 @@ impl Server {
162164
let (shutdown_tx, shutdown_rx) = oneshot::channel();
163165
let socket = self.config().socket();
164166
let reaper = self.reaper.clone();
167+
168+
let signal_handler_span = debug_span!("signal_handler");
165169
task::spawn(
166170
Self::start_signal_handler(reaper, socket, shutdown_tx)
167-
.instrument(debug_span!("signal_handler")),
171+
.with_context(signal_handler_span.context())
172+
.instrument(signal_handler_span),
168173
);
169174

175+
let backend_span = debug_span!("backend");
170176
task::spawn_blocking(move || {
171177
Handle::current().block_on(
172178
async {
173179
LocalSet::new()
174180
.run_until(self.start_backend(shutdown_rx))
175181
.await
176182
}
177-
.instrument(debug_span!("backend")),
183+
.with_context(backend_span.context())
184+
.instrument(backend_span),
178185
)
179186
})
180187
.await?

0 commit comments

Comments
 (0)
Please sign in to comment.