-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Move browserTracingIntegration
code to setup
hook
#16386
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [Sentry.browserTracingIntegration()], | ||
tracePropagationTargets: ['http://sentry-test-site.example'], | ||
tracesSampleRate: 1, | ||
autoSessionTracking: false, | ||
}); | ||
|
||
// fetch directly after init | ||
fetch('http://sentry-test-site.example/0'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect } from '@playwright/test'; | ||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { | ||
envelopeRequestParser, | ||
shouldSkipTracingTest, | ||
waitForTransactionRequestOnUrl, | ||
} from '../../../../utils/helpers'; | ||
|
||
sentryTest('should create spans for fetch requests called directly after init', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipTracingTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('http://sentry-test-site.example/*', route => route.fulfill({ body: 'ok' })); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const req = await waitForTransactionRequestOnUrl(page, url); | ||
const tracingEvent = envelopeRequestParser(req); | ||
|
||
const requestSpans = tracingEvent.spans?.filter(({ op }) => op === 'http.client'); | ||
|
||
expect(requestSpans).toHaveLength(1); | ||
|
||
expect(requestSpans![0]).toMatchObject({ | ||
description: 'GET http://sentry-test-site.example/0', | ||
parent_span_id: tracingEvent.contexts?.trace?.span_id, | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
start_timestamp: expect.any(Number), | ||
timestamp: expect.any(Number), | ||
trace_id: tracingEvent.contexts?.trace?.trace_id, | ||
data: { | ||
'http.method': 'GET', | ||
'http.url': 'http://sentry-test-site.example/0', | ||
url: 'http://sentry-test-site.example/0', | ||
'server.address': 'sentry-test-site.example', | ||
type: 'fetch', | ||
}, | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,12 @@ class MockIntegration implements Integration { | |
// Only for testing - tag to keep separate instances straight when testing deduplication | ||
public tag?: string; | ||
|
||
public setupOnce = vi.fn(() => {}); | ||
|
||
public constructor(name: string, tag?: string) { | ||
this.name = name; | ||
this.tag = tag; | ||
} | ||
|
||
public setupOnce(): void { | ||
// noop | ||
} | ||
} | ||
|
||
type TestCase = [ | ||
|
@@ -74,6 +72,31 @@ describe('getIntegrationsToSetup', () => { | |
}); | ||
expect(integrations.map(i => i.name)).toEqual(expected); | ||
}); | ||
|
||
test('it uses passed integration over default intergation', () => { | ||
const integrationDefault = new MockIntegration('ChaseSquirrels'); | ||
const integration1 = new MockIntegration('ChaseSquirrels'); | ||
|
||
const integrations = getIntegrationsToSetup({ | ||
defaultIntegrations: [integrationDefault], | ||
integrations: [integration1], | ||
}); | ||
|
||
expect(integrations).toEqual([integration1]); | ||
}); | ||
|
||
test('it uses last passed integration only', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah nice, I think this is good behaviour and probably better than taking first one. Just in case users have some kind of dynamic behaviour that builds the integrations array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jup, totally, that was what we had already anyhow 👍 the test just shows that! |
||
const integrationDefault = new MockIntegration('ChaseSquirrels'); | ||
const integration1 = new MockIntegration('ChaseSquirrels'); | ||
const integration2 = new MockIntegration('ChaseSquirrels'); | ||
|
||
const integrations = getIntegrationsToSetup({ | ||
defaultIntegrations: [integrationDefault], | ||
integrations: [integration1, integration2], | ||
}); | ||
|
||
expect(integrations).toEqual([integration2]); | ||
}); | ||
}); | ||
|
||
describe('deduping', () => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.