-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(core): Add isolateTrace option to Sentry.withMonitor()
#18079
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
12 commits
Select commit
Hold shift + click to select a range
2b4f7c1
feat(core): Add isolateTrace option to MonitorConfig
naaa760 382fdc6
feat(core): Implement isolateTrace in withMonitor function
naaa760 4dfa0af
test(core): Add tests for isolateTrace functionality
naaa760 e06ae30
feat: Update isolateTrace implementation to use startNewTrace
naaa760 a16ae77
test: Add integration test for isolateTrace functionality
naaa760 50d5386
test: Fix withMonitor integration test to use proper test runner
naaa760 4215d49
fix: Add newline at end of scenario file
naaa760 7d10a53
test: Remove comments from withMonitor scenario file
naaa760 b9b6ba7
Merge branch 'develop' into feat/monitor-trace
naaa760 ad7c159
ensure initial checkin and terminal checkin have same trace
Lms24 b12304b
formatting and linting
Lms24 4551a8e
fix unit tests, fix integration tests
Lms24 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
43 changes: 43 additions & 0 deletions
43
dev-packages/node-integration-tests/suites/public-api/withMonitor/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,43 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| transport: loggingTransport, | ||
| }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.withMonitor( | ||
| 'cron-job-1', | ||
| async () => { | ||
| await new Promise<void>(resolve => { | ||
| setTimeout(() => { | ||
| resolve(); | ||
| }, 100); | ||
| }); | ||
| }, | ||
| { | ||
| schedule: { type: 'crontab', value: '* * * * *' }, | ||
| }, | ||
| ); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.withMonitor( | ||
| 'cron-job-2', | ||
| async () => { | ||
| await new Promise<void>(resolve => { | ||
| setTimeout(() => { | ||
| resolve(); | ||
| }, 100); | ||
| }); | ||
| }, | ||
| { | ||
| schedule: { type: 'crontab', value: '* * * * *' }, | ||
| isolateTrace: true, | ||
| }, | ||
| ); | ||
|
|
||
| setTimeout(() => { | ||
| process.exit(); | ||
| }, 500); |
54 changes: 54 additions & 0 deletions
54
dev-packages/node-integration-tests/suites/public-api/withMonitor/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,54 @@ | ||
| import type { SerializedCheckIn } from '@sentry/core'; | ||
| import { afterAll, describe, expect, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
|
||
| describe('withMonitor isolateTrace', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('creates distinct traces when isolateTrace is enabled', async () => { | ||
| const checkIns: SerializedCheckIn[] = []; | ||
|
|
||
| await createRunner(__dirname, 'scenario.ts') | ||
| .expect({ | ||
| check_in: checkIn => { | ||
| checkIns.push(checkIn); | ||
| }, | ||
| }) | ||
| .expect({ | ||
| check_in: checkIn => { | ||
| checkIns.push(checkIn); | ||
| }, | ||
| }) | ||
| .expect({ | ||
| check_in: checkIn => { | ||
| checkIns.push(checkIn); | ||
| }, | ||
| }) | ||
| .expect({ | ||
| check_in: checkIn => { | ||
| checkIns.push(checkIn); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
|
|
||
| const checkIn1InProgress = checkIns.find(c => c.monitor_slug === 'cron-job-1' && c.status === 'in_progress'); | ||
| const checkIn1Ok = checkIns.find(c => c.monitor_slug === 'cron-job-1' && c.status === 'ok'); | ||
|
|
||
| const checkIn2InProgress = checkIns.find(c => c.monitor_slug === 'cron-job-2' && c.status === 'in_progress'); | ||
| const checkIn2Ok = checkIns.find(c => c.monitor_slug === 'cron-job-2' && c.status === 'ok'); | ||
|
|
||
| expect(checkIn1InProgress?.contexts?.trace?.trace_id).toMatch(/[a-f\d]{32}/); | ||
| expect(checkIn1Ok?.contexts?.trace?.trace_id).toMatch(/[a-f\d]{32}/); | ||
| expect(checkIn2InProgress?.contexts?.trace?.trace_id).toMatch(/[a-f\d]{32}/); | ||
| expect(checkIn2Ok?.contexts?.trace?.trace_id).toMatch(/[a-f\d]{32}/); | ||
|
|
||
| expect(checkIn1InProgress!.contexts?.trace?.trace_id).not.toBe(checkIn2InProgress!.contexts?.trace?.trace_id); | ||
| expect(checkIn1Ok!.contexts?.trace?.span_id).not.toBe(checkIn2Ok!.contexts?.trace?.span_id); | ||
|
|
||
| expect(checkIn1Ok!.contexts?.trace?.trace_id).toBe(checkIn1InProgress!.contexts?.trace?.trace_id); | ||
| expect(checkIn2Ok!.contexts?.trace?.trace_id).toBe(checkIn2InProgress!.contexts?.trace?.trace_id); | ||
| }); | ||
| }); |
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.
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'm afraid this is not gonna work because it doesn't use our test runner at all. Did you test this?
I suggest taking a look at a test like this one and using the same runner, just that you assert on two transactions and check for distinct trace ids.