Repository navigation
pkg/tracing: deprecate Logrushook in favor of log/otel.Logrushook - #14023
Conversation
There was a problem hiding this comment.
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/otelmodule (hook implementation + helpers + license) and update vendoring metadata. - Deprecate
pkg/tracing’sLogrusHook/HookOpt/constructors via type/function aliases tolog/otel. - Switch
cmd/containerdstartup hook registration frompkg/tracingtogithub.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 leakotelidentifiers 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.
| tracingHook := otel.NewLogrusHook(otel.WithTraceIDField(config.Debug.LogTraceID)) | ||
| logrus.StandardLogger().AddHook(tracingHook) |
There was a problem hiding this comment.
Tests were migrated to the new repository, so should cover this.
c87cb14 to
2298951
Compare
There was a problem hiding this comment.
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 intovendor/modules.txt). Before merging, this should be removed and the dependency should be pinned to an upstreamgithub.com/containerd/log/otelversion/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
2298951 to
1d57353
Compare
There was a problem hiding this comment.
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
replaceto a personal fork should not be merged as-is.replacedirectives are not applied by downstream module consumers, and this can also make non-vendored builds depend on an unpublished fork; please switch to the officialgithub.com/containerd/log/otelversion (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
| // 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) |
There was a problem hiding this comment.
trace.SpanFromContext handles a nil context, so it would be an optimisation, not a bug-fix to return early;
containerd/vendor/go.opentelemetry.io/otel/trace/context.go
Lines 33 to 45 in 6e6518a
There was a problem hiding this comment.
1d57353 to
bf6a4b7
Compare
|
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]>
bf6a4b7 to
20fed51
Compare
|
cc @samuelkarp PTAL (probably ready to go - assuming we'll tag a version before GA) |
| 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 |
There was a problem hiding this comment.
I think so; probably both log and log/otel can get a new tag
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.