-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Rethrow caught promise rejections in startSpan
, startSpanManual
, trace
#9958
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 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4c1e8b6
fix(core): Rethrow caught promise rejections in `startSpan`, `startSp…
Lms24 d811008
add tests but they no work :(
Lms24 92d9003
fix integration tests
Lms24 2b13a8a
create test that actually failed previously
Lms24 52b83d3
fix other trace functions
Lms24 c8d2839
lint
Lms24 c474988
dsn
Lms24 ffea627
cleanup tests
Lms24 3f70311
fix (biome) and cleanup tests
Lms24 66c8e14
remove console logs
Lms24 6066d1a
biome bs
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
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/public-api/startSpan/basic/subject.js
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,9 @@ | ||
async function run() { | ||
Sentry.startSpan({ name: 'parent_span' }, () => { | ||
Sentry.startSpan({ name: 'child_span' }, () => { | ||
// whatever a user would do here | ||
}); | ||
}); | ||
} | ||
|
||
run(); |
34 changes: 34 additions & 0 deletions
34
packages/browser-integration-tests/suites/public-api/startSpan/basic/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,34 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should send a transaction in an envelope', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(transaction.transaction).toBe('parent_span'); | ||
expect(transaction.spans).toBeDefined(); | ||
}); | ||
|
||
sentryTest('should report finished spans as children of the root transaction', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
const rootSpanId = transaction?.contexts?.trace?.spanId; | ||
|
||
expect(transaction.spans).toHaveLength(1); | ||
|
||
const span_1 = transaction.spans?.[0]; | ||
expect(span_1?.description).toBe('child_span'); | ||
expect(span_1?.parentSpanId).toEqual(rootSpanId); | ||
}); |
23 changes: 23 additions & 0 deletions
23
...es/browser-integration-tests/suites/public-api/startSpan/error-async-reject/template.html
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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<button id="button1" type="button">Button 1</button> | ||
|
||
<script> | ||
async function run() { | ||
await Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => { | ||
Promise.reject('Async Promise Rejection'); | ||
}); | ||
} | ||
|
||
const button = document.getElementById('button1'); | ||
button.addEventListener('click', async () => { | ||
await run(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
30 changes: 30 additions & 0 deletions
30
packages/browser-integration-tests/suites/public-api/startSpan/error-async-reject/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,30 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should capture a promise rejection within an async startSpan callback', | ||
async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2); | ||
|
||
await page.goto(url); | ||
|
||
const clickPromise = page.getByText('Button 1').click(); | ||
|
||
const [, events] = await Promise.all([clickPromise, envelopePromise]); | ||
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]]; | ||
|
||
expect(txn).toMatchObject({ transaction: 'parent_span' }); | ||
|
||
expect(err?.exception?.values?.[0]?.value).toBe( | ||
'Non-Error promise rejection captured with value: Async Promise Rejection', | ||
); | ||
}, | ||
); |
25 changes: 25 additions & 0 deletions
25
.../browser-integration-tests/suites/public-api/startSpan/error-async-throw-ii/template.html
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
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,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<button id="button1" type="button">Button 1</button> | ||
|
||
<script type="module"> | ||
async function run() { | ||
Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => { | ||
console.log('throwing error') | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error('Async Thrown Error'); | ||
}); | ||
} | ||
|
||
const button = document.getElementById('button1'); | ||
button.addEventListener('click', () => { | ||
void run(); | ||
console.log('click'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
packages/browser-integration-tests/suites/public-api/startSpan/error-async-throw-ii/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,27 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
"should capture a thrown error within an async startSpan callback that's not awaited properly", | ||
async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const clickPromise = page.getByText('Button 1').click(); | ||
|
||
// awaiting both events simultaneously to avoid race conditions | ||
const [, events] = await Promise.all([clickPromise, envelopePromise]); | ||
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]]; | ||
|
||
expect(txn).toMatchObject({ transaction: 'parent_span' }); | ||
expect(err?.exception?.values?.[0]?.value).toBe('Async Thrown Error'); | ||
}, | ||
); |
26 changes: 26 additions & 0 deletions
26
...ges/browser-integration-tests/suites/public-api/startSpan/error-async-throw/template.html
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,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<button id="button1" type="button">Button 1</button> | ||
|
||
<script type="module"> | ||
async function run() { | ||
await Promise.resolve(); | ||
await Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => { | ||
console.log('throwing error') | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error('Async Thrown Error'); | ||
}); | ||
} | ||
|
||
const button = document.getElementById('button1'); | ||
button.addEventListener('click', () => { | ||
void run(); | ||
console.log('click'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
24 changes: 24 additions & 0 deletions
24
packages/browser-integration-tests/suites/public-api/startSpan/error-async-throw/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,24 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should capture a thrown error within an async startSpan callback', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
const clickPromise = page.getByText('Button 1').click(); | ||
|
||
// awaiting both events simultaneously to avoid race conditions | ||
const [, events] = await Promise.all([clickPromise, envelopePromise]); | ||
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]]; | ||
|
||
expect(txn).toMatchObject({ transaction: 'parent_span' }); | ||
expect(err?.exception?.values?.[0]?.value).toBe('Async Thrown Error'); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/browser-integration-tests/suites/public-api/startSpan/error-sync/subject.js
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,9 @@ | ||
function run() { | ||
Sentry.startSpan({ name: 'parent_span' }, () => { | ||
throw new Error('Sync Error'); | ||
}); | ||
} | ||
|
||
// using `setTimeout` here because otherwise the thrown error will be | ||
// thrown as a generic "Script Error." instead of the actual error". | ||
setTimeout(run); |
22 changes: 22 additions & 0 deletions
22
packages/browser-integration-tests/suites/public-api/startSpan/error-sync/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,22 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should capture an error within a sync startSpan callback', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const gotoPromise = page.goto(url); | ||
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2); | ||
|
||
const [_, events] = await Promise.all([gotoPromise, envelopePromise]); | ||
|
||
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]]; | ||
|
||
expect(txn).toMatchObject({ transaction: 'parent_span' }); | ||
expect(err?.exception?.values?.[0]?.value).toBe('Sync Error'); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/browser-integration-tests/suites/public-api/startSpan/init.js
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,10 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
// eslint-disable-next-line no-unused-vars | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
tracesSampleRate: 1.0, | ||
normalizeDepth: 10, | ||
}); |
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
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.