-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: support openTelemetry for browser mode #9180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: support openTelemetry for browser mode #9180
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
851cd85 to
056b80c
Compare
There was a problem hiding this 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 PR adds OpenTelemetry tracing support for Vitest's browser mode, enabling trace collection from browser runtime in addition to the existing Node.js side tracing. The implementation propagates trace context from the Node.js orchestrator to browser contexts (orchestrator iframe and test iframes) using OTEL carrier objects, allowing proper parent-child span relationships across runtime boundaries.
Key Changes
- Added
browserSdkPathconfiguration option to specify a browser-compatible OpenTelemetry SDK - Implemented trace context propagation from Node.js to browser using OTEL carriers
- Added traces for browser pool operations, orchestrator lifecycle, tester execution, and browser commands
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
packages/vitest/src/utils/traces.ts |
Added bind() and flush() methods; made SDK type support optional forceFlush; added @vite-ignore for dynamic imports |
packages/vitest/src/types/browser.ts |
Added otelCarrier field to BrowserTesterOptions for context propagation |
packages/vitest/src/runtime/config.ts |
Added openTelemetry config to SerializedConfig for browser runtime |
packages/vitest/src/public/browser.ts |
Exported Traces and OTELCarrier for browser use |
packages/vitest/src/node/types/config.ts |
Added browserSdkPath to OpenTelemetry config interface |
packages/vitest/src/node/pools/browser.ts |
Instrumented browser pool with vitest.browser, vitest.browser.open, and vitest.browser.run spans |
packages/vitest/src/node/config/serializeConfig.ts |
Serialized OpenTelemetry config for browser runtime |
packages/vitest/src/node/config/resolveConfig.ts |
Resolved browserSdkPath to absolute path |
packages/browser/src/node/plugin.ts |
Added browser SDK to Vite optimization entries |
packages/browser/src/client/utils.ts |
Added traces to BrowserRunnerState |
packages/browser/src/client/tester/tester.ts |
Initialized traces in tester, created root span, and instrumented test execution |
packages/browser/src/client/tester/tester-utils.ts |
Added tracing to browser commands |
packages/browser/src/client/tester/runner.ts |
Implemented trace method for browser test runner |
packages/browser/src/client/orchestrator.ts |
Created orchestrator traces and propagated context to iframes |
packages/browser/src/client/channel.ts |
Added otelCarrier to IframePrepareEvent |
packages/browser/scripts/build-client.js |
Added build wrapper script for client watch mode |
packages/browser/package.json |
Updated dev:client script; added @opentelemetry/api dependency |
test/cli/test/open-telemetry.test.ts |
Added test case for browser SDK configuration |
test/cli/package.json |
Added OpenTelemetry browser dependencies |
test/cli/fixtures/otel-tests/otel.browser.sdk.js |
Added minimal browser SDK fixture for testing |
test/core/test/exports.test.ts |
Updated snapshot for new Traces export |
examples/opentelemetry/vite.config.ts |
Added browserSdkPath to example config |
examples/opentelemetry/src/other.test.ts |
Added example tests demonstrating browser tracing |
examples/opentelemetry/package.json |
Added OpenTelemetry browser dependencies |
examples/opentelemetry/otel-browser.js |
Created example browser SDK setup |
examples/opentelemetry/jaeger-config.yml |
Configured CORS for browser trace exports |
docs/guide/open-telemetry.md |
Added browser mode documentation section |
docs/config/experimental.md |
Documented browserSdkPath configuration |
pnpm-lock.yaml |
Added OpenTelemetry browser dependencies and updated jsdom |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Description
Resolves #9043
Summary
This PR improves open telemetry integration for browser by adding following traces:
vitest.browser.run,vitest.browser.openvitest.browser.orchestrator.runvitest.browser.tester.run,vitest.browser.tester.command(+ enable existing test runner traces)The browser runtime side traces (orchestrator and tester) rely on SDK provided through
browserSdkPath. On browser runtime, async context doesn't work, so each test runner span aren't nested. However, main internal spans relationsvitest.browser.run -> vitest.browser.orchestrator.run -> vitest.browser.tester.run -> vitest.test.runner.xxxare nested by manually passing otel carrier and setting up root context in each browser runtime.TODO
pools/poolRunner.tstraces topools/browser.tsvitest.test.runner.test.callback)To explore:
Example
pnpm -C examples/opentelemetry/ compose up -d pnpm -C examples/opentelemetry/ test --experimental.openTelemetry.enabled --browser.enabled runScreenshot 📸
pnpm -C examples/opentelemetry/ test --experimental.openTelemetry.enabled --browser.enabled --browser.headless runScreenshot 📸
npm -C examples/opentelemetry/ test --experimental.openTelemetry.enabled --browser.enabled --browser.headless --isolate=false --maxWorkers=1 run(This looks weird because there are two
vitest.browser.orchestrator.runbut only onevitest.browser.tester.run, but it shows tester iframe is reused properly.)Screenshot 📸
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.