Skip to content
Open
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/containerd-shimkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ opentelemetry-otlp = { version = "0.16.0", default-features = false, features =
"grpc-tonic",
"http-proto",
"reqwest-client",
"reqwest-rustls",
"trace",
], optional = true }
opentelemetry_sdk = { version = "0.23", default-features = false, features = [
Expand Down
15 changes: 10 additions & 5 deletions crates/containerd-shimkit/src/sandbox/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,18 @@ where
}

#[cfg(feature = "opentelemetry")]
if otel_traces_enabled() {
// Only initialize OTEL in serve mode (empty action).
if otel_traces_enabled() && flags.action.is_empty() {
// opentelemetry uses tokio, so we need to initialize a runtime
async {
let otlp_config = OtlpConfig::build_from_env().expect("Failed to build OtelConfig.");
let _guard = otlp_config
.init()
.expect("Failed to initialize OpenTelemetry.");
let _guard = OtlpConfig::build_from_env()
.and_then(|c| c.init())
.map_err(|e| {
eprintln!(
"Failed to initialize OpenTelemetry (continuing without tracing): {e}"
)
})
.ok();
tokio::task::block_in_place(move || {
shim_main_inner::<I>(name, config);
});
Expand Down
4 changes: 2 additions & 2 deletions crates/containerd-shimkit/src/sandbox/shim/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Config {
/// Initializes the tracer, sets up the telemetry and subscriber layers, and sets the global subscriber.
///
/// Note: this function should be called only once and be called by the binary entry point.
pub fn init(&self) -> anyhow::Result<impl Drop> {
pub fn init(&self) -> anyhow::Result<ShutdownGuard> {
let tracer = self.init_tracer()?;
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
set_text_map_propagator(TraceContextPropagator::new());
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Config {

/// Shutdown of the open telemetry services will automatically called when the OtelConfig instance goes out of scope.
#[must_use]
struct ShutdownGuard;
pub struct ShutdownGuard;

impl Drop for ShutdownGuard {
fn drop(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shimkit/src/sandbox/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<T> WaitableCell<T> {
/// The function `f` will always be called, regardless of whether the `WaitableCell` has a value or not.
/// The `WaitableCell` is going to be set even in the case of an unwind. In this case, ff the function `f`
/// panics it will cause an abort, so it's recommended to avoid any panics in `f`.
pub fn set_guard_with<R: Into<T>, F: FnOnce() -> R>(&self, f: F) -> impl Drop + use<F, T, R> {
pub fn set_guard_with<R: Into<T>, F: FnOnce() -> R>(&self, f: F) -> impl Drop {
let cell = (*self).clone();
WaitableCellSetGuard { f: Some(f), cell }
}
Expand Down
Loading