Skip to content

Commit

Permalink
Manually add OTEL context to both root spans
Browse files Browse the repository at this point in the history
According to
open-telemetry/opentelemetry-rust#888 (comment),
this works around the current the cases where the root span is missing
from the traces.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Oct 17, 2022
1 parent ee7f609 commit 63c0164
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions conmon-rs/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use nix::{
sys::signal::Signal,
unistd::{fork, ForkResult},
};
use opentelemetry::trace::FutureExt as OpenTelemetryFutureExt;
use std::{fs::File, io::Write, path::Path, process, str::FromStr, sync::Arc};
use tokio::{
fs,
Expand All @@ -32,6 +33,7 @@ use tokio::{
};
use tokio_util::compat::TokioAsyncReadCompatExt;
use tracing::{debug, debug_span, info, Instrument};
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_subscriber::{filter::LevelFilter, layer::SubscriberExt, prelude::*};
use twoparty::VatNetwork;

Expand Down Expand Up @@ -162,19 +164,24 @@ impl Server {
let (shutdown_tx, shutdown_rx) = oneshot::channel();
let socket = self.config().socket();
let reaper = self.reaper.clone();

let signal_handler_span = debug_span!("signal_handler");
task::spawn(
Self::start_signal_handler(reaper, socket, shutdown_tx)
.instrument(debug_span!("signal_handler")),
.with_context(signal_handler_span.context())
.instrument(signal_handler_span),
);

let backend_span = debug_span!("backend");
task::spawn_blocking(move || {
Handle::current().block_on(
async {
LocalSet::new()
.run_until(self.start_backend(shutdown_rx))
.await
}
.instrument(debug_span!("backend")),
.with_context(backend_span.context())
.instrument(backend_span),
)
})
.await?
Expand Down

0 comments on commit 63c0164

Please sign in to comment.