-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(integrations): Export pluggable integrations directly #8842
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [new Sentry.Integrations.ExtraErrorData()], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const error = new TypeError('foo'); | ||
error.baz = 42; | ||
error.foo = 'bar'; | ||
|
||
Sentry.captureException(error); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body></body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../utils/helpers'; | ||
|
||
sentryTest('allows to use pluggable integrations from @sentry/browser', async ({ getLocalTestUrl, page }) => { | ||
const bundle = process.env.PW_BUNDLE; | ||
|
||
// Only run this for import-based tests, not CDN bundles/loader | ||
if (bundle && bundle.startsWith('bundle_')) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const req = await waitForErrorRequestOnUrl(page, url); | ||
|
||
const eventData = envelopeRequestParser(req); | ||
|
||
expect(eventData).toEqual( | ||
expect.objectContaining({ | ||
contexts: expect.objectContaining({ | ||
TypeError: { | ||
baz: 42, | ||
foo: 'bar', | ||
}, | ||
}), | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'TypeError', | ||
value: 'foo', | ||
mechanism: { | ||
type: 'generic', | ||
handled: true, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}, | ||
], | ||
}, | ||
}), | ||
); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from './exports'; | ||
|
||
import { Integrations as CoreIntegrations } from '@sentry/core'; | ||
import * as PluggableIntegrations from '@sentry/integrations'; | ||
|
||
import { WINDOW } from './helpers'; | ||
import * as BrowserIntegrations from './integrations'; | ||
|
@@ -16,6 +17,7 @@ const INTEGRATIONS = { | |
...windowIntegrations, | ||
...CoreIntegrations, | ||
...BrowserIntegrations, | ||
...PluggableIntegrations, | ||
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. h: This will not tree-shake as soon as people import We need to do the same here - exporting the pluggable integrations top level. 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. right, that makes sense of course... I wonder actually if we should then completely get rid of the
IMHO it would be a bit weird to have the default integrations be available under 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. In the next major we should remove the Integrations object for sure. I agree having them in separate places is weird. I think we could export everything top level. 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. |
||
}; | ||
|
||
export { INTEGRATIONS as Integrations }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ | |
"tslib": "^2.4.1 || ^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@sentry/browser": "7.64.0", | ||
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. This would have been a circular dependency, so got rid of this (similar to what we had to do for replay) |
||
"chai": "^4.1.2" | ||
}, | ||
"scripts": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
integrations: [new Sentry.Integrations.ExtraErrorData({})], | ||
}); | ||
|
||
const error = new TypeError('foo') as Error & { baz: number; foo: string }; | ||
error.baz = 42; | ||
error.foo = 'bar'; | ||
|
||
Sentry.captureException(error); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { assertSentryEvent, TestEnv } from '../../../utils'; | ||
|
||
test('allows to use pluggable integrations from @sentry/node export', async () => { | ||
const env = await TestEnv.init(__dirname); | ||
const event = await env.getEnvelopeRequest(); | ||
|
||
assertSentryEvent(event[2], { | ||
contexts: expect.objectContaining({ | ||
TypeError: { | ||
baz: 42, | ||
foo: 'bar', | ||
}, | ||
}), | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'TypeError', | ||
value: 'foo', | ||
mechanism: { | ||
type: 'generic', | ||
handled: true, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); |
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.
Without this change, this fails for all tests as the build output of webpack includes the import from
@sentry/integrations
by default and tries to "fix" it in there, but it also does not contain animported
field so it just fails.