-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(bun): Add bunRuntimeMetricsIntegration
#19979
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a3fa333
wip
chargome 1198de9
fix units
chargome ede983c
.
chargome 36c65ad
trim down defaults
chargome 8eb8b58
fix: re-export nodeRuntimeMetricsIntegration in astro/aws-serverless/…
chargome 22d0b42
fix(test): disable eventLoopDelayP50 in opt-out scenario
chargome 347917f
fix(node): use process.on instead of process.once for beforeExit list…
chargome d67aa51
fix(node): remove beforeExit flush from nodeRuntimeMetricsIntegration
chargome eb3c16d
feat(node): add sentry.origin attribute to runtime metrics, full asse…
chargome ff6e6a0
feat(core): export safeUnref as _INTERNAL_safeUnref, use in nodeRunti…
chargome 83d32be
style(node): use bracketed if blocks in nodeRuntimeMetricsIntegration
chargome 7abc910
fmt
chargome 37b2e12
prevent leaks
chargome cdd501f
fix(node): use expect.objectContaining for metric attribute assertion…
chargome a97b5b2
feat(bun): add bunRuntimeMetricsIntegration
chargome 3fca862
test(bun): add integration tests for bunRuntimeMetricsIntegration
chargome 33f816b
fmt
chargome c2b78bd
meta(changelog): add bunRuntimeMetricsIntegration entry
chargome 5c26482
meta(changelog): consolidate node/bun runtime metrics entries
chargome c96481e
refactor(bun): use Pick instead of Omit for BunCollectOptions
chargome 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
27 changes: 27 additions & 0 deletions
27
dev-packages/node-integration-tests/suites/bun-runtime-metrics/scenario-all.ts
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,27 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { bunRuntimeMetricsIntegration } from '@sentry/bun'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0.0', | ||
| environment: 'test', | ||
| transport: loggingTransport, | ||
| integrations: [ | ||
| bunRuntimeMetricsIntegration({ | ||
| collectionIntervalMs: 100, | ||
| collect: { | ||
| cpuTime: true, | ||
| memExternal: true, | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| async function run(): Promise<void> { | ||
| await new Promise<void>(resolve => setTimeout(resolve, 250)); | ||
| await Sentry.flush(); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| run(); |
29 changes: 29 additions & 0 deletions
29
dev-packages/node-integration-tests/suites/bun-runtime-metrics/scenario-opt-out.ts
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,29 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { bunRuntimeMetricsIntegration } from '@sentry/bun'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0.0', | ||
| environment: 'test', | ||
| transport: loggingTransport, | ||
| integrations: [ | ||
| bunRuntimeMetricsIntegration({ | ||
| collectionIntervalMs: 100, | ||
| collect: { | ||
| cpuUtilization: false, | ||
| cpuTime: false, | ||
| eventLoopUtilization: false, | ||
| uptime: false, | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| async function run(): Promise<void> { | ||
| await new Promise<void>(resolve => setTimeout(resolve, 250)); | ||
| await Sentry.flush(); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| run(); |
23 changes: 23 additions & 0 deletions
23
dev-packages/node-integration-tests/suites/bun-runtime-metrics/scenario.ts
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,23 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { bunRuntimeMetricsIntegration } from '@sentry/bun'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0.0', | ||
| environment: 'test', | ||
| transport: loggingTransport, | ||
| integrations: [ | ||
| bunRuntimeMetricsIntegration({ | ||
| collectionIntervalMs: 100, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| async function run(): Promise<void> { | ||
| await new Promise<void>(resolve => setTimeout(resolve, 250)); | ||
| await Sentry.flush(); | ||
| } | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| run(); |
116 changes: 116 additions & 0 deletions
116
dev-packages/node-integration-tests/suites/bun-runtime-metrics/test.ts
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,116 @@ | ||
| import { afterAll, describe, expect, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../utils/runner'; | ||
|
|
||
| const SENTRY_ATTRIBUTES = { | ||
| 'sentry.release': { value: '1.0.0', type: 'string' }, | ||
| 'sentry.environment': { value: 'test', type: 'string' }, | ||
| 'sentry.sdk.name': { value: 'sentry.javascript.node', type: 'string' }, | ||
| 'sentry.sdk.version': { value: expect.any(String), type: 'string' }, | ||
| 'sentry.origin': { value: 'auto.bun.runtime_metrics', type: 'string' }, | ||
| }; | ||
|
|
||
| const gauge = (name: string, unit?: string) => ({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| name, | ||
| type: 'gauge', | ||
| ...(unit ? { unit } : {}), | ||
| value: expect.any(Number), | ||
| attributes: expect.objectContaining(SENTRY_ATTRIBUTES), | ||
| }); | ||
|
|
||
| const counter = (name: string, unit?: string) => ({ | ||
| timestamp: expect.any(Number), | ||
| trace_id: expect.any(String), | ||
| name, | ||
| type: 'counter', | ||
| ...(unit ? { unit } : {}), | ||
| value: expect.any(Number), | ||
| attributes: expect.objectContaining(SENTRY_ATTRIBUTES), | ||
| }); | ||
|
|
||
| describe('bunRuntimeMetricsIntegration', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('emits default runtime metrics with correct shape', async () => { | ||
| const runner = createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| trace_metric: { | ||
| items: expect.arrayContaining([ | ||
| gauge('bun.runtime.mem.rss', 'byte'), | ||
| gauge('bun.runtime.mem.heap_used', 'byte'), | ||
| gauge('bun.runtime.mem.heap_total', 'byte'), | ||
| gauge('bun.runtime.cpu.utilization'), | ||
| gauge('bun.runtime.event_loop.utilization'), | ||
| counter('bun.runtime.process.uptime', 'second'), | ||
| ]), | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
|
|
||
| test('does not emit opt-in metrics by default', async () => { | ||
| const runner = createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| trace_metric: (container: { items: Array<{ name: string }> }) => { | ||
| const names = container.items.map(item => item.name); | ||
| expect(names).not.toContain('bun.runtime.cpu.user'); | ||
| expect(names).not.toContain('bun.runtime.cpu.system'); | ||
| expect(names).not.toContain('bun.runtime.mem.external'); | ||
| expect(names).not.toContain('bun.runtime.mem.array_buffers'); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
|
|
||
| test('emits all metrics when fully opted in', async () => { | ||
| const runner = createRunner(__dirname, 'scenario-all.ts') | ||
| .expect({ | ||
| trace_metric: { | ||
| items: expect.arrayContaining([ | ||
| gauge('bun.runtime.mem.rss', 'byte'), | ||
| gauge('bun.runtime.mem.heap_used', 'byte'), | ||
| gauge('bun.runtime.mem.heap_total', 'byte'), | ||
| gauge('bun.runtime.mem.external', 'byte'), | ||
| gauge('bun.runtime.mem.array_buffers', 'byte'), | ||
| gauge('bun.runtime.cpu.user', 'second'), | ||
| gauge('bun.runtime.cpu.system', 'second'), | ||
| gauge('bun.runtime.cpu.utilization'), | ||
| gauge('bun.runtime.event_loop.utilization'), | ||
| counter('bun.runtime.process.uptime', 'second'), | ||
| ]), | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
|
|
||
| test('respects opt-out: only memory metrics remain when cpu/event loop/uptime are disabled', async () => { | ||
| const runner = createRunner(__dirname, 'scenario-opt-out.ts') | ||
| .expect({ | ||
| trace_metric: (container: { items: Array<{ name: string }> }) => { | ||
| const names = container.items.map(item => item.name); | ||
|
|
||
| // Memory metrics should still be present | ||
| expect(names).toContain('bun.runtime.mem.rss'); | ||
| expect(names).toContain('bun.runtime.mem.heap_used'); | ||
| expect(names).toContain('bun.runtime.mem.heap_total'); | ||
|
|
||
| // Everything else should be absent | ||
| expect(names).not.toContain('bun.runtime.cpu.utilization'); | ||
| expect(names).not.toContain('bun.runtime.event_loop.utilization'); | ||
| expect(names).not.toContain('bun.runtime.process.uptime'); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
| }); |
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.
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.
I added the note for node again bc this was somehow lost in the gitflow merge (?)