Skip to content

[Monitor Exporter] Keep the SDK statistics ikey on the distro endpoint - #63342

Merged
Rajkumar Rangaraj (rajkumar-rangaraj) merged 2 commits into
Azure:mainfrom
rajkumar-rangaraj:rajkumar/distro-sdkstats-ikey
Sep 23, 2026
Merged

Rajkumar Rangaraj (rajkumar-rangaraj) merged 2 commits into
Azure:mainfrom
rajkumar-rangaraj:rajkumar/distro-sdkstats-ikey

Conversation

@rajkumar-rangaraj

Copy link
Copy Markdown
Member

Problem

With the Azure.Monitor.OpenTelemetry.Exporter.RouteSdkStatsToDistroEndpoint AppContext switch on, the exporter fetches { "ver": 1, "enabled": true, "url": "..." } from the SDK statistics config endpoint. On the UseUrl path, BuildConnectionStringFromHost hard-coded InstrumentationKey=00000000-0000-0000-0000-000000000000, so every SDK statistics envelope sent to the distro endpoint carried an all-zero iKey. The config contract has no ikey field; the distro is meant to change only the destination, while the ikey stays the same as other internal SDK statistics.

Change

  • StatsbeatConstants: extract Statsbeat_InstrumentationKey_NonEU (c4a29126-...) and Statsbeat_InstrumentationKey_EU (7dc56bab-...). The legacy connection strings are composed from them and are byte-for-byte unchanged.
  • AzureMonitorStatsbeat:
    • UseUrl now builds InstrumentationKey={region-matched SDK stats ikey};IngestionEndpoint=https://{url}/.
    • New GetSdkStatsInstrumentationKey shares one IsEuRegion check with GetSdkStatsConfigUrl, so an EU customer gets the EU config host and the EU ikey; unknown regions default to non-EU for both.
    • Removed the "placeholder iKey is ignored server-side" comment.
Path Endpoint Envelope iKey
Switch off (legacy) region-derived SDK stats ikey (unchanged)
Distro, config fallback region-derived SDK stats ikey (unchanged)
Distro, config url config url SDK stats ikey (was all zeros)
Distro, enabled: false not sent n/a
APPLICATIONINSIGHTS_STATS_CONNECTION_STRING as configured as configured (unchanged)

The customer ikey continues to be sent only as the cikey dimension.

Tests

New in DistroSdkStatsRoutingTests:

  • Config url for EU / non-EU / unknown region: exact resolved connection string, parsed ikey equals the SDK stats ikey, and is neither the customer's ikey nor all zeros (customer ikey in the test is non-zero so the checks are meaningful).
  • BuildConnectionStringFromHost preserves the ikey for bare host / trailing slash / full URL.
  • Both ikeys and legacy connection strings pinned to literals.
  • ikey region and config URL region always agree.

Full exporter suite passes on net8.0 (1194); DistroSdkStatsRoutingTests pass on net462.

When the RouteSdkStatsToDistroEndpoint AppContext switch is on and the remote
config returns a url, SDK statistics were sent with an all-zero placeholder
instrumentation key. The distro changes only the destination: envelopes now
carry the same region-matched SDK statistics instrumentation key as the
existing endpoint. The ikey region is selected with the same rule as the
config url. Legacy, fallback and override paths are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 23, 2026 22:32
@github-actions github-actions Bot added the Monitor - Exporter Monitor OpenTelemetry Exporter label Sep 23, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The focused internal fix is consistent with existing routing behavior and has comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes SDK statistics attribution when routing through distro-configured endpoints.

Changes:

  • Preserves region-matched SDK statistics instrumentation keys.
  • Shares EU-region selection logic across configuration URLs and keys.
  • Adds regression tests and changelog documentation.
File Description
CHANGELOG.md Documents the routing fix.
StatsbeatConstants.cs Extracts EU and non-EU instrumentation keys.
AzureMonitorStatsbeat.cs Uses the regional key for distro endpoints.
DistroSdkStatsRoutingTests.cs Tests key selection and connection-string construction.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@rajkumar-rangaraj
Rajkumar Rangaraj (rajkumar-rangaraj) merged commit 3a8fb14 into Azure:main Sep 23, 2026
25 checks passed
This was referenced Oct 7, 2026
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.

3 participants