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
| function _extractTelemetryItems(payload: IInternalStorageItem[]): ITelemetryItem[] { | ||
| if (payload && payload.length) { | ||
| let items: ITelemetryItem[] = []; | ||
| arrForEach(payload, (p) => { | ||
| if (p) { | ||
| let baseType = p.bT || "EventData"; | ||
| items.push({ name: baseType, baseType: baseType } as ITelemetryItem); |
There was a problem hiding this comment.
The name field in extracted telemetry items is set to baseType (line 1427), which doesn't represent the actual telemetry item name. This creates synthetic items where name equals baseType (e.g., both set to "EventData"). While this may be intentional for notification purposes since the original name is not available in IInternalStorageItem, it could be misleading for listeners expecting accurate telemetry item information. Consider documenting this behavior in the function comment or using a more descriptive synthetic name pattern.
| * error handler | ||
| */ | ||
| _self._onError = (payload: IInternalStorageItem[] | string[], message: string, event?: ErrorEvent) => { | ||
| _self._onError = (payload: IInternalStorageItem[] | string[], message: string, event?: ErrorEvent, statusCode?: number) => { |
There was a problem hiding this comment.
The public stub signature for _onError is missing the new statusCode parameter. The implementation at line 630 accepts a statusCode parameter, but the stub at line 1594 does not include it. Update the stub signature to include the optional statusCode parameter: public _onError(payload: string[] | IInternalStorageItem[], message: string, event?: ErrorEvent, statusCode?: number)
This pull request introduces SDK statistics tracking and enhances event notification capabilities in the Application Insights SDK. The main focus is on enabling periodic SDK stats reporting, improving notification for telemetry event lifecycle (including retries), and supporting these features with new interfaces and configuration options.
SDK Statistics Tracking:
SDK_STATS,SDK_STATS_VERSION,SDK_STATS_FLUSH_INTERVAL) and default enablement in the config. The stats listener is registered during initialization and properly cleaned up on unload. (AISKU/src/AISku.ts[1] [2] [3] [4] [5] [6]ISdkStatsNotifCbkand related imports to facilitate SDK stats notification callbacks. (AISKU/src/AISku.tsAISKU/src/AISku.tsL14-R21)Telemetry Event Notification Enhancements:
eventsRetryevent, allowing listeners to be notified when telemetry items are retried, along with the relevant HTTP status code. (shared/AppInsightsCore/src/constants/InternalConstants.ts[1]shared/AppInsightsCore/src/core/NotificationManager.ts[2] [3] [4]Senderplugin to trigger notification callbacks for events sent, discarded, and retried, including logic to extract minimal telemetry items for notification purposes. (channels/applicationinsights-channel-js/src/Sender.ts[1] [2] [3] [4] [5]Internal Data Structure Updates:
bT(baseType) property toIInternalStorageItemfor mapping telemetry types in SDK stats and notification extraction. (channels/applicationinsights-channel-js/src/Interfaces.ts[1]channels/applicationinsights-channel-js/src/Sender.ts[2]These changes collectively improve observability, reliability, and extensibility of the telemetry pipeline, especially for SDK usage metrics and event retry handling.