-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Merged
hi-ogawa
merged 58 commits into
vitest-dev:main
from
hi-ogawa:12-04-feat_support_opentelemetry_for_browser_mode
Dec 19, 2025
+466
−47
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
401a8d3
feat: support openTelemetry for browser mode (wip)
hi-ogawa 1b9169a
chore: add examples/opentelemetry
hi-ogawa 063e192
vitest.browser.open
hi-ogawa adc451c
vitest.browser.run
hi-ogawa 6cdad2a
cleanup
hi-ogawa 527b41d
Merge branch 'main' into 12-04-feat_support_opentelemetry_for_browser…
hi-ogawa 8057c1d
chore: tweak examples
hi-ogawa 5d0d333
tweak
hi-ogawa 8b0885f
Merge branch 'main' into 12-04-feat_support_opentelemetry_for_browser…
hi-ogawa 7d5f86d
span "vitest.browser"
hi-ogawa 830048b
trace `vitest.browser.orchestrator.iframe`
hi-ogawa 74018e0
browserSdkPath
hi-ogawa 4ee2b43
exports.test
hi-ogawa c68ffbd
wip: trace on tester
hi-ogawa aad5157
fix: bind root tester context
hi-ogawa c4d2eae
cleanup .claude/issue-9043.md
hi-ogawa 997b706
example BatchSpanProcessor
hi-ogawa b20711b
refactor: orchestrator traces
hi-ogawa 4f1340e
refactor: orchestrater trace
hi-ogawa fd17c84
examples: two files
hi-ogawa 458799a
fix: back to one orchestrator one Traces
hi-ogawa 683b2ba
fix: trace per tester iframe events
hi-ogawa 9480a0c
Merge branch 'main' into 12-04-feat_support_opentelemetry_for_browser…
hi-ogawa 21de3d8
chore: fix browser watch build
hi-ogawa faa7d4c
cleanup
hi-ogawa 1199e45
docs: @opentelemetry/api is peer dep
hi-ogawa 13336be
todo
hi-ogawa aaad556
fix: optimize otel deps
hi-ogawa 0cdff75
comment
hi-ogawa e16cf81
docs: todo
hi-ogawa 5171320
test: add test
hi-ogawa 1322c16
docs
hi-ogawa bb813bc
cleanup
hi-ogawa c46b4d1
docs: simplify
hi-ogawa 8d4bc2a
docs: experimental.md
hi-ogawa 52905a4
docs: cleanup
hi-ogawa f5203f7
refactor tester
hi-ogawa 056b80c
cleanup
hi-ogawa ae8f376
fix: fix windows
hi-ogawa 6a70d18
examples: test custom trace
hi-ogawa 0bc3a51
fix: please `/@fs/`
hi-ogawa b6f9bae
trace `vitest.browser.tester.command`
hi-ogawa a6eee41
cleanup
hi-ogawa d5899a1
examples: test ZoneContextManager
hi-ogawa bf13c47
refactor tester
hi-ogawa 7cd9ebf
docs: fix @opentelemetry/exporter-trace-otlp-proto
hi-ogawa f78898d
fix: endSpan outside of loop
hi-ogawa 9161a57
fix: null check
hi-ogawa 0c41299
fix: move spand.end
hi-ogawa 24f5f2a
Merge branch 'main' into 12-04-feat_support_opentelemetry_for_browser…
hi-ogawa e2315f1
tweak docs and comment
hi-ogawa 0f7a1d4
Merge branch 'main' into 12-04-feat_support_opentelemetry_for_browser…
hi-ogawa fa83301
comment
hi-ogawa a027bfb
add Traces.recordInitSpan
hi-ogawa 758575c
wip: orchestrator recordInitSpan
hi-ogawa f15572d
fix: move parent trace for orchestrater init span
hi-ogawa 98d3e7a
refactor: pass carrier through orchestrator url
hi-ogawa 7a752ac
refactor: more recordInitSpan
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' | ||
| import { resourceFromAttributes } from '@opentelemetry/resources' | ||
| import { BatchSpanProcessor, WebTracerProvider } from '@opentelemetry/sdk-trace-web' | ||
|
|
||
| const provider = new WebTracerProvider({ | ||
| resource: resourceFromAttributes({ | ||
| 'service.name': 'vitest-browser', | ||
| }), | ||
| spanProcessors: [ | ||
| new BatchSpanProcessor(new OTLPTraceExporter()), | ||
| // you can add a ConsoleSpanExporter for debugging purposes | ||
| // (available in @opentelemetry/sdk-trace-web) | ||
| // new SimpleSpanProcessor(new ConsoleSpanExporter()), | ||
| ], | ||
| }) | ||
|
|
||
| provider.register({ | ||
| // you can customize contextManager but browser support has limitation | ||
| // cf. https://github.com/open-telemetry/opentelemetry-js/discussions/2060 | ||
| // contextManager: new StackContextManager(), // this is the default (avialable in sdk-trace-web) | ||
| // contextManager: new ZoneContextManager(), // doesn't seem to help (avialable in @opentelemetry/context-zone) | ||
| }) | ||
|
|
||
| export default provider |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { trace } from '@opentelemetry/api' | ||
| import { test } from 'vitest' | ||
|
|
||
| test('other', async () => { | ||
| await new Promise(r => setTimeout(r, 150)) | ||
| }) | ||
|
|
||
| test('custom', async () => { | ||
| // this starts span synchronously inside test function, | ||
| // so trace parent works without async context manager (e.g. on browser mode). | ||
|
|
||
| // console.log(context.active()) | ||
| // > vitest.test.runner.test.callback | ||
| // > custom-span | ||
|
|
||
| const tracer = trace.getTracer('custom-scope') | ||
| await tracer.startActiveSpan('custom-span', async (span) => { | ||
| span.setAttribute('custom-attribute', 'hello world') | ||
| await new Promise(resolve => setTimeout(resolve, 50)) | ||
| span.end() | ||
| }) | ||
|
|
||
| // however the context is dropped on browser mode. | ||
| // console.log(context.active()) | ||
| }) | ||
|
|
||
| test.runIf(typeof document !== 'undefined')('browser test', async () => { | ||
| const { page } = await import('vitest/browser') | ||
| document.body.innerHTML = `<button>Hello Vitest</button>` | ||
| await page.getByRole('button', { name: 'Hello Vitest' }).click() | ||
| }) |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // wrapper script for `node --watch`. | ||
| // this works around some issues with `vite build --watch`. | ||
| import { spawn } from 'node:child_process' | ||
|
|
||
| spawn('node', ['--run', 'build:client'], { | ||
| stdio: 'inherit', | ||
| }) | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.