Skip to content

migrate containerd/pkg/tracing - #24

Open
thaJeztah wants to merge 10 commits into
containerd:mainfrom
thaJeztah:integrate_tracing
Open

migrate containerd/pkg/tracing#24
thaJeztah wants to merge 10 commits into
containerd:mainfrom
thaJeztah:integrate_tracing

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Aug 23, 2026

Copy link
Copy Markdown
Member

migrate containerd/pkg/tracing

This migrates the log-related code from github.com/containerd/containerd/v2/pkg/tracing

Code was taken at this commit https://github.com/containerd/containerd/commits/fd399bd7b8cfdd47fb4f6cc021db417e5397a42f/pkg/tracing

Strategy taken:

# install filter-repo (https://github.com/newren/git-filter-repo/blob/main/INSTALL.md)
brew install git-filter-repo

cd ~/projects

# create a temporary clone of docker
git clone https://github.com/containerd/containerd.git tmp_tracing
cd tmp_tracing

git rev-parse HEAD
fd399bd7b8cfdd47fb4f6cc021db417e5397a42f

# remove all code, except for pkg/tracing, and rename to /otel
git filter-repo \
    --path tracing/helpers.go \
    --path tracing/log.go \
    --path tracing/log_test.go \
    --path pkg/tracing/helpers.go \
    --path pkg/tracing/log.go \
    --path pkg/tracing/log_test.go \
    --path-rename tracing/:otel/ \
    --path-rename pkg/tracing/:otel/ \
    --prune-empty always \
    --prune-degenerate always

# go to the target github.com/containerd/log repository
cd ~/projects/log

# create a branch to work with
git checkout -b integrate_tracing

# add the temporary repository as an upstream and make sure it's up-to-date
git remote add tmp_tracing ~/projects/tmp_tracing
git fetch --no-tags tmp_tracing main

# merge the upstream code
git merge --allow-unrelated-histories --signoff -S tmp_tracing/main

otel: fix imports, remove testify, add go.mod

Make the otel package a separate module, so that containerd/log
does not inherit the otel dependencies.

otel: handle error and typed-nil Stringer attributes

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).

@thaJeztah

Copy link
Copy Markdown
Member Author

Oh! We need to update GolangCi lint, because it's now running go1.27

run golangci-lint
  Running [/home/runner/golangci-lint-2.12.2-linux-amd64/golangci-lint config path] in [/home/runner/work/log/log] ...
  Running [/home/runner/golangci-lint-2.12.2-linux-amd64/golangci-lint config verify] in [/home/runner/work/log/log] ...
  Running [/home/runner/golangci-lint-2.12.2-linux-amd64/golangci-lint run] in [/home/runner/work/log/log] ...
  Error: ../../../../../opt/hostedtoolcache/go/1.27.0/x64/src/internal/poll/splice_linux.go:237:21: unknown field rfd in struct literal of type splicePipe (typecheck)
  	return &splicePipe{rfd: fds[0], wfd: fds[1]}
  	                   ^

cpuguy83 and others added 10 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>
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