Enable SDK Stats and route to the SDK Stats ingestion endpoint#2741
Open
JacksonWeber wants to merge 10 commits into
Open
Enable SDK Stats and route to the SDK Stats ingestion endpoint#2741JacksonWeber wants to merge 10 commits into
JacksonWeber wants to merge 10 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
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(). |
- 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>
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.
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-netStatsbeatConstants.cs+ the .NET distro)https://stats.monitor.azure.com/v2/trackhttps://eu.stats.monitor.azure.com/v2/track00000000-0000-0000-0000-000000000000, same Breeze envelope, no auth. EU vs non-EU chosen from the customer endpoint region.Configurable Destination (new
stats.monitorendpoint vs. legacy breeze)The SDK Stats destination is now selectable at runtime via the CDN / dynamic config:
config.stats(IStatsBeatConfig), overridable via the CDN / cfgSync dynamic config.config.stats.mode(eStatsEndpointType):SdkStats(default) sends tostats.monitor.azure.com/eu.stats.monitor.azure.com;Breezesends to the legacy breeze endpoint (the customer's own breeze host, using the Microsoft-owned SDK Stats iKeyc4a29126…/7dc56bab…by region)._trackfrom the live config, so CDN changes take effect at runtime. A fullendCfgkey map (with explicitkeyand newurl) can also be supplied viaconfig.stats.endCfgto fully override routing.Note: in
Breezemode the events flow through the normal channel to the customer's breeze endpoint (legacy behaviour); inSdkStatsmode 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 viafeatureOptIn: "sdkStats"),createSdkStatsMgrConfig()helper, and configurable mode + key map support.AppInsightsCore.ts/IAppInsightsCore.ts/index.ts— restoregetStatsBeat/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— addedstats?: IStatsBeatConfigfield for dynamic config.StatsType.ts— addedeStatsEndpointTypeenum (SdkStats/Breeze).IStatsBeat.ts— addedIStatsBeatConfig.modeandIStatsBeatKeyMap.urlfields.StatsBeat.Tests.tsin both core and channel-js), fixed import paths, updated terminology from "statsbeat" to "SDK Stats" in test names and assertions.Architecture note
createStatsMgrlives in core, which cannot depend on the channel's BreezeEnvelopeCreator. 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
tsc --noEmitfrom source using the repo's exact compiler settings — core, channel, and AISKU compile with 0 errors.Follow-ups (left for review)
AISKULightSize,AppInsightsCoreSize) if needed.npm run lint-fix+npm run fullCleanBuildbefore marking ready (requires environment outside VS Code due to Rush/ESLint plugin version conflicts).Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com