Skip to content

pkg/tracing: deprecate Logrushook in favor of log/otel.Logrushook - #14023

Merged
dmcgowan merged 1 commit into
containerd:mainfrom
thaJeztah:migrate_tracing_loghook
Sep 5, 2026
Merged

dmcgowan merged 1 commit into
containerd:mainfrom
thaJeztah:migrate_tracing_loghook

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

relates to:

Migrate the hook to a separate moduile in the containerd/log repository, as it's closely related to the logging utilities provided there, and allows consumers to use the hook without a direct dependency on containerd itself.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the OpenTelemetry logrus hook out of pkg/tracing into the external github.com/containerd/log/otel module, keeping pkg/tracing as a deprecated compatibility shim while updating containerd’s startup to use the new module directly.

Changes:

  • Add and vendor the new github.com/containerd/log/otel module (hook implementation + helpers + license) and update vendoring metadata.
  • Deprecate pkg/tracing’s LogrusHook/HookOpt/constructors via type/function aliases to log/otel.
  • Switch cmd/containerd startup hook registration from pkg/tracing to github.com/containerd/log/otel.

Reviewed changes

Copilot reviewed 4 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
go.mod Adds dependency on github.com/containerd/log/otel and a temporary replace to a fork for testing.
go.sum Adds checksums for the temporarily replaced fork module.
cmd/containerd/command/main.go Uses github.com/containerd/log/otel.NewLogrusHook during daemon startup.
pkg/tracing/log.go Deprecates the old API and forwards to log/otel via aliases/wrappers.
pkg/tracing/log_test.go Removes the prior in-repo regression test for the hook behavior.
vendor/modules.txt Adds vendoring metadata for the new log/otel module and replacement mapping.
vendor/github.com/containerd/log/otel/log.go Vendors the new hook implementation that records log events on active spans.
vendor/github.com/containerd/log/otel/helpers.go Vendors attribute conversion helpers for structured log fields.
vendor/github.com/containerd/log/otel/LICENSE Vendors the module license text.
Suppressed comments (1)

pkg/tracing/log.go:38

  • Same as NewLogrusHook: consider returning the local alias type (HookOpt) here so the deprecated wrapper doesn’t leak otel identifiers in its API surface.
func WithTraceIDField(enabled bool) otel.HookOpt {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread go.mod Resolved
Comment thread go.mod Resolved
Comment thread pkg/tracing/log_deprecated.go Resolved
Comment on lines +169 to 170
tracingHook := otel.NewLogrusHook(otel.WithTraceIDField(config.Debug.LogTraceID))
logrus.StandardLogger().AddHook(tracingHook)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests were migrated to the new repository, so should cover this.

Copilot AI review requested due to automatic review settings August 24, 2026 10:51
@thaJeztah
thaJeztah force-pushed the migrate_tracing_loghook branch from c87cb14 to 2298951 Compare August 24, 2026 10:51
@kubernetes-prow kubernetes-prow Bot added size/L and removed size/XL labels Aug 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 9 changed files in this pull request and generated no new comments.

Suppressed comments (1)

go.mod:6

  • The committed replace github.com/containerd/log/otel => github.com/thaJeztah/log/otel ... points to a personal fork and is marked as “temporary for testing”. This will make builds non-reproducible for downstream consumers and can’t be relied on outside this repo (and it also leaks into vendor/modules.txt). Before merging, this should be removed and the dependency should be pinned to an upstream github.com/containerd/log/otel version/pseudo-version that exists, followed by re-vendoring.
// FIXME(thaJeztah): temporary replace, just for testing https://github.com/containerd/log/pull/25
replace github.com/containerd/log/otel => github.com/thaJeztah/log/otel v0.0.0-20260823154913-15f4ac3d51b3

Copilot AI review requested due to automatic review settings August 27, 2026 10:54
@thaJeztah
thaJeztah force-pushed the migrate_tracing_loghook branch from 2298951 to 1d57353 Compare August 27, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

go.mod:6

  • This temporary replace to a personal fork should not be merged as-is. replace directives are not applied by downstream module consumers, and this can also make non-vendored builds depend on an unpublished fork; please switch to the official github.com/containerd/log/otel version (tag/pseudo-version) and remove this replace before merging.
// FIXME(thaJeztah): temporary replace, just for testing https://github.com/containerd/log/pull/25
replace github.com/containerd/log/otel => github.com/thaJeztah/log/otel v0.0.0-20260825121036-042c0c770ad0

Comment on lines 166 to 170
// Register the tracing hook as soon as config is available. Later startup
// steps may start goroutines that log, so avoid mutating hooks after hook
// reads may have begun.
tracingHook := tracing.NewLogrusHook(tracing.WithTraceIDField(config.Debug.LogTraceID))
tracingHook := otel.NewLogrusHook(otel.WithTraceIDField(config.Debug.LogTraceID))
logrus.StandardLogger().AddHook(tracingHook)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace.SpanFromContext handles a nil context, so it would be an optimisation, not a bug-fix to return early;

// SpanFromContext returns the current Span from ctx.
//
// If no Span is currently set in ctx an implementation of a Span that
// performs no operations is returned.
func SpanFromContext(ctx context.Context) Span {
if ctx == nil {
return noopSpanInstance
}
if span, ok := ctx.Value(currentSpanKey).(Span); ok {
return span
}
return noopSpanInstance
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI review requested due to automatic review settings August 27, 2026 23:29
@thaJeztah
thaJeztah force-pushed the migrate_tracing_loghook branch from 1d57353 to bf6a4b7 Compare August 27, 2026 23:29
@thaJeztah thaJeztah added this to the 2.4 milestone Aug 27, 2026
@thaJeztah
thaJeztah marked this pull request as ready for review August 27, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 9 changed files in this pull request and generated 1 comment.

Comment thread go.mod Resolved
@thaJeztah

Copy link
Copy Markdown
Member Author

I can update this to to current main (after the last PRs were merged)

Migrate the hook to a separate moduile in the containerd/log repository,
as it's closely related to the logging utilities provided there, and
allows consumers to use the hook without a direct dependency on
containerd itself.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copilot AI review requested due to automatic review settings August 28, 2026 14:25
@thaJeztah
thaJeztah force-pushed the migrate_tracing_loghook branch from bf6a4b7 to 20fed51 Compare August 28, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 9 changed files in this pull request and generated no new comments.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Aug 28, 2026
@thaJeztah

Copy link
Copy Markdown
Member Author

cc @samuelkarp PTAL (probably ready to go - assuming we'll tag a version before GA)

Comment thread go.mod
github.com/containerd/go-runc v1.2.1
github.com/containerd/imgcrypt/v2 v2.0.3
github.com/containerd/log v0.1.0
github.com/containerd/log/otel v0.0.0-20260828142140-8b5d6538fa1f // main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ready to be tagged?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so; probably both log and log/otel can get a new tag

@dmcgowan
dmcgowan added this pull request to the merge queue Sep 5, 2026
Merged via the queue into containerd:main with commit c003f88 Sep 5, 2026
96 of 98 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 5, 2026
@thaJeztah
thaJeztah deleted the migrate_tracing_loghook branch September 14, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants