Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Apr 4, 2023
1 parent d8e5e66 commit 5f05517
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions packages/sveltekit/src/client/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch

const browserTracingIntegration =
client.getIntegrationById && (client.getIntegrationById('BrowserTracing') as BrowserTracing | undefined);
const breadcrumbsIntegration = client.getIntegrationById('Breadcrumbs') as Breadcrumbs | undefined;
const breadcrumbsIntegration =
client.getIntegrationById && (client.getIntegrationById('Breadcrumbs') as Breadcrumbs | undefined);

const browserTracingOptions = browserTracingIntegration && browserTracingIntegration.options;

Expand All @@ -133,22 +134,23 @@ function instrumentSvelteKitFetch(originalFetch: SvelteKitFetch): SvelteKitFetch
apply: (wrappingTarget, thisArg, args: Parameters<LoadEvent['fetch']>) => {
const [input, init] = args;
const { url: rawUrl, method } = parseFetchArgs(args);
const urlObject = parseUrl(rawUrl);

const requestData: SanitizedRequestData = {
url: getSanitizedUrlString(urlObject),
method,
'http.query': urlObject.search,
'http.fragment': urlObject.hash,
};

// TODO: extract this to a util function (and use it in breadcrumbs integration as well)
if (rawUrl.match(/sentry_key/)) {
// We don't create spans or breadcrumbs for fetch requests that contain `sentry_key` (internal sentry requests)
return wrappingTarget.apply(thisArg, args);
}

const patchedInit: RequestInit = { ...init } || {};
const urlObject = parseUrl(rawUrl);

const requestData: SanitizedRequestData = {
url: getSanitizedUrlString(urlObject),
method,
...(urlObject.search && { 'http.query': urlObject.search.substring(1) }),
...(urlObject.hash && { 'http.hash': urlObject.hash.substring(1) }),
};

const patchedInit: RequestInit = { ...init };
const activeSpan = getCurrentHub().getScope().getSpan();
const activeTransaction = activeSpan && activeSpan.transaction;

Expand Down
2 changes: 1 addition & 1 deletion packages/tracing-internal/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function addTracingHeadersToFetchRequest(
newHeaders.append('sentry-trace', sentryTraceHeader);

if (sentryBaggageHeader) {
// If the same header is appended miultiple times the browser will merge the values into a single request header.
// If the same header is appended multiple times the browser will merge the values into a single request header.
// Its therefore safe to simply push a "baggage" entry, even though there might already be another baggage header.
newHeaders.append(BAGGAGE_HEADER_NAME, sentryBaggageHeader);
}
Expand Down

0 comments on commit 5f05517

Please sign in to comment.