Improve OsPlugin reliability: proactive OS retrieval, unload handling, and session caching#2719
Open
MSNev wants to merge 1 commit intomicrosoft:mainfrom
Open
Improve OsPlugin reliability: proactive OS retrieval, unload handling, and session caching#2719MSNev wants to merge 1 commit intomicrosoft:mainfrom
MSNev wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Collaborator
MSNev
commented
Mar 31, 2026
- Refactor OsPlugin to start OS version retrieval during initialize() instead of waiting for the first telemetry event, reducing latency for the initial tracked events
- Add page unload/pagehide/visibilitychange event handlers to flush the queued telemetry when the page is being unloaded before the OS lookup completes
- Respect disableFlushOnUnload config to skip registering unload handlers when disabled
- Properly clean up unload event handlers after OS version is resolved
- Improve session storage caching: validate cached OS data on load and guard writes behind isStorageUseDisabled config check
- Use safeGetLogger and getNavigator() instead of direct navigator/core.logger access for safer operation when core may not be fully initialized
- Fix safeGetLogger to fall back to core.config when no explicit config is provided
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Application Insights OS plugin reliability by starting OS version retrieval during initialize(), adding unload-time flushing for queued telemetry, and strengthening session-storage caching behavior; it also includes a small safeGetLogger fix and related test updates.
Changes:
- Refactors
OsPluginto proactively fetch OS version on initialize, queue/flush telemetry during lookup, and add/remove unload/pagehide/visibilitychange handlers (respectingdisableFlushOnUnload). - Improves OS sessionStorage caching behavior and updates/extends unit tests to cover the new lifecycle and caching scenarios.
- Fixes
safeGetLoggerfallback behavior and updates minification config foreUrlRedactionOptions.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/AppInsightsCore/Tests/Unit/src/ai/ThrottleMgr.tests.ts | Adds UTC date helpers to simplify and stabilize date calculations in throttle interval tests. |
| shared/AppInsightsCore/src/enums/ai/UrlRedactionOptions.ts | Minor formatting change in the exported enum-style object. |
| shared/AppInsightsCore/src/diagnostics/DiagnosticLogger.ts | Updates safeGetLogger() to fall back to core.config when no explicit config is provided. |
| extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts | Adds/updates unit tests for proactive OS retrieval, unload flushing, handler cleanup, and session caching behavior. |
| extensions/applicationinsights-osplugin-js/src/OsPlugin.ts | Implements proactive OS lookup, unload flushing, and storage-guarded caching; refactors telemetry update logic. |
| .aiAutoMinify.json | Adds eUrlRedactionOptions to the auto-minify symbol list. |
extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts
Show resolved
Hide resolved
8c72365 to
a43a0dd
Compare
extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts
Show resolved
Hide resolved
…, and session caching - Refactor OsPlugin to start OS version retrieval during initialize() instead of waiting for the first telemetry event, reducing latency for the initial tracked events - Add page unload/pagehide/visibilitychange event handlers to flush the queued telemetry when the page is being unloaded before the OS lookup completes - Respect disableFlushOnUnload config to skip registering unload handlers when disabled - Properly clean up unload event handlers after OS version is resolved - Improve session storage caching: validate cached OS data on load and guard writes behind isStorageUseDisabled config check - Use safeGetLogger and getNavigator() instead of direct navigator/core.logger access for safer operation when core may not be fully initialized - Fix safeGetLogger to fall back to core.config when no explicit config is provided
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
extensions/applicationinsights-osplugin-js/Tests/Unit/src/OsPluginTest.ts:232
- There is a leftover
console.log()in this unit test. This can add noise to CI logs and isn't needed for assertions; please remove it (or gate behind a debug flag if intentionally kept).
Assert.equal(this._channelSpy.called, true);
let telemetry = this._channelSpy.getCall(0).args[0];
console.log("telemetry", JSON.stringify(telemetry));
Assert.equal(JSON.stringify(telemetry).includes("osVer"), true, "before timeout, get os version");
JacksonWeber
approved these changes
Apr 3, 2026
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.