Skip to content

tracing: add option to inject trace ID into logrus fields#13117

Merged
mxpv merged 1 commit intocontainerd:mainfrom
HASidd:log-trace
Apr 1, 2026
Merged

tracing: add option to inject trace ID into logrus fields#13117
mxpv merged 1 commit intocontainerd:mainfrom
HASidd:log-trace

Conversation

@HASidd
Copy link
Copy Markdown
Contributor

@HASidd HASidd commented Mar 24, 2026

This PR introduces the ability to inject OpenTelemetry Trace IDs directly into logrus entry fields. This is particularly useful for correlating logs and traces in distributed environments.

Key Changes:

  • Moved LogrusHook registration from the init() function in otlp.go to app.Action in main.go (prior to server start). This is required because init() executes before config.toml is parsed, making it impossible to evaluate the debug configuration flag otherwise.
  • Added WithTraceIDField functional option to NewLogrusHook to preserve API stability for external consumers.
  • Added log_trace_id toggle to the [debug] section of the containerd configuration.
  • Updated the tracing.LogrusHook.Fire method to extract and set the trace_id field when enabled.

Implements #13116.

Add option to inject trace ID to logs

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>
Comment thread pkg/tracing/log.go
@samuelkarp samuelkarp added this to the 2.3 milestone Mar 30, 2026
@samuelkarp samuelkarp moved this from Needs Triage to Needs Reviewers in Pull Request Review Mar 30, 2026
@github-project-automation github-project-automation Bot moved this from Needs Reviewers to Review In Progress in Pull Request Review Mar 31, 2026
@mxpv mxpv added this pull request to the merge queue Mar 31, 2026
Merged via the queue into containerd:main with commit 43d906b Apr 1, 2026
54 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

4 participants