Skip to content

Reduce allocations when building OpenTelemetry metric tags - #6227

Merged
Sergei Smelov (ssmelov) merged 2 commits into
mainfrom
ssmelov/reduce-allocations-when-building-otel-metric-tags
Oct 23, 2026
Merged

Sergei Smelov (ssmelov) merged 2 commits into
mainfrom
ssmelov/reduce-allocations-when-building-otel-metric-tags

Conversation

@ssmelov

Copy link
Copy Markdown
Collaborator

Optimizes OpenTelemetry tag construction by removing per-recording canonical-tag arrays and HashSet allocations.

@ssmelov
Sergei Smelov (ssmelov) requested a review from a team as a code owner October 21, 2026 15:45
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:45

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.

🟢 Approval recommended

The focused refactor preserves canonical metric values and collision protection, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Reduces allocations in MSAL.NET’s OpenTelemetry metric tag construction.

Changes:

  • Builds tags directly in TagList, removing intermediate arrays and lists.
  • Caches canonical tag keys per metric instead of creating a HashSet for each recording.
  • Retains canonical-tag validation and collision protection.
File Description
src/​client/​Microsoft.Identity.Client/​Platforms/​Features/​OpenTelemetry/​OtelInstrumentation.cs Uses direct tag construction and cached canonical keys across metric recording paths.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 22, 2026 22:27

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.

🟢 Approval recommended

The focused internal refactor preserves metric recording behavior, with no unresolved correctness issues identified.

No open issues 🎉

Review effort: Balanced

@ssmelov
Sergei Smelov (ssmelov) merged commit 54e4d62 into main Oct 23, 2026
19 checks passed
@ssmelov
Sergei Smelov (ssmelov) deleted the ssmelov/reduce-allocations-when-building-otel-metric-tags branch October 23, 2026 14:59
This was referenced Oct 29, 2026
This was referenced Nov 12, 2026
maksii pushed a commit to maksii/paqvilo that referenced this pull request Nov 16, 2026
Updated
[Microsoft.Identity.Client](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet)
from 4.91.1 to 4.92.0.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.Identity.Client's
releases](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/releases)._

## 4.92.0

### New Features

- Added `COSMIC_LOCATION` as a regional auto-detection source, after
`REGION_NAME` and before IMDS.
[#​6240](AzureAD/microsoft-authentication-library-for-dotnet#6240)
- Added `ITokenCacheSnapshotProvider` and `TokenCacheSnapshot` for
process-local token-cache capture and restore without repeated JSON
serialization. Use V3 serialization for persistence.
[#​6229](AzureAD/microsoft-authentication-library-for-dotnet#6229)

### Bug Fixes

- Fixed certificate private-key attachment on .NET Framework 4.7.2 to
support non-exportable CNG keys.
[#​6244](AzureAD/microsoft-authentication-library-for-dotnet#6244)
- Fixed managed identity KeyGuard attestation endpoint selection to use
cloud-specific regional endpoints from IMDS compute metadata.
[#​6238](AzureAD/microsoft-authentication-library-for-dotnet#6238)
- Fixed Android broker request serialization by registering
`BrokerRequest` in the source-generated JSON serializer context.
[#​6226](AzureAD/microsoft-authentication-library-for-dotnet#6226)

### Changes

- Updated `Microsoft.Identity.Client.NativeInterop` from 0.20.6 to
0.20.7.
[#​6230](AzureAD/microsoft-authentication-library-for-dotnet#6230)
- Reduced OpenTelemetry metric-tag allocations using `TagList` and
cached canonical tag-key sets. Custom enrichers should use noncanonical
tag names.
[#​6227](AzureAD/microsoft-authentication-library-for-dotnet#6227)


Commits viewable in [compare
view](AzureAD/microsoft-authentication-library-for-dotnet@4.91.1...4.92.0).
</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

4 participants