refactor: key internal attributes from registry enums, not literals#92
Merged
Conversation
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>
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.
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)
service.name/versioninotel.dart,exception.*intracer.dartrecordException,exception.*in thepackage:loggingbridge.attr.key == 'service.name', duplicated ~13×): OTLP span/log transformers, tracer/logger providers,resource.dart, console log exporter, andOTEL_RESOURCE_ATTRIBUTESparsing.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.keyresolves to the identical registry string, so the wire output is byte-for-byte unchanged; this is purely compile-time safety.Verification
dart analyze --fatal-infosclean. Full suite green except one pre-existing flaky subprocess timeout ingetBlrpConfig(a function this PR doesn't touch) — the env suite passes 215/215 in isolation, including thegetServiceConfigparsing this PR modifies.🤖 Generated with Claude Code