Allow strong-typed metrics with 30+ tags - #7681
Open
adhikareeprayush wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Microsoft.Gen.Metrics source generator to allow strong-typed metrics (e.g., [Counter(typeof(MyDimensions))]) to use more than 30 tag names, matching the behavior already allowed when tag names are provided explicitly in the attribute. It also retires diagnostic METGEN013 (while keeping the ID reserved).
Changes:
- Removed the generator’s 30-tag strong-type limit check and retired the
METGEN013diagnostic descriptor/resources. - Updated/added parser tests to validate strong-typed metrics with 33+ tags (including gauge/histogram scenarios).
- Added a generated/runtime test that emits and validates a 33-tag strong-typed counter end-to-end.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Generators/Microsoft.Gen.Metrics/Unit/ParserTests.StrongTypes.cs | Updates strong-type parser test to validate >30 dimensions without diagnostics. |
| test/Generators/Microsoft.Gen.Metrics/Unit/ParserTests.Diagnostics.cs | Removes the old “too many dimensions” diagnostic test and replaces gauge test to ensure >30 tags succeeds. |
| test/Generators/Microsoft.Gen.Metrics/TestClasses/ManyTagsTestExtensions.cs | Adds test input types/extensions to generate and exercise a 33-tag strong-typed counter. |
| test/Generators/Microsoft.Gen.Metrics/Generated/MetricTests.cs | Adds end-to-end verification that a 33-tag strong-typed counter records expected tags/values. |
| src/Generators/Microsoft.Gen.Metrics/Resources.resx | Removes localized strings for the retired METGEN013 diagnostic. |
| src/Generators/Microsoft.Gen.Metrics/Resources.Designer.cs | Removes the generated resource accessors for the retired METGEN013 strings. |
| src/Generators/Microsoft.Gen.Metrics/Parser.cs | Removes the strong-type tag count enforcement that produced METGEN013. |
| src/Generators/Microsoft.Gen.Metrics/DiagDescriptors.cs | Removes the METGEN013 diagnostic descriptor definition. |
| docs/list-of-diagnostics.md | Removes METGEN013 from the published diagnostics list. |
Files not reviewed (1)
- src/Generators/Microsoft.Gen.Metrics/Resources.Designer.cs: Generated file
Author
@dotnet-policy-service agree |
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.
Summary
METGEN013) for strong-typed metrics inMicrosoft.Gen.Metrics[Counter(typeof(SomeType))]can now have more than 30 tag names, same as[Counter("D1", ..., "D33")]METGEN013; the ID is left reserved so it is not reusedFixes #7573
Test plan
Microsoft.Gen.Metrics.Unit.TestspassMicrosoft.Gen.Metrics.Generated.Testspass on net8.0, net9.0, and net10.0Microsoft Reviewers: Open in CodeFlow