Skip to content

fix(otel): encode span event values like the json log line - #57

Open
josuegiron wants to merge 1 commit into
masterfrom
fix/otel-span-event-redaction
Open

josuegiron wants to merge 1 commit into
masterfrom
fix/otel-span-event-redaction

Conversation

@josuegiron

Copy link
Copy Markdown
Member

Summary

Span event attributes of kind Any are now encoded the way slog's JSON handler encodes them for the log line, instead of with %+v:

  • after slog.LogValuer resolution, an error that is not a json.Marshaler is written as ERROR: + Error();
  • any other value goes through encoding/json (no HTML escaping), so MarshalJSON/MarshalText apply and json:"-" and unexported fields stay out; a JSON string result is unquoted;
  • a value encoding/json rejects 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 OtelHandler doc 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 ./... in otel/.
  • New 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

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

1 participant