Skip to content

Enable Customer SDK Stats#2707

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

Enable Customer SDK Stats#2707
JacksonWeber wants to merge 26 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
[SDK_STATS]: {mode: FeatureOptInMode.enable}
},
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.

Do we really want to make this a config? As this would allow end-users to change this to anything they like

Copy link
Author

Choose a reason for hiding this comment

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

Removed lang from being dynamically configurable.

},
sdkStats: cfgDfMerge({
lang: "JavaScript",
ver: UNDEFINED_VALUE,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess likewise with this one.

var props: { [key: string]: any } = {
telemetry_type: telType,
language: statsCfg.lang || "JavaScript",
version: statsCfg.ver || "unknown",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than defaulting to "Unknown" we could put a const version at the top of the file, which would be set by the build -- downside, for 1DS this would report the ApplicationInsights version and not the 1DS version.

And I guess these 2 setting are also part of the eariler comment about "letting" the end-user change / set the config -- should both of these be some sort of "internal" config (which we don't currently have). But there is a pluginString that we could use something like this that could expose the SDK version etc

Copy link
Author

Choose a reason for hiding this comment

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

Added this constant to pull version from the build.

for (let i = 0; i < listeners.length; i++) {
let listener = listeners[i];
// The SDK stats listener has a flush and unload method
if (listener && typeof listener.flush === "function" && typeof listener.unload === "function" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

general comment (doesn't need to be changed)

This is potentially fragile and might break at some point in the future, as this would find the "first" listener that has all 4 functions and may not actually be the sdkStats listener -- maybe use a "known" symbol to tag the returned instance (object returned by the createSdkStats...) using effectively the Symbol.for (via symbolFor helper) as this returns the same global symbol for the provided string -- so symbolFor("sdkStats") always creates and returns the same symbol regardless of who creates it the first time,

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