containerd / rust-extensions

Rust crates to extend containerd
https://containerd.io
Apache License 2.0
172 stars 66 forks source link

shim: add tracing macros #269

Closed Mossaka closed 3 months ago

Mossaka commented 3 months ago

This PR introduces tracing instrumentation to the shim crate. It will allow us to collect detailed function entry and exit, args and returns to understand the behaviour of the shim process.

An use case for runwasi shim is that it will collect the traces and transform them to OTLP traces and output them to an jeager endpoint (see https://github.com/containerd/runwasi/pull/582).

From my observation the perf overhead with tracing macros is minimal. If this is a concern, we can try disabling tracing staticlly. Statically, we may use rust conditional compilation feature to add either compile or ignore tracing macros that are added to each function.

Update: I've created a new shim_instrument proc-macro that will statically disable/enable tracing for each function. if the feature tracing is not enabled, the instrument macro is acts as a no-opt. Otherwise, it will apply tracing::instrument to that function.

mxpv commented 3 months ago

Do we need to maintain one more crate for this? This seems to be achievable with:

#[cfg_attr(feature = "tracing", tracing::instrument)]
Mossaka commented 3 months ago

Do we need to maintain one more crate for this? This seems to be achievable with:

#[cfg_attr(feature = "tracing", tracing::instrument)]

Ah yeah this looks like a better idea 👍.

mxpv commented 3 months ago

Same applies to level.

Unless overridden, a span with the [INFO] will be generated.