Skip to content

Enable SDK Stats and route to the SDK Stats ingestion endpoint#2741

Open
JacksonWeber wants to merge 10 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/enable-sdk-stats
Open

Enable SDK Stats and route to the SDK Stats ingestion endpoint#2741
JacksonWeber wants to merge 10 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/enable-sdk-stats

Conversation

@JacksonWeber

@JacksonWeber JacksonWeber commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Re-enables the SDK Stats manager (createStatsMgr) and routes its events to the distro-owned SDK Stats ingestion endpoint used by opentelemetry-distro-dotnet, instead of piggy-backing on the customer's breeze endpoint.

Endpoints (from Azure/azure-sdk-for-net StatsbeatConstants.cs + the .NET distro)

  • Non-EU -> https://stats.monitor.azure.com/v2/track
  • EU -> https://eu.stats.monitor.azure.com/v2/track
  • Placeholder iKey 00000000-0000-0000-0000-000000000000, same Breeze envelope, no auth. EU vs non-EU chosen from the customer endpoint region.

Configurable Destination (new stats.monitor endpoint vs. legacy breeze)

The SDK Stats destination is now selectable at runtime via the CDN / dynamic config:

  • New config field config.stats (IStatsBeatConfig), overridable via the CDN / cfgSync dynamic config.
  • config.stats.mode (eStatsEndpointType): SdkStats (default) sends to stats.monitor.azure.com / eu.stats.monitor.azure.com; Breeze sends to the legacy breeze endpoint (the customer's own breeze host, using the Microsoft-owned SDK Stats iKey c4a29126… / 7dc56bab… by region).
  • The destination iKey and ingestion endpoint are resolved per-event in _track from the live config, so CDN changes take effect at runtime. A full endCfg key map (with explicit key and new url) can also be supplied via config.stats.endCfg to fully override routing.

Note: in Breeze mode the events flow through the normal channel to the customer's breeze endpoint (legacy behaviour); in SdkStats mode they bypass the customer buffer and are excluded from request counting.

Changes

  • StatsBeat.ts — SDK Stats endpoint constants, EU/non-EU region detection (getStatsEndpoint), per-event destination + placeholder-iKey stamping, enabled-by-default feature gate (opt-out via featureOptIn: "sdkStats"), createSdkStatsMgrConfig() helper, and configurable mode + key map support.
  • AppInsightsCore.ts / IAppInsightsCore.ts / index.ts — restore getStatsBeat/setStatsMgr, fields, unload cleanup, stubs, interface methods, and exports.
  • Sender.ts — restore request-counting hooks + statsBeatData; redirect SDK Stats items to the SDK Stats endpoint via a per-item URL override on _doSend/_getPayload, bypassing the customer buffer; SDK Stats sends are excluded from counting (no feedback loop); optimized property access for minification efficiency.
  • AISku.ts — create + init + set the manager after core init (kept out of core/AISKULight for bundle size).
  • IConfiguration.ts — added stats?: IStatsBeatConfig field for dynamic config.
  • StatsType.ts — added eStatsEndpointType enum (SdkStats / Breeze).
  • IStatsBeat.ts — added IStatsBeatConfig.mode and IStatsBeatKeyMap.url fields.
  • Tests — re-enabled all SDK Stats unit tests (StatsBeat.Tests.ts in both core and channel-js), fixed import paths, updated terminology from "statsbeat" to "SDK Stats" in test names and assertions.

Architecture note

createStatsMgr lives in core, which cannot depend on the channel's Breeze EnvelopeCreator. So SDK Stats events flow through _core.track() (reusing the channel's envelope creation) and the redirect to the SDK Stats endpoint happens in the Sender via a per-item endpoint override.

Verification

  • Verified with tsc --noEmit from source using the repo's exact compiler settings — core, channel, and AISKU compile with 0 errors.
  • Reviewed for minification efficiency — no spread operators, optional chaining, or nullish coalescing; optimized repeated property access.
  • Unit tests uncommented and updated with proper terminology.

Follow-ups (left for review)

  • Update bundle-size test thresholds (AISKULightSize, AppInsightsCoreSize) if needed.
  • Run npm run lint-fix + npm run fullCleanBuild before marking ready (requires environment outside VS Code due to Rush/ESLint plugin version conflicts).

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

JacksonWeber and others added 4 commits June 16, 2026 17:09
Completes and enables the SDK Stats manager (createStatsMgr) and routes
the resulting events to the distro-owned SDK Stats ingestion endpoint
(stats.monitor.azure.com / eu.stats.monitor.azure.com) instead of the
customer's breeze endpoint, matching the Microsoft OpenTelemetry distro.

- StatsBeat.ts: add SDK Stats endpoint constants, EU/non-EU region
  detection, per-event destination + placeholder iKey stamping,
  enabled-by-default feature gate, and createSdkStatsMgrConfig().
- AppInsightsCore / IAppInsightsCore / index: restore getStatsBeat,
  setStatsMgr, fields, unload cleanup, stubs, and exports.
- Sender.ts: restore request-counting hooks and statsBeatData; redirect
  SDK Stats items to the SDK Stats endpoint via a per-item URL override,
  bypassing the customer buffer; exclude SDK Stats sends from counting.
- AISku.ts: create, init and set the SDK Stats manager after core init.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds support for sending SDK Stats to either the new SDK Stats endpoint
(stats.monitor.azure.com) or the legacy breeze endpoints, selectable at
runtime via config.stats (IStatsBeatConfig), which is overridable through
the CDN / dynamic config.

- StatsType.ts: add eStatsEndpointType (SdkStats / Breeze) enum.
- IStatsBeat.ts: add IStatsBeatConfig.mode and IStatsBeatKeyMap.url.
- IConfiguration.ts: add stats?: IStatsBeatConfig (dynamic-config surface).
- StatsBeat.ts: factor EU detection into _isEuEndpoint; add
  getStatsBreezeIKey + breeze SDK Stats iKey constants; resolve the
  destination iKey/endpoint per-event in _track based on the (dynamic)
  mode; createSdkStatsMgrConfig now reads config.stats so the endpoint
  and key map can be overridden via the CDN at runtime. Defaults to the
  SDK Stats endpoint.
- index.ts: export the new enum, helper and constants.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cache telemetryItem.data reference to avoid repeated property lookups.
Reduces minified output size in hot path (runs for every telemetry item).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Uncommented all SDK Stats test files
- Updated test case names from 'StatsBeat' to 'SDK Stats'
- Updated test assertions to use 'SDK Stats' terminology
- Fixed import paths for relocated modules
- Tests now reference the feature as 'SDK Stats' in all user-facing messages

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JacksonWeber JacksonWeber marked this pull request as ready for review June 17, 2026 22:43
@JacksonWeber JacksonWeber requested a review from a team as a code owner June 17, 2026 22:43
Copilot AI review requested due to automatic review settings June 17, 2026 22:43

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.

Pull request overview

This PR re-enables the SDK Stats (StatsBeat) manager in the Application Insights JavaScript SDK and adds support for routing SDK Stats telemetry to a distro-owned ingestion endpoint (EU vs non-EU), rather than piggy-backing on the customer’s Breeze endpoint. It introduces a runtime-selectable destination mode via config/dynamic config, restores core APIs for stats manager access, and updates the Sender channel to redirect per-item sends when the SDK Stats endpoint override marker is present.

Changes:

  • Added SDK Stats endpoint + iKey resolution (EU vs non-EU), plus configurable routing mode (SDK Stats endpoint vs legacy Breeze) and per-event destination stamping.
  • Restored core APIs (getStatsBeat / setStatsMgr) and exports to support enabling SDK Stats from AISKU without increasing core bundle size.
  • Updated Sender to detect SDK Stats endpoint overrides, bypass the customer buffer for SDK Stats sends, and re-enabled associated unit tests.

Reviewed changes

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

Show a summary per file
File Description
shared/AppInsightsCore/Tests/Unit/src/aiunittests.ts Re-enabled SDK Stats unit test suite execution.
shared/AppInsightsCore/Tests/Unit/src/ai/StatsBeat.Tests.ts Re-enabled and updated core SDK Stats unit tests.
shared/AppInsightsCore/src/interfaces/ai/IStatsBeat.ts Added SDK Stats routing config surface (mode, per-keymap url).
shared/AppInsightsCore/src/interfaces/ai/IConfiguration.ts Added stats?: IStatsBeatConfig for runtime/dynamic config control.
shared/AppInsightsCore/src/interfaces/ai/IAppInsightsCore.ts Restored getStatsBeat / setStatsMgr APIs on the core interface.
shared/AppInsightsCore/src/index.ts Re-exported SDK Stats enums, interfaces, and core helper APIs/constants.
shared/AppInsightsCore/src/enums/ai/StatsType.ts Added eStatsEndpointType / StatsEndpointType for routing mode selection.
shared/AppInsightsCore/src/core/StatsBeat.ts Implemented SDK Stats endpoint/iKey resolution, routing mode support, and default manager config helper.
shared/AppInsightsCore/src/core/AppInsightsCore.ts Restored core state + lifecycle cleanup for stats manager / stats beat instance.
channels/applicationinsights-channel-js/Tests/Unit/src/StatsBeat.tests.ts Re-enabled channel-level SDK Stats tests for Sender request counting / emission.
channels/applicationinsights-channel-js/Tests/Unit/src/aichannel.tests.ts Re-enabled channel SDK Stats tests in the channel test runner.
channels/applicationinsights-channel-js/src/Sender.ts Added per-item SDK Stats endpoint override handling + direct send path, and restored request counting hooks.
AISKU/src/AISku.ts Enabled SDK Stats from AISKU after core init via createSdkStatsMgrConfig().

Comment thread channels/applicationinsights-channel-js/Tests/Unit/src/StatsBeat.tests.ts Outdated
Comment thread shared/AppInsightsCore/Tests/Unit/src/ai/StatsBeat.Tests.ts
Comment thread shared/AppInsightsCore/Tests/Unit/src/ai/StatsBeat.Tests.ts Outdated
JacksonWeber and others added 6 commits June 18, 2026 13:47
- Initialize the core before init-ing the stats manager against the same core instance so the manager actually enables (channel + core tests)
- Match the stats endCfg to the Sender's endpoint so metrics are tracked
- Pass an IStatsBeatState to getStatsBeat() when wiring the count spy
- Fix the xhr test config built with '&&' that discarded the Sender config
- Guard the dynamic-config test against double core initialization

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
IConfiguration exposes 'stats' (IStatsBeatConfig) at the top level, not under a '_sdk' wrapper. Update the SDK Stats unit tests to set config.stats and read cfg.stats so they compile against IConfiguration.

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

- Tick the real short interval (shrtInt*1000 ms) so the stats timer fires in the count/countException tests
- FeatureOptInMode.none and a null mode fall back to the SDK default (enabled), so assert SDK Stats stays enabled rather than being removed
- Bump core size budget to 135 KB raw / 55 KB deflate to cover the re-enabled getStatsBeat/setStatsMgr core APIs (was 133/54)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The 'SDK Stats initializes when stats is true' test initialized the stats manager but never called core.setStatsMgr(), so core.getStatsBeat() returned null. Register the manager with the core so the instance is created.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Enabling SDK Stats from AISKU pulls in the re-enabled core getStatsBeat/setStatsMgr APIs and stats manager wiring, growing the AISKU bundle. Bump the budget to 178 KB / 72 KB deflate (was 175/71).

Co-authored-by: Copilot <223556219+Copilot@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.

2 participants