Skip to content

otel: add options to configure log level and span error status (WithLevel, WithErrorStatusLevel) - #25

Draft
thaJeztah wants to merge 12 commits into
containerd:mainfrom
thaJeztah:integrate_tracing_improve
Draft

otel: add options to configure log level and span error status (WithLevel, WithErrorStatusLevel)#25
thaJeztah wants to merge 12 commits into
containerd:mainfrom
thaJeztah:integrate_tracing_improve

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Aug 23, 2026

Copy link
Copy Markdown
Member

otel: add options to configure log level and span error status

These options make the containerd hook flexible enough to replace otellogrus (https://pkg.go.dev/github.com/uptrace/opentelemetry-go-extra/otellogrus) for consumers that currently use it for Logrus/OpenTelemetry integration combined with containerd/log. Callers can preserve their existing log-level filtering and span error-status behavior without needing a second tracing hook implementation.

otel: add option to configure log level

Add WithLevel to configure the minimum log level handled by the
OpenTelemetry hook.

This allows callers to limit which log entries are recorded as span
events, reducing trace noise and overhead when lower-severity logs are
not useful for tracing.

By default, the hook continues to handle all log levels, preserving
the existing behavior.

otel: add option to set span error status

Add WithErrorStatusLevel to configure the minimum log level that marks
an active span with an error status.

This allows callers to reflect sufficiently severe log entries in the
span status while keeping the behavior independent from attached error
fields.

By default, log entries continue to leave the span status unchanged.

@thaJeztah
thaJeztah force-pushed the integrate_tracing_improve branch 3 times, most recently from 187bc04 to 0ae6429 Compare August 23, 2026 11:54
cpuguy83 and others added 12 commits August 23, 2026 17:48
This adds valuable logging data to the open telemetry traces.

When the trace is not recording we don't bother doing anything as it is
relatively expensive to convert logrus data to otel just due to the
nature of how logrus works.

The way this works is that we now set a context on the logrus.Entry that
gets passed around which the hook then uses to determine if there is an
active span to forward the logs to.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This fixes the issue with the usage of the deprecated attribute.Any
function that original caused build issues.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Swagat Bora <sbora@amazon.com>
Signed-off-by: Swagat Bora <sbora@amazon.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
While the hook is intended to be used with logrus, we don't need to have
the direct import; use the aliases provided by the containerd/log module
instead.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Check span.IsRecording first, as it's a more lightweight check than
span.SpanContext().IsValid()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Introduce functional options to NewLogrusHook to allow optional Trace ID
injection into log fields. This enables log-trace correlation via the
[debug] config without breaking existing external consumers of
pkg/tracing.

Signed-off-by: Hasan Siddiqui <hasiddiqui@google.com>
Make the otel package a separate module, so that containerd/log
does not inherit the otel dependencies.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Log fields which contain an error currently fall through to JSON
marshaling, which may produce an unhelpful value such as "{}" instead
of the error message.

Handle error values explicitly and use fmt.Sprint when formatting error
and fmt.Stringer values. Besides preserving their textual
representation, fmt handles typed-nil implementations without
propagating a panic from their Error or String method.

Also simplify the final fmt.Sprintf("%v", v) fallback to fmt.Sprint(v).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add WithLevel to configure the minimum log level handled by the
OpenTelemetry hook.

This allows callers to limit which log entries are recorded as span
events, reducing trace noise and overhead when lower-severity logs are
not useful for tracing.

By default, the hook continues to handle all log levels, preserving
the existing behavior.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add WithErrorStatusLevel to configure the minimum log level that marks
an active span with an error status.

This allows callers to reflect sufficiently severe log entries in the
span status while keeping the behavior independent from attached error
fields.

By default, log entries continue to leave the span status unchanged.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants