Skip to content

fix: provider accessors use spec-mandated safe defaults, never throw - #39

Merged
michaelbushe merged 2 commits into
mainfrom
fix/spec-provider-safe-defaults
Jul 18, 2026
Merged

fix: provider accessors use spec-mandated safe defaults, never throw#39
michaelbushe merged 2 commits into
mainfrom
fix/spec-provider-safe-defaults

Conversation

@michaelbushe

Copy link
Copy Markdown
Member

Summary

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

The violation

  • trace/api.md, Get a Tracer: "In case an invalid name (null or empty string) is specified, a working Tracer implementation MUST be returned as a fallback rather than returning null or throwing an exception" — OTelAPI.tracerProvider('') / meterProvider('') / loggerProvider('') threw ArgumentError; they now warn and return the global default (exactly what the old error message told users to do manually).
  • error-handling.md: "API methods MUST NOT throw unhandled exceptions when used incorrectly by end users" — getTracer / getMeter / getLogger threw StateError after provider shutdown; they now warn and return a no-op instance.

Merge order

Stacked on #37 (→ #36): merge #36#37 → this.

Validation

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

🤖 Generated with Claude Code

@michaelbushe
michaelbushe force-pushed the fix/spec-provider-safe-defaults branch from 4b28838 to 87e410d Compare July 11, 2026 06:36
@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:33
trace/api.md Get a Tracer: an invalid name MUST return a working
fallback "rather than returning null or throwing an exception";
error-handling.md: API methods MUST NOT throw on misuse. Current
OTelAPI.tracerProvider/meterProvider/loggerProvider throw
ArgumentError on empty names, and getTracer/getMeter/getLogger throw
StateError after provider shutdown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Turns the red spec tests green:
- OTelAPI.tracerProvider('')/meterProvider('')/loggerProvider('')
  warn and return the global default instead of ArgumentError
- getTracer/getMeter/getLogger after provider shutdown warn and
  return a no-op instance instead of StateError

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@michaelbushe
michaelbushe force-pushed the fix/spec-provider-safe-defaults branch from 0e670b4 to cc6a377 Compare July 18, 2026 05:33
@michaelbushe
michaelbushe merged commit 48d13ef into main Jul 18, 2026
6 checks passed
@michaelbushe
michaelbushe deleted the fix/spec-provider-safe-defaults branch July 18, 2026 05:33
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