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 issue 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 9240f2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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
2 changes: 1 addition & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ var _ = Describe("ConmonClient", func() {
rssAfter := vmRSSGivenPID(pid)
GinkgoWriter.Printf("VmRSS after: %d\n", rssAfter)
GinkgoWriter.Printf("VmRSS diff: %d\n", rssAfter-rssBefore)
Expect(rssAfter - rssBefore).To(BeNumerically("<", 1200))
Expect(rssAfter - rssBefore).To(BeNumerically("<", 1500))
})
}
})
Expand Down

0 comments on commit 9240f2f

Please sign in to comment.