Skip to content

refactor: key internal attributes from registry enums, not literals#92

Merged
michaelbushe merged 2 commits into
mainfrom
feat/enum-harden-attribute-keys
Jul 20, 2026
Merged

refactor: key internal attributes from registry enums, not literals#92
michaelbushe merged 2 commits into
mainfrom
feat/enum-harden-attribute-keys

Conversation

@michaelbushe

Copy link
Copy Markdown
Member

Follow-up to the #90 resource-detector fix: a scan turned up the same string-literal-attribute-key pattern in production code, all with existing registry enums. This hardens every one so a mistyped key is a compile error — the exact bug class that put the hostname in host.arch.

What changed (23 sites, 11 files)

  • Setting attributes (the real IO resource detector sets host.arch to the hostname #90-class risk — a typo ships bad telemetry): resource service.name/version in otel.dart, exception.* in tracer.dart recordException, exception.* in the package:logging bridge.
  • Comparing keys (attr.key == 'service.name', duplicated ~13×): OTLP span/log transformers, tracer/logger providers, resource.dart, console log exporter, and OTEL_RESOURCE_ATTRIBUTES parsing.
  • Reading (getString('otel.status_code')): counting_sampler.dart.

Enums: Service.*, ExceptionAttributes.*, Otel.* — all already re-exported through the SDK barrel, so no new imports.

No behavior change

Enum.key resolves to the identical registry string, so the wire output is byte-for-byte unchanged; this is purely compile-time safety.

Verification

dart analyze --fatal-infos clean. Full suite green except one pre-existing flaky subprocess timeout in getBlrpConfig (a function this PR doesn't touch) — the env suite passes 215/215 in isolation, including the getServiceConfig parsing this PR modifies.

🤖 Generated with Claude Code

michaelbushe and others added 2 commits July 20, 2026 22:44
Same hardening as the #90 resource-detector fix, applied across the
codebase: every registry attribute key used in production code now comes
from the generated semconv enum instead of a string literal, so a
mistyped key is a compile error.

- Setting: resource service.name/version (otel.dart), exception.*
  recording (tracer.dart), the package:logging bridge (dart_log_bridge).
- Comparing: the ~13 duplicated `attr.key == 'service.name'` checks in
  the OTLP span/log transformers, tracer/logger providers, resource,
  console log exporter, and OTEL_RESOURCE_ATTRIBUTES parsing.
- Reading: counting_sampler's otel.status_code/description lookups.

Enums used: Service.*, ExceptionAttributes.*, Otel.*. No wire change —
Enum.key resolves to the identical registry string. 23 sites, 11 files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@michaelbushe
michaelbushe merged commit 11d9dfb into main Jul 20, 2026
6 checks passed
@michaelbushe
michaelbushe deleted the feat/enum-harden-attribute-keys branch July 20, 2026 21:16
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