Skip to content

Allow strong-typed metrics with 30+ tags - #7681

Open
adhikareeprayush wants to merge 2 commits into
dotnet:mainfrom
adhikareeprayush:issue-7573-metric-more-than-30-tags
Open

Allow strong-typed metrics with 30+ tags#7681
adhikareeprayush wants to merge 2 commits into
dotnet:mainfrom
adhikareeprayush:issue-7573-metric-more-than-30-tags

Conversation

@adhikareeprayush

@adhikareeprayush adhikareeprayush commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • Remove the 30-tag limit (METGEN013) for strong-typed metrics in Microsoft.Gen.Metrics
  • Strong-typed metrics like [Counter(typeof(SomeType))] can now have more than 30 tag names, same as [Counter("D1", ..., "D33")]
  • Retire diagnostic METGEN013; the ID is left reserved so it is not reused

Fixes #7573

Test plan

  • Parser tests accept strong-typed metrics with 33+ tags (histogram and gauge)
  • Generated/runtime test records a 33-tag strong-typed counter
  • Microsoft.Gen.Metrics.Unit.Tests pass
  • Microsoft.Gen.Metrics.Generated.Tests pass on net8.0, net9.0, and net10.0
Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings August 5, 2026 12:00
@adhikareeprayush
adhikareeprayush requested review from a team as code owners August 5, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 METGEN013 diagnostic 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

@adhikareeprayush

Copy link
Copy Markdown
Author

@adhikareeprayush please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

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.

[Metric source-generator] Allow metric-classes to have more than 30 tag names

2 participants