Skip to content

Enable Customer SDK Stats#2707

Open
JacksonWeber wants to merge 30 commits intomicrosoft:mainfrom
JacksonWeber:jacksonweber/enable-customer-sdk-stats
Open

Enable Customer SDK Stats#2707
JacksonWeber wants to merge 30 commits intomicrosoft:mainfrom
JacksonWeber:jacksonweber/enable-customer-sdk-stats

Conversation

@JacksonWeber
Copy link

@JacksonWeber JacksonWeber commented Feb 21, 2026

This pull request introduces SDK statistics telemetry collection and notification improvements, as well as enhanced event retry notification and error reporting in the Application Insights JavaScript SDK. The main changes add support for dynamically enabling/disabling SDK stats telemetry, improve notification to listeners about retried and discarded events (with status codes), and enhance test coverage for these new behaviors.

SDK Statistics Telemetry and Dynamic Listener Management

  • Added support for SDK statistics telemetry (SdkStats) in the main configuration and enabled dynamic creation and cleanup of the SDK stats notification listener (_sdkStatsListener) based on feature flags. The listener is properly unloaded and flushed with other telemetry during shutdown. (AISKU/src/AISku.ts) [1] [2] [3] [4] [5] [6] [7]

Event Retry and Notification Enhancements

  • Implemented notification to listeners when events are retried (requeued) after a retriable failure, including passing HTTP status codes. This ensures better observability of event processing and retries. (channels/1ds-post-js/src/PostChannel.ts) [1] [2] [3]

Testing Improvements

  • Added a comprehensive unit test to verify that the eventsRetry notification is fired when events are requeued after a retriable failure, ensuring the feature works as intended. (channels/1ds-post-js/test/Unit/src/PostChannelTest.ts) [1] [2] [3]

Channel Plugin Notification Improvements

  • Enhanced the classic channel plugin to:
    • Store the telemetry item's baseType for SDK stats mapping.
    • Notify listeners of discarded events (with status code) and successful sends.
    • Notify listeners of retries, including the HTTP status code. (channels/applicationinsights-channel-js/src/Interfaces.ts, channels/applicationinsights-channel-js/src/Sender.ts) [1] [2] [3] [4] [5] [6] [7] [8]

@JacksonWeber JacksonWeber marked this pull request as ready for review February 24, 2026 18:07
@JacksonWeber JacksonWeber requested a review from a team as a code owner February 24, 2026 18:07
Copilot AI review requested due to automatic review settings February 24, 2026 18:07
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 pull request introduces comprehensive SDK statistics tracking and enhances the notification system to support telemetry retry events. The main objective is to enable periodic reporting of SDK usage metrics (success, dropped, and retry counts) and provide visibility into the complete telemetry lifecycle including retry scenarios.

Changes:

  • Adds eventsRetry notification callback to INotificationManager and INotificationListener interfaces for tracking telemetry retry events with HTTP status codes
  • Implements SdkStatsNotificationCbk - a notification listener that accumulates telemetry counts by type and periodically reports them as metrics
  • Integrates SDK stats listener into AISku with automatic initialization (enabled by default) and proper cleanup during unload
  • Updates Sender to trigger notifications for sent, discarded, and retried events, storing baseType in IInternalStorageItem for telemetry type mapping
  • Adds comprehensive unit tests for the SDK stats notification callback covering all major scenarios

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
shared/AppInsightsCore/src/interfaces/ai/INotificationManager.ts Adds eventsRetry method signature to notification manager interface
shared/AppInsightsCore/src/interfaces/ai/INotificationListener.ts Adds optional eventsRetry callback to listener interface
shared/AppInsightsCore/src/index.ts Exports new SDK stats notification callback factory and interfaces
shared/AppInsightsCore/src/core/SdkStatsNotificationCbk.ts New file implementing the SDK stats accumulator and periodic metric flushing logic
shared/AppInsightsCore/src/core/NotificationManager.ts Implements eventsRetry notification dispatch to all registered listeners
shared/AppInsightsCore/src/constants/InternalConstants.ts Adds STR_EVENTS_RETRY constant for the new notification type
shared/AppInsightsCore/Tests/Unit/src/aiunittests.ts Registers new SDK stats notification callback test suite
shared/AppInsightsCore/Tests/Unit/src/ai/SdkStatsNotificationCbk.Tests.ts New comprehensive test suite covering all SDK stats functionality
channels/applicationinsights-channel-js/src/Sender.ts Adds notification triggers for sent/discarded/retry events and extracts telemetry items for notifications
channels/applicationinsights-channel-js/src/Interfaces.ts Adds bT (baseType) property to IInternalStorageItem for telemetry type mapping
AISKU/src/AISku.ts Integrates SDK stats listener with initialization, configuration, and unload handling

@JacksonWeber JacksonWeber changed the title Jacksonweber/enable customer sdk stats Enable Customer SDK Stats Feb 24, 2026
@JacksonWeber JacksonWeber force-pushed the jacksonweber/enable-customer-sdk-stats branch from 9ed6655 to 7eaafe0 Compare February 25, 2026 20:21
@JacksonWeber JacksonWeber changed the base branch from beta to main February 25, 2026 20:22
@JacksonWeber JacksonWeber requested a review from Copilot February 25, 2026 20:23
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

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

// Notify listeners of successful send
let mgr = _getNotifyMgr();
if (mgr) {
let items = _extractTelemetryItems(payload);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up PR -- lets try and minimize the need to call this, it might be a large PR as it will most likely require changing the whole serialization process (like we do in 1ds-post-js) where we convert to a string as late as possible so at this level we are still playing with the objects -- there is a gotya around the persistence to the session storage / array storage today for this though.

@JacksonWeber JacksonWeber requested a review from MSNev March 5, 2026 19:49
@JacksonWeber JacksonWeber force-pushed the jacksonweber/enable-customer-sdk-stats branch from 134aa94 to c5776d5 Compare March 18, 2026 22:05
…ackage

The 1ds-core-js package is no longer actively updated, so instead of
reading its version from package.json, derive the 1ds version by taking
the core package version and incrementing the major version by 1.
For example, core version 3.3.11 produces 1ds version 4.3.11.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diagnosticLogInterval: UNDEFINED_VALUE,
traceHdrMode: eTraceHeadersMode.All,
sdkStats: cfgDfMerge({
lang: "JavaScript",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 are the 2 items I was talking about -- by having them here they will be populated in the shared config (and become dynamic) -- if they are not needed (because we don't wany to let them be changed) then they should not be included (extra bundle size and CPU / memory usage on initialization)

export { IXDomainRequest, IBackendResponse } from "./interfaces/ai/IXDomainRequest";
export { _ISenderOnComplete, _ISendPostMgrConfig, _ITimeoutOverrideWrapper, _IInternalXhrOverride } from "./interfaces/ai/ISenderPostManager";
export { SenderPostManager } from "./core/SenderPostManager";
export { createSdkStatsNotifCbk, ISdkStatsConfig, ISdkStatsNotifCbk } from "./core/SdkStatsNotificationCbk";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export "createSdkStatsNotifCbk"?
As this then becomes part of the public API, as part of removing the 1ds-core-js so it's now part of the applicationinsights-core-js it gives us more flexibility to avoid exposing internal implementations just to share for 1ds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And tests "should" be able to reach into the src files within importing from the package to enable internal unit testing

};

// version and language are SDK-internal
objDefine(props, "language", { v: "JavaScript", w: false, c: false, e: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to use objDefine here as your just creating the "event" (metric) so just adding to the props "should" be fine ....

Unless you want to explicitly stop the end-users changing this value via a telemetry initializer (which is really all this is doing. -- It was just the config / core instance that I was thinking about for this not the reported event.


// version and language are SDK-internal
objDefine(props, "language", { v: "JavaScript", w: false, c: false, e: true });
objDefine(props, "version", { v: _version, w: false, c: false, e: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is also going to always use the application insights version and not the 1ds-version when running from 1ds. -- So as customer stats go this "might" confuse (cause questions / incidents) people.

* @returns An INotificationListener with flush and unload methods
*/
/*#__NO_SIDE_EFFECTS__*/
export function createSdkStatsNotifCbk(core: IAppInsightsCore): ISdkStatsNotifCbk {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps either pass the "version" from the core instance here -- or add a specific readonly version to the core instance and use that.

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