Skip to content

[AzureMonitorExporter] Fix performance counters not using configured resource attributes (role name/instance)#54944

Merged
rajkumar-rangaraj merged 3 commits intoAzure:mainfrom
rajkumar-rangaraj:rarang/fixperfcounterrole
Jan 12, 2026
Merged

[AzureMonitorExporter] Fix performance counters not using configured resource attributes (role name/instance)#54944
rajkumar-rangaraj merged 3 commits intoAzure:mainfrom
rajkumar-rangaraj:rarang/fixperfcounterrole

Conversation

@rajkumar-rangaraj
Copy link
Contributor

Fixes #54618

Description

Fixed performance counter metrics not using configured cloud_RoleName and cloud_RoleInstance resource attributes (showing "unknown_service:appname" instead).

Root Cause

The internal MeterProvider created by StandardMetricsExtractionProcessor was initialized in the constructor before the processor was attached to the TracerProvider, so it couldn't access the configured resource attributes.

Solution

Changed MeterProvider to use lazy initialization with Lazy<T>. The lazy factory calls ParentProvider?.GetResource() to obtain resource attributes after the processor is attached to the TracerProvider, ensuring performance counters inherit the correct role name and instance.

Changes

  • Modified StandardMetricsExtractionProcessor to use Lazy<MeterProvider?> for thread-safe lazy initialization
  • Updated constructor signature to accept AzureMonitorMetricExporter parameter
  • Updated call sites in ExporterRegistrationHostedService and AzureMonitorExporterExtensions
  • Added test to verify performance counters use configured resource attributes

Copilot AI review requested due to automatic review settings January 9, 2026 22:29
@github-actions github-actions bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Jan 9, 2026
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 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 MeterProvider initialization to use lazy initialization pattern to defer creation until after processor attachment
  • Updated all test usages to access the lazy value via .Value property
  • 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)

@rajkumar-rangaraj rajkumar-rangaraj changed the title Fix performance counters not using configured resource attributes (role name/instance) [AzureMonitorExporter] Fix performance counters not using configured resource attributes (role name/instance) Jan 9, 2026
@rajkumar-rangaraj rajkumar-rangaraj merged commit 9336644 into Azure:main Jan 12, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Monitor - Exporter Monitor OpenTelemetry Exporter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Azure Monitor Distro tracks performanceCounters disregarding resource attributes

2 participants