Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Jan 3, 2023
1 parent 6a2b90c commit f346e2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
29 changes: 12 additions & 17 deletions packages/browser/src/integrations/httpclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import { eventFromUnknownInput } from '../eventbuilder';
export type HttpStatusCodeRange = [number, number] | number;
export type HttpRequestTarget = string | RegExp;
interface HttpClientOptions {
/**
* Controls whether failed requests should be captured.
*
* Default: false
*/
captureFailedRequests?: boolean;

/**
* HTTP status codes that should be considered failed.
* This array can contain tuples of `[begin, end]` (both inclusive),
Expand Down Expand Up @@ -55,7 +48,6 @@ export class HttpClient implements Integration {
*/
public constructor(options?: Partial<HttpClientOptions>) {
this._options = {
captureFailedRequests: false,
failedRequestStatusCodes: [[500, 599]],
failedRequestTargets: [/.*/],
...options,
Expand All @@ -68,10 +60,6 @@ export class HttpClient implements Integration {
* @param options
*/
public setupOnce(): void {
if (!this._options.captureFailedRequests) {
return;
}

this._wrapFetch();
this._wrapXHR();
}
Expand Down Expand Up @@ -170,7 +158,6 @@ export class HttpClient implements Integration {
responseCookies,
});

// Note: Not adding request / response objects as hints for XHR
captureEvent(event);
}
}
Expand Down Expand Up @@ -284,7 +271,7 @@ export class HttpClient implements Integration {
}

/**
*
* Wraps `fetch` function to capture request and response data
*/
private _wrapFetch(): void {
if (!supportsNativeFetch()) {
Expand Down Expand Up @@ -314,7 +301,7 @@ export class HttpClient implements Integration {
}

/**
* Wraps XMLHttpRequest to capture request and response data
* Wraps XMLHttpRequest to capture request and response data
*/
private _wrapXHR(): void {
if (!('XMLHttpRequest' in GLOBAL_OBJ)) {
Expand Down Expand Up @@ -358,7 +345,9 @@ export class HttpClient implements Integration {
__DEBUG_BUILD__ && logger.warn('Error while extracting response event form XHR response', e);
}

return original?.apply(xhr, onloadendArgs);
if (original) {
return original.apply(xhr, onloadendArgs);
}
};
});

Expand All @@ -373,7 +362,13 @@ export class HttpClient implements Integration {
* @param url url to verify
*/
private _isSentryRequest(url: string): boolean {
const dsn = getCurrentHub().getClient()?.getDsn();
const client = getCurrentHub().getClient();

if (!client) {
return false;
}

const dsn = client.getDsn();
return dsn ? url.includes(dsn.host) : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [
new Sentry.Integrations.HttpClient({
captureFailedRequests: true,
}),
],
integrations: [new Sentry.Integrations.HttpClient()],
tracesSampleRate: 1,
sendDefaultPii: true,
});

0 comments on commit f346e2a

Please sign in to comment.