chore(analytics-browser): add platform and web_environment tags to diagnostics - #1914
Merged
Merged
Conversation
Report `platform: "Web"` as a diagnostics tag, alongside the existing `library` and `user_agent` tags. Reuse the `BROWSER_PLATFORM` constant already used for the analytics event `platform` field so the two stay in sync. Mirrors the mobile SDKs, which set the same `platform` tag key with "iOS"/"macOS"/"Android". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
Add isBrowser/isWebWorker (copied from the paused #1908 so the two branches converge), plus isServiceWorker, isNode, and a getWebEnvironment() resolver returning one of: browser, web_worker, service_worker, chrome_extension, chrome_extension_service_worker, node, unknown. Check order is load-bearing: ServiceWorkerGlobalScope inherits from WorkerGlobalScope; extension pages have a document; jsdom has both document and process.versions.node. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Report the JS runtime environment alongside the platform tag, so diagnostics can distinguish page / worker / service worker / extension traffic. Named web_environment because Datadog already auto-tracks an environment tag. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The helpers are only consumed by the browser SDK, and core is shared by all platforms — keep it as light as possible. Reverts analytics-core to untouched (which also removes the merge conflict with #1908) and keeps getWebEnvironment() internal to analytics-browser, with predicates taking the resolved global scope so classification reads one consistent object. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 806320b. Configure here.
…vironment Some classified environments aren't web (node), so WebEnvironment was a misnomer. The web_environment tag key is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
daniel-graham-amplitude
approved these changes
Jul 31, 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.
Summary
Adds two diagnostics tags on the browser SDK, set at init in
browser-client.tsnext to the existinglibraryanduser_agenttags:platformWeb— reuses theBROWSER_PLATFORMconstant backing the analytics eventplatformfield (src/plugins/context.ts), and matches the mobile diagnostics values (Swift:iOS/tvOS/visionOS/macOS/watchOS, Kotlin:Android)web_environmentbrowser|web_worker|service_worker|chrome_extension|chrome_extension_service_worker|node|unknownweb_environmentrefinesplatform: Webby JS runtime — each value is a distinct event-loss regime (workers have nolocalStorageso the event queue falls back toMemoryStorage; service workers are additionally killed after ~30s idle and can't usexhr/beacontransports). Namedweb_environmentbecause Datadog already auto-tracks anenvironmenttag. Full design incl. the API-availability-per-environment table: SDKW-47 design comment.Detection is internal to
analytics-browser(src/utils/environment.ts,getRuntimeEnvironment()) — it's only consumed here, and core stays light since it's shared by all platforms.analytics-coreis untouched. Check order is load-bearing:ServiceWorkerGlobalScopeinherits fromWorkerGlobalScopebrowserafter thechrome.runtime.idsplit — extension pages and content scripts have adocumentbrowserbeforenode— jsdom exposes bothdocumentandprocess.versions.nodeOut of scope
Tracking the exact event-drop reason (storage fallback, retry exhaustion, transport unsupported): SDKW-48.
Testing
analytics-browser— 499 tests pass, coverage 100% on all four metrics (repo gate); new suite covers everygetRuntimeEnvironmentbranch, incl. service-worker-vs-web-worker precedence, extension variants, and exposed-but-not-instance worker constructorsanalytics-core— untouched, 869 tests passeslintclean on changed filesCloses SDKW-47 — https://linear.app/amplitude/issue/SDKW-47/diagnostics-add-platform-web
Checklist
🤖 Generated with Claude Code
Note
Low Risk
Observability-only metadata at init; no changes to event pipeline, storage, or transports.
Overview
Adds
platform(Web, from exportedBROWSER_PLATFORM) andweb_environment(from newgetRuntimeEnvironment()) as diagnostics tags during browser SDK init, alongside existinglibraryanduser_agenttags.getRuntimeEnvironment()insrc/utils/environment.tsclassifies the JS runtime (browser, workers, Chrome extension contexts, Node, orunknown) usinggetGlobalScope()with an explicit check order (service worker before web worker, extension split on main thread, browser before Node for jsdom). Tests cover init tag wiring and every classification branch.Reviewed by Cursor Bugbot for commit 806320b. Configure here.