[AzureMonitorExporter] Fix performance counters not using configured resource attributes (role name/instance)#54944
Merged
rajkumar-rangaraj merged 3 commits intoAzure:mainfrom Jan 12, 2026
Conversation
…le name/instance)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where performance counter metrics were not using configured resource attributes (cloud_RoleName and cloud_RoleInstance), instead showing "unknown_service:appname". The root cause was that the internal MeterProvider was initialized in the constructor before the processor was attached to the TracerProvider, preventing access to configured resource attributes.
Key Changes:
- Changed
MeterProviderinitialization to use lazy initialization pattern to defer creation until after processor attachment - Updated all test usages to access the lazy value via
.Valueproperty - Added comprehensive test to verify the fix works correctly
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
StandardMetricsExtractionProcessor.cs |
Converted MeterProvider to Lazy<MeterProvider?> with deferred initialization that accesses ParentProvider.GetResource() to inherit resource attributes; removed unused import |
StandardMetricTests.cs |
Updated all existing tests to access _meterProvider.Value instead of _meterProvider directly; added new test to verify performance counters use configured resource attributes |
CHANGELOG.md |
Added entry documenting the bug fix (PR link placeholder needs completion) |
...tor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/StandardMetricsExtractionProcessor.cs
Outdated
Show resolved
Hide resolved
...tor/Azure.Monitor.OpenTelemetry.Exporter/src/Internals/StandardMetricsExtractionProcessor.cs
Outdated
Show resolved
Hide resolved
harsimar
approved these changes
Jan 12, 2026
This was referenced Jan 29, 2026
Merged
Closed
This was referenced Feb 3, 2026
Closed
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.
Fixes #54618
Description
Fixed performance counter metrics not using configured
cloud_RoleNameandcloud_RoleInstanceresource attributes (showing "unknown_service:appname" instead).Root Cause
The internal
MeterProvidercreated byStandardMetricsExtractionProcessorwas initialized in the constructor before the processor was attached to theTracerProvider, so it couldn't access the configured resource attributes.Solution
Changed
MeterProviderto use lazy initialization withLazy<T>. The lazy factory callsParentProvider?.GetResource()to obtain resource attributes after the processor is attached to theTracerProvider, ensuring performance counters inherit the correct role name and instance.Changes
StandardMetricsExtractionProcessorto useLazy<MeterProvider?>for thread-safe lazy initializationAzureMonitorMetricExporterparameterExporterRegistrationHostedServiceandAzureMonitorExporterExtensions