-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundles): Add pluggable integrations on CDN to
Sentry
namespace (
#10452) Previously, they were only put on `Sentry.Integrations.XXX`, now you can do e.g. `Sentry.httpClientIntegration()`. While at it, I also added a browser integration test for this. I also made the way we do this more future proof, as in v8 this will not be imported anymore from `@sentry/integrations` (which we rely on right now), plus the heuristic used to rely on integration name === filename. Now, there is a manual map of imported method names to a CDN bundle file name.
- Loading branch information
1 parent
4c6b638
commit 9317f85
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...es/browser-integration-tests/suites/integrations/httpclient/httpClientIntegration/init.js
This file contains 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,11 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import { httpClientIntegration } from '@sentry/integrations'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [httpClientIntegration()], | ||
tracesSampleRate: 1, | ||
sendDefaultPii: true, | ||
}); |
8 changes: 8 additions & 0 deletions
8
...browser-integration-tests/suites/integrations/httpclient/httpClientIntegration/subject.js
This file contains 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,8 @@ | ||
const xhr = new XMLHttpRequest(); | ||
|
||
xhr.open('GET', 'http://localhost:7654/foo', true); | ||
xhr.withCredentials = true; | ||
xhr.setRequestHeader('Accept', 'application/json'); | ||
xhr.setRequestHeader('Content-Type', 'application/json'); | ||
xhr.setRequestHeader('Cache', 'no-cache'); | ||
xhr.send(); |
64 changes: 64 additions & 0 deletions
64
...es/browser-integration-tests/suites/integrations/httpclient/httpClientIntegration/test.ts
This file contains 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,64 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers'; | ||
|
||
sentryTest('works with httpClientIntegration', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.route('**/foo', route => { | ||
return route.fulfill({ | ||
status: 500, | ||
body: JSON.stringify({ | ||
error: { | ||
message: 'Internal Server Error', | ||
}, | ||
}), | ||
headers: { | ||
'Content-Type': 'text/html', | ||
}, | ||
}); | ||
}); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
|
||
// Not able to get the cookies from the request/response because of Playwright bug | ||
// https://github.com/microsoft/playwright/issues/11035 | ||
expect(eventData).toMatchObject({ | ||
message: 'HTTP Client Error with status code: 500', | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'HTTP Client Error with status code: 500', | ||
mechanism: { | ||
type: 'http.client', | ||
handled: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
request: { | ||
url: 'http://localhost:7654/foo', | ||
method: 'GET', | ||
headers: { | ||
accept: 'application/json', | ||
cache: 'no-cache', | ||
'content-type': 'application/json', | ||
}, | ||
}, | ||
contexts: { | ||
response: { | ||
status_code: 500, | ||
body_size: 45, | ||
headers: { | ||
'content-type': 'text/html', | ||
'content-length': '45', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); |
This file contains 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 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