Skip to content

Conversation

@mariamgerges
Copy link
Contributor

@mariamgerges mariamgerges commented Dec 2, 2025

solving ticket #7079

@mariamgerges mariamgerges self-assigned this Dec 2, 2025
Copilot AI review requested due to automatic review settings December 2, 2025 10:24
@mariamgerges mariamgerges requested a review from a team as a code owner December 2, 2025 10:24
Copy link
Contributor

Copilot AI left a comment

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 adds support for a Unit parameter to the metric source generator, allowing developers to specify units of measurement (like "seconds", "bytes", "meters") when defining metrics. The unit is stored in the generated metric instruments and can be retrieved for observability purposes.

Key changes:

  • Added Unit property to metric attribute classes (Counter, Histogram, Gauge, and TagName attributes)
  • Updated parser to extract unit values from both named arguments and strong type configurations
  • Modified emitter to include unit parameter when creating instruments
  • Added comprehensive test coverage including parser tests and integration tests

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/CounterAttribute.cs Added Unit property to allow specifying measurement units for counters
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/CounterAttributeT.cs Added Unit property for generic counter attributes
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/HistogramAttribute.cs Added Unit property for histogram attributes
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/HistogramAttributeT.cs Added Unit property for generic histogram attributes
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/GaugeAttribute.cs Added Unit property for gauge attributes
src/Libraries/Microsoft.Extensions.Telemetry.Abstractions/Metrics/TagNameAttribute.cs Incorrectly added Unit property to tag name attribute (used for dimension naming, not metrics)
src/Generators/Microsoft.Gen.Metrics/Model/MetricMethod.cs Added MetricUnit field to store unit in the metric model
src/Generators/Microsoft.Gen.Metrics/StrongTypeAttributeParameters.cs Added MetricUnitFromAttribute field to capture unit from strong type configurations
src/Generators/Microsoft.Gen.Metrics/Parser.cs Updated parsing logic to extract unit from both named arguments and strong type attributes
src/Generators/Microsoft.Gen.Metrics/MetricFactoryEmitter.cs Modified code generation to include unit parameter when creating instruments
test/Generators/Microsoft.Gen.Metrics/Unit/ParserTests.cs Added parser test to verify unit parameter is accepted without errors
test/Generators/Microsoft.Gen.Metrics/Unit/ParserTests.StrongTypes.cs Added parser test for strong types with unit parameter
test/Generators/Microsoft.Gen.Metrics/TestClasses/MetricsWithUnit.cs Added test metric definitions covering various unit scenarios
test/Generators/Microsoft.Gen.Metrics/Generated/MetricTests.Ext.Unit.cs Added integration tests validating unit functionality for counters and histograms

Copy link
Member

@dariusclay dariusclay left a comment

Choose a reason for hiding this comment

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

LGTM

@mariamgerges mariamgerges merged commit 4a49fcf into main Dec 5, 2025
6 checks passed
@mariamgerges mariamgerges deleted the mariamaziz/metric-gen-unit branch December 5, 2025 09:31
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants