Conversation
There was a problem hiding this comment.
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
eventsRetrynotification 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 |
shared/AppInsightsCore/Tests/Unit/src/ai/SdkStatsNotificationCbk.Tests.ts
Show resolved
Hide resolved
9ed6655 to
7eaafe0
Compare
| // Notify listeners of successful send | ||
| let mgr = _getNotifyMgr(); | ||
| if (mgr) { | ||
| let items = _extractTelemetryItems(payload); |
There was a problem hiding this comment.
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.
134aa94 to
c5776d5
Compare
…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", |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Perhaps either pass the "version" from the core instance here -- or add a specific readonly version to the core instance and use that.
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
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
channels/1ds-post-js/src/PostChannel.ts) [1] [2] [3]Testing Improvements
eventsRetrynotification 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
baseTypefor SDK stats mapping.channels/applicationinsights-channel-js/src/Interfaces.ts,channels/applicationinsights-channel-js/src/Sender.ts) [1] [2] [3] [4] [5] [6] [7] [8]