Skip to content

pkg/tracing: handle error and typed-nil Stringer attributes - #14013

Merged
mxpv merged 1 commit into
containerd:mainfrom
thaJeztah:fix_tracing
Aug 25, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
thaJeztah:fix_tracing

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

noticed this code, and recently had a similar issue in logrus;

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

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 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 22, 2026 18:52
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Aug 22, 2026
@thaJeztah thaJeztah added this to the 2.4 milestone Aug 22, 2026
@thaJeztah thaJeztah added the cherry-pick/2.3.x Change to be cherry picked to release/2.3 label Aug 22, 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

This PR improves how pkg/tracing converts arbitrary log/trace field values into OpenTelemetry attributes, ensuring error values and typed-nil error/fmt.Stringer values produce a useful, non-panicking string representation.

Changes:

  • Handle error values explicitly in keyValue to avoid falling through to JSON marshaling (which can yield {} for errors).
  • Use fmt.Sprint for error and fmt.Stringer formatting to safely handle typed-nil implementations.
  • Add unit tests covering nil, error, typed-nil error, fmt.Stringer, typed-nil fmt.Stringer, and JSON-marshaled values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/tracing/helpers.go Adds explicit error handling and switches string formatting to fmt.Sprint for safer, more helpful attribute strings.
pkg/tracing/helpers_test.go Introduces tests validating correct formatting and non-panicking behavior for typed-nil error/Stringer values.

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

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Aug 25, 2026
@mxpv
mxpv added this pull request to the merge queue Aug 25, 2026
Merged via the queue into containerd:main with commit e661845 Aug 25, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Aug 25, 2026
@thaJeztah
thaJeztah deleted the fix_tracing branch August 25, 2026 08:45
@thaJeztah

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@thaJeztah: new pull request created: #14049

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@thaJeztah thaJeztah added cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants