Skip to content

feat(browser): Set page context instead of using request interface #15912

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Event } from '@sentry/core';
import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';

sentryTest('httpContextIntegration captures user-agent and referrer', async ({ getLocalTestUrl, page }) => {
sentryTest('pageInformationIntegration captures user-agent and referrer', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
dedupeIntegration,
defaultStackParser,
functionToStringIntegration,
httpContextIntegration,
pageInformationIntegration,
eventFiltersIntegration,
linkedErrorsIntegration,
makeFetchTransport,
Expand All @@ -15,7 +15,7 @@ const integrations = [
breadcrumbsIntegration(),
functionToStringIntegration(),
dedupeIntegration(),
httpContextIntegration(),
pageInformationIntegration(),
eventFiltersIntegration(),
linkedErrorsIntegration(),
];
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
breadcrumbsIntegration,
browserSessionIntegration,
globalHandlersIntegration,
httpContextIntegration,
pageInformationIntegration,
init as browserInit,
linkedErrorsIntegration,
setContext,
Expand Down Expand Up @@ -41,7 +41,7 @@ export function getDefaultIntegrations(_options: BrowserOptions = {}): Integrati
globalHandlersIntegration(),
linkedErrorsIntegration(),
dedupeIntegration(),
httpContextIntegration(),
pageInformationIntegration(),
browserSessionIntegration(),
];
}
Expand Down
3 changes: 2 additions & 1 deletion packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export { getDefaultIntegrations, forceLoad, init, onLoad, showReportDialog } fro

export { breadcrumbsIntegration } from './integrations/breadcrumbs';
export { globalHandlersIntegration } from './integrations/globalhandlers';
export { httpContextIntegration } from './integrations/httpcontext';
// eslint-disable-next-line deprecation/deprecation
export { httpContextIntegration, pageInformationIntegration } from './integrations/pageinformation';
export { linkedErrorsIntegration } from './integrations/linkederrors';
export { browserApiErrorsIntegration } from './integrations/browserapierrors';

Expand Down
36 changes: 0 additions & 36 deletions packages/browser/src/integrations/httpcontext.ts

This file was deleted.

41 changes: 41 additions & 0 deletions packages/browser/src/integrations/pageinformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineIntegration, getLocationHref } from '@sentry/core';
import { WINDOW } from '../helpers';

/**
* Collects information about the current page and attaches it as context to the event.
*/
export const pageInformationIntegration = defineIntegration(() => {
return {
// TODO(v10): Update name to "PageInformation"
name: 'HttpContext',
preprocessEvent(event) {
// if none of the information we want exists, don't bother
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
return;
}

const href = getLocationHref();

// grab as much info as exists and add it to the event
const url = event.request?.url || href;
const request = {
...(url && { url }),
};
event.request = request;

event.contexts = event.contexts || {};
event.contexts.page = {
href: href || undefined,
referrer: WINDOW.document.referrer,
user_agent: WINDOW.navigator.userAgent,
};
},
};
});

/**
* Collects information about the current page and attaches it as context to the event.
*
* @deprecated This integration was renamed to `pageInformationIntegration`, which should be used instead.
*/
export const httpContextIntegration = pageInformationIntegration;
4 changes: 2 additions & 2 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { breadcrumbsIntegration } from './integrations/breadcrumbs';
import { browserApiErrorsIntegration } from './integrations/browserapierrors';
import { browserSessionIntegration } from './integrations/browsersession';
import { globalHandlersIntegration } from './integrations/globalhandlers';
import { httpContextIntegration } from './integrations/httpcontext';
import { pageInformationIntegration } from './integrations/pageinformation';
import { linkedErrorsIntegration } from './integrations/linkederrors';
import { defaultStackParser } from './stack-parsers';
import { makeFetchTransport } from './transports/fetch';
Expand All @@ -43,7 +43,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
globalHandlersIntegration(),
linkedErrorsIntegration(),
dedupeIntegration(),
httpContextIntegration(),
pageInformationIntegration(),
browserSessionIntegration(),
];
}
Expand Down
Loading