Repository navigation
fix(otel): encode span event values like the json log line - #57
Open
josuegiron wants to merge 1 commit into
Open
josuegiron wants to merge 1 commit into
josuegiron wants to merge 1 commit into
Conversation
Span event attributes of kind Any were written with %+v, so fields tagged json:"-" and MarshalJSON/MarshalText redaction did not apply to spans. Encode them with encoding/json as slog's JSON handler does, errors with Error(), and recover panics the way slog does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Span event attributes of kind
Anyare now encoded the way slog's JSON handler encodes them for the log line, instead of with%+v:slog.LogValuerresolution, an error that is not ajson.Marshaleris written asERROR:+Error();encoding/json(no HTML escaping), soMarshalJSON/MarshalTextapply andjson:"-"and unexported fields stay out; a JSON string result is unquoted;encoding/jsonrejects is recorded as!ERROR: <error>; a nil-pointer panic in a method gives<nil>, other panics!PANIC: <value>(as slog does).The 1 KiB string cap and the slice caps are unchanged. The
OtelHandlerdoc comment and the README describe the encoding.Output change: struct and map values on span events are now JSON (
{"A":1}) instead of{A:1}; this ships as a minor otel release.Verification
gofmt -l .,go vet ./...,go test -race ./...,govulncheck ./...inotel/.BenchmarkHandleSpanEventAnyValues(struct + error): before ~4.1-7.9 us/op, 625 B, 12 allocs; after ~3.1-3.4 us/op, 753 B, 15 allocs.🤖 Generated with Claude Code