Skip to content

fix: TraceState spec compliance — ignore invalid input, never throw - #37

Merged
michaelbushe merged 2 commits into
mainfrom
fix/spec-tracestate-no-throw
Jul 18, 2026
Merged

fix: TraceState spec compliance — ignore invalid input, never throw#37
michaelbushe merged 2 commits into
mainfrom
fix/spec-tracestate-no-throw

Conversation

@michaelbushe

Copy link
Copy Markdown
Member

Summary

Documents and fixes a spec violation found auditing against specification/trace/api.md. TDD: first commit pins the spec contracts red (5 failing), second turns them green.

The violation

  • "Every mutating operations MUST validate input parameters. If invalid value is passed the operation MUST NOT return TraceState containing invalid data and MUST follow the general error handling guidelines" — and error-handling.md: "API methods MUST NOT throw unhandled exceptions when used incorrectly by end users." TraceState.put threw ArgumentError on invalid keys/values; it now warns and returns the state unchanged, so the state stays valid and the caller never crashes.
  • put/remove also threw StateError('Call initialize() first.') before initialization; they now lazily install the no-op factory like the rest of the API.

Merge order

Stacked on #36: merge #36 first, then this. Note: fix/tracestate-tenant-key-w3c (in-flight from another session) touches the same file — whichever merges second will need a small rebase.

Validation

  • dart analyze / dart format --set-exit-if-changed . — clean
  • dart test — 760 tests passing

🤖 Generated with Claude Code

@michaelbushe

Copy link
Copy Markdown
Member Author

Reviews welcome: @harshitt13 @kevmoo @muhammadkamel @rohit482 @cnbleu @yuzurihaaa @robert-northmind @benjaben @danexello — spec-compliance work against the OpenTelemetry specification; the PR description has the normative quotes and the red/green test commits.

michaelbushe and others added 2 commits July 18, 2026 07:32
specification/trace/api.md: mutating operations MUST validate input,
MUST NOT return TraceState containing invalid data, and MUST follow
the error-handling guidelines — which forbid throwing on misuse.
Current put() throws ArgumentError on invalid key/value, and
put()/remove() throw StateError before initialization.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Turns the red spec tests green:
- put() with an invalid key or value warns and returns the state
  unchanged instead of throwing ArgumentError, so TraceState never
  contains invalid data and never crashes the caller
- put()/remove() use getOrCreateDefault so they work without an
  installed SDK

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@michaelbushe
michaelbushe force-pushed the fix/spec-tracestate-no-throw branch from a705023 to 6f94560 Compare July 18, 2026 05:32
@michaelbushe
michaelbushe merged commit 501ee50 into main Jul 18, 2026
6 checks passed
@michaelbushe
michaelbushe deleted the fix/spec-tracestate-no-throw branch July 18, 2026 05:32
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