From a1f0050f8090969eedd3c1afdea1417155ae1df7 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Thu, 5 Jan 2023 14:30:03 +0000 Subject: [PATCH 1/3] Add docs for JavaScript HttpClient Integration. --- .../configuration/http-client/javascript.mdx | 54 +++++++++++++++++++ .../configuration/integrations/plugin.mdx | 22 +++++++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/platform-includes/configuration/http-client/javascript.mdx diff --git a/src/platform-includes/configuration/http-client/javascript.mdx b/src/platform-includes/configuration/http-client/javascript.mdx new file mode 100644 index 00000000000000..b78ea9a1c97f59 --- /dev/null +++ b/src/platform-includes/configuration/http-client/javascript.mdx @@ -0,0 +1,54 @@ +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/browser"; +import { HttpClient as HttpClientIntegration } from "@sentry/integrations"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [new HttpClientIntegration({ + // This array can contain tuples of `[begin, end]` (both inclusive), + // Single status codes, or a combinations of both. + // default: [[500, 599]] + failedRequestStatusCodes: [[500, 505], 507], + + // This array can contain Regexes or strings, or combinations of both. + // default: [/.*/] + failedRequestTargets: [/ab+c/, 'http://example.com/api/test'], + })], + // This is required for capturing headers and cookies. + // Without it, the `event.request` and `event.contexts.response` objects + // will not include `headers` and `cookies`. + sendDefaultPii: true, +}); +``` + +```javascript {tabTitle: CDN} + + + + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [new Sentry.Integrations.HttpClient({ + // This array can contain tuples of `[begin, end]` (both inclusive), + // Single status codes, or a combinations of both. + // default: [[500, 599]] + failedRequestStatusCodes: [[500, 505], 507], + + // This array can contain Regexes or strings, or combinations of both. + // default: [/.*/] + failedRequestTargets: [/ab+c/, 'http://example.com/api/test'], + })], + // This is required for capturing headers and cookies. + // Without it, the `event.request` and `event.contexts.response` objects + // will not include `headers` and `cookies`. + sendDefaultPii: true, +}); +``` diff --git a/src/platforms/javascript/common/configuration/integrations/plugin.mdx b/src/platforms/javascript/common/configuration/integrations/plugin.mdx index 36d388979e1603..8eba6705ff9220 100644 --- a/src/platforms/javascript/common/configuration/integrations/plugin.mdx +++ b/src/platforms/javascript/common/configuration/integrations/plugin.mdx @@ -1,6 +1,6 @@ --- title: Pluggable Integrations -description: "Learn more about pluggable integrations ExtraErrorData, CaptureConsole, Debug, Offline, RewriteFrames, and ReportingObserver, which are snippets of code that augment functionality for specific applications and/or frameworks." +description: "Learn more about pluggable integrations ExtraErrorData, CaptureConsole, Debug, HttpClient, Offline, RewriteFrames, and ReportingObserver, which are snippets of code that augment functionality for specific applications and/or frameworks." redirect_from: - /platforms/javascript/integrations/plugin/ - /platforms/javascript/pluggable-integrations/ @@ -50,6 +50,26 @@ Available options: +### HttpClient + +_(New in version 7.30.0)_ + +_Import name: `Sentry.Integrations.HttpClient`_ + +This integration intercepts Fetch API and XHR requests to get the response / request information, and captures events if there is a failed request according to the user's configuration. + +By default, error events won't contain any PII data, such as Headers and Cookies, but you can change this behavior by setting the `sendDefaultPii` option to `true`. + +Available options: + + + + + +Due to the limitations of both Fetch API and XHR, the cookie and header collection for both requests and responses is the best effort. Certain headers may be missing here in the integration-created event, even if they exist in the original request / response. + + + ### Offline From 27d83e14f33cef275d88ca1d55dd9483865edd48 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 5 Jan 2023 16:53:22 +0100 Subject: [PATCH 2/3] Minor formatting and wording changes --- .../configuration/http-client/javascript.mdx | 60 +++++++++++-------- .../configuration/integrations/plugin.mdx | 6 +- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/platform-includes/configuration/http-client/javascript.mdx b/src/platform-includes/configuration/http-client/javascript.mdx index b78ea9a1c97f59..df1741e5a6c10b 100644 --- a/src/platform-includes/configuration/http-client/javascript.mdx +++ b/src/platform-includes/configuration/http-client/javascript.mdx @@ -4,19 +4,23 @@ import { HttpClient as HttpClientIntegration } from "@sentry/integrations"; Sentry.init({ dsn: "___PUBLIC_DSN___", - integrations: [new HttpClientIntegration({ - // This array can contain tuples of `[begin, end]` (both inclusive), - // Single status codes, or a combinations of both. - // default: [[500, 599]] - failedRequestStatusCodes: [[500, 505], 507], - - // This array can contain Regexes or strings, or combinations of both. - // default: [/.*/] - failedRequestTargets: [/ab+c/, 'http://example.com/api/test'], - })], - // This is required for capturing headers and cookies. - // Without it, the `event.request` and `event.contexts.response` objects - // will not include `headers` and `cookies`. + integrations: [ + new HttpClientIntegration({ + // This array can contain tuples of `[begin, end]` (both inclusive), + // single status codes, or a combination of both. + // default: [[500, 599]] + failedRequestStatusCodes: [[500, 505], 507], + + // This array can contain Regexes, strings, or a combination of both. + // default: [/.*/] + failedRequestTargets: [ + "http://example.com/api/test", + /(staging\.)?mypage\.com/, + ], + }), + ], + + // This option is required for capturing headers and cookies. sendDefaultPii: true, }); ``` @@ -36,19 +40,23 @@ Sentry.init({ Sentry.init({ dsn: "___PUBLIC_DSN___", - integrations: [new Sentry.Integrations.HttpClient({ - // This array can contain tuples of `[begin, end]` (both inclusive), - // Single status codes, or a combinations of both. - // default: [[500, 599]] - failedRequestStatusCodes: [[500, 505], 507], - - // This array can contain Regexes or strings, or combinations of both. - // default: [/.*/] - failedRequestTargets: [/ab+c/, 'http://example.com/api/test'], - })], - // This is required for capturing headers and cookies. - // Without it, the `event.request` and `event.contexts.response` objects - // will not include `headers` and `cookies`. + integrations: [ + new HttpClientIntegration({ + // This array can contain tuples of `[begin, end]` (both inclusive), + // single status codes, or a combination of both. + // default: [[500, 599]] + failedRequestStatusCodes: [[500, 505], 507], + + // This array can contain Regexes, strings, or a combination of both. + // default: [/.*/] + failedRequestTargets: [ + "http://example.com/api/test", + /(staging\.)?mypage\.com/, + ], + }), + ], + + // This option is required for capturing headers and cookies. sendDefaultPii: true, }); ``` diff --git a/src/platforms/javascript/common/configuration/integrations/plugin.mdx b/src/platforms/javascript/common/configuration/integrations/plugin.mdx index 8eba6705ff9220..c7c6b2a3b0acde 100644 --- a/src/platforms/javascript/common/configuration/integrations/plugin.mdx +++ b/src/platforms/javascript/common/configuration/integrations/plugin.mdx @@ -56,9 +56,9 @@ _(New in version 7.30.0)_ _Import name: `Sentry.Integrations.HttpClient`_ -This integration intercepts Fetch API and XHR requests to get the response / request information, and captures events if there is a failed request according to the user's configuration. +This integration and captures errors on failed requests from Fetch and XHR requests and attaches request and response information. -By default, error events won't contain any PII data, such as Headers and Cookies, but you can change this behavior by setting the `sendDefaultPii` option to `true`. +By default, error events will not contain header and cookie data. You can change this behavior by setting the `sendDefaultPii` option to `true`. Available options: @@ -66,7 +66,7 @@ Available options: -Due to the limitations of both Fetch API and XHR, the cookie and header collection for both requests and responses is the best effort. Certain headers may be missing here in the integration-created event, even if they exist in the original request / response. +Due to the limitations of both the Fetch and XHR API, the cookie and header collection for both requests and responses is based on best effort. Certain headers may be missing in the event created by the integration. From dc08732e598aa747de0a900345ab14dfe654eff9 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Fri, 6 Jan 2023 13:44:43 +0000 Subject: [PATCH 3/3] Update src/platforms/javascript/common/configuration/integrations/plugin.mdx Co-authored-by: Liza Mock --- .../javascript/common/configuration/integrations/plugin.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/javascript/common/configuration/integrations/plugin.mdx b/src/platforms/javascript/common/configuration/integrations/plugin.mdx index c7c6b2a3b0acde..673ea771cab397 100644 --- a/src/platforms/javascript/common/configuration/integrations/plugin.mdx +++ b/src/platforms/javascript/common/configuration/integrations/plugin.mdx @@ -56,7 +56,7 @@ _(New in version 7.30.0)_ _Import name: `Sentry.Integrations.HttpClient`_ -This integration and captures errors on failed requests from Fetch and XHR requests and attaches request and response information. +This integration captures errors on failed requests from Fetch and XHR and attaches request and response information. By default, error events will not contain header and cookie data. You can change this behavior by setting the `sendDefaultPii` option to `true`.