@sentry/browser
Advanced tools
Comparing version
@@ -158,3 +158,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/** | ||
* Get HTTP request data from the current page. | ||
*/ | ||
function getHttpRequestData() { | ||
// grab as much info as exists and add it to the event | ||
const url = core.getLocationHref(); | ||
const { referrer } = WINDOW.document || {}; | ||
const { userAgent } = WINDOW.navigator || {}; | ||
const headers = { | ||
...(referrer && { Referer: referrer }), | ||
...(userAgent && { 'User-Agent': userAgent }), | ||
}; | ||
const request = { | ||
url, | ||
headers, | ||
}; | ||
return request; | ||
} | ||
exports.WINDOW = WINDOW; | ||
exports.getHttpRequestData = getHttpRequestData; | ||
exports.ignoreNextOnError = ignoreNextOnError; | ||
@@ -161,0 +183,0 @@ exports.shouldIgnoreOnError = shouldIgnoreOnError; |
@@ -19,19 +19,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
// grab as much info as exists and add it to the event | ||
const url = event.request?.url || core.getLocationHref(); | ||
const { referrer } = helpers.WINDOW.document || {}; | ||
const { userAgent } = helpers.WINDOW.navigator || {}; | ||
const reqData = helpers.getHttpRequestData(); | ||
const headers = { | ||
...reqData.headers, | ||
...event.request?.headers, | ||
...(referrer && { Referer: referrer }), | ||
...(userAgent && { 'User-Agent': userAgent }), | ||
}; | ||
const request = { | ||
event.request = { | ||
...reqData, | ||
...event.request, | ||
...(url && { url }), | ||
headers, | ||
}; | ||
event.request = request; | ||
}, | ||
@@ -38,0 +32,0 @@ }; |
@@ -194,4 +194,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
core.getIsolationScope().setPropagationContext({ traceId: core.generateTraceId(), sampleRand: Math.random() }); | ||
core.getCurrentScope().setPropagationContext({ traceId: core.generateTraceId(), sampleRand: Math.random() }); | ||
const scope = core.getCurrentScope(); | ||
scope.setPropagationContext({ traceId: core.generateTraceId(), sampleRand: Math.random() }); | ||
// We reset this to ensure we do not have lingering incorrect data here | ||
// places that call this hook may set this where appropriate - else, the URL at span sending time is used | ||
scope.setSDKProcessingMetadata({ | ||
normalizedRequest: undefined, | ||
}); | ||
_createRouteSpan(client, { | ||
@@ -213,4 +220,12 @@ op: 'navigation', | ||
const propagationContext = core.propagationContextFromHeaders(sentryTrace, baggage); | ||
core.getCurrentScope().setPropagationContext(propagationContext); | ||
const scope = core.getCurrentScope(); | ||
scope.setPropagationContext(propagationContext); | ||
// We store the normalized request data on the scope, so we get the request data at time of span creation | ||
// otherwise, the URL etc. may already be of the following navigation, and we'd report the wrong URL | ||
scope.setSDKProcessingMetadata({ | ||
normalizedRequest: helpers.getHttpRequestData(), | ||
}); | ||
_createRouteSpan(client, { | ||
@@ -256,12 +271,21 @@ op: 'pageload', | ||
if (from !== to) { | ||
startingUrl = undefined; | ||
startBrowserTracingNavigationSpan(client, { | ||
name: helpers.WINDOW.location.pathname, | ||
attributes: { | ||
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser', | ||
}, | ||
}); | ||
} | ||
startingUrl = undefined; | ||
const parsed = core.parseStringToURLObject(to); | ||
startBrowserTracingNavigationSpan(client, { | ||
name: parsed?.pathname || helpers.WINDOW.location.pathname, | ||
attributes: { | ||
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser', | ||
}, | ||
}); | ||
// We store the normalized request data on the scope, so we get the request data at time of span creation | ||
// otherwise, the URL etc. may already be of the following navigation, and we'd report the wrong URL | ||
core.getCurrentScope().setSDKProcessingMetadata({ | ||
normalizedRequest: { | ||
...helpers.getHttpRequestData(), | ||
// Ensure to set this, so this matches the target route even if the URL has not yet been updated | ||
url: to, | ||
}, | ||
}); | ||
}); | ||
@@ -268,0 +292,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { GLOBAL_OBJ, getOriginalFunction, markFunctionWrapped, addNonEnumerableProperty, withScope, addExceptionTypeValue, addExceptionMechanism, captureException } from '@sentry/core'; | ||
import { GLOBAL_OBJ, getOriginalFunction, markFunctionWrapped, addNonEnumerableProperty, withScope, addExceptionTypeValue, addExceptionMechanism, captureException, getLocationHref } from '@sentry/core'; | ||
@@ -156,3 +156,24 @@ const WINDOW = GLOBAL_OBJ ; | ||
export { WINDOW, ignoreNextOnError, shouldIgnoreOnError, wrap }; | ||
/** | ||
* Get HTTP request data from the current page. | ||
*/ | ||
function getHttpRequestData() { | ||
// grab as much info as exists and add it to the event | ||
const url = getLocationHref(); | ||
const { referrer } = WINDOW.document || {}; | ||
const { userAgent } = WINDOW.navigator || {}; | ||
const headers = { | ||
...(referrer && { Referer: referrer }), | ||
...(userAgent && { 'User-Agent': userAgent }), | ||
}; | ||
const request = { | ||
url, | ||
headers, | ||
}; | ||
return request; | ||
} | ||
export { WINDOW, getHttpRequestData, ignoreNextOnError, shouldIgnoreOnError, wrap }; | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,3 +0,3 @@ | ||
import { defineIntegration, getLocationHref } from '@sentry/core'; | ||
import { WINDOW } from '../helpers.js'; | ||
import { defineIntegration } from '@sentry/core'; | ||
import { WINDOW, getHttpRequestData } from '../helpers.js'; | ||
@@ -17,19 +17,13 @@ /** | ||
// grab as much info as exists and add it to the event | ||
const url = event.request?.url || getLocationHref(); | ||
const { referrer } = WINDOW.document || {}; | ||
const { userAgent } = WINDOW.navigator || {}; | ||
const reqData = getHttpRequestData(); | ||
const headers = { | ||
...reqData.headers, | ||
...event.request?.headers, | ||
...(referrer && { Referer: referrer }), | ||
...(userAgent && { 'User-Agent': userAgent }), | ||
}; | ||
const request = { | ||
event.request = { | ||
...reqData, | ||
...event.request, | ||
...(url && { url }), | ||
headers, | ||
}; | ||
event.request = request; | ||
}, | ||
@@ -36,0 +30,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
{"type":"module","version":"9.19.0","sideEffects":false} | ||
{"type":"module","version":"9.20.0","sideEffects":false} |
@@ -1,5 +0,5 @@ | ||
import { TRACING_DEFAULTS, registerSpanErrorInstrumentation, GLOBAL_OBJ, getLocationHref, getClient, getIsolationScope, generateTraceId, getCurrentScope, propagationContextFromHeaders, browserPerformanceTimeOrigin, spanToJSON, logger, SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, startIdleSpan, getDynamicSamplingContextFromSpan, spanIsSampled, addNonEnumerableProperty, consoleSandbox, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; | ||
import { TRACING_DEFAULTS, registerSpanErrorInstrumentation, GLOBAL_OBJ, getLocationHref, getClient, getIsolationScope, generateTraceId, getCurrentScope, propagationContextFromHeaders, browserPerformanceTimeOrigin, parseStringToURLObject, spanToJSON, logger, SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, startIdleSpan, getDynamicSamplingContextFromSpan, spanIsSampled, addNonEnumerableProperty, consoleSandbox, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; | ||
import { startTrackingWebVitals, startTrackingINP, startTrackingLongAnimationFrames, startTrackingLongTasks, startTrackingInteractions, addHistoryInstrumentationHandler, registerInpInteractionListener, addPerformanceEntries } from '@sentry-internal/browser-utils'; | ||
import { DEBUG_BUILD } from '../debug-build.js'; | ||
import { WINDOW } from '../helpers.js'; | ||
import { WINDOW, getHttpRequestData } from '../helpers.js'; | ||
import { registerBackgroundTabDetection } from './backgroundtab.js'; | ||
@@ -192,4 +192,11 @@ import { linkTraces } from './linkedTraces.js'; | ||
getIsolationScope().setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() }); | ||
getCurrentScope().setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() }); | ||
const scope = getCurrentScope(); | ||
scope.setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() }); | ||
// We reset this to ensure we do not have lingering incorrect data here | ||
// places that call this hook may set this where appropriate - else, the URL at span sending time is used | ||
scope.setSDKProcessingMetadata({ | ||
normalizedRequest: undefined, | ||
}); | ||
_createRouteSpan(client, { | ||
@@ -211,4 +218,12 @@ op: 'navigation', | ||
const propagationContext = propagationContextFromHeaders(sentryTrace, baggage); | ||
getCurrentScope().setPropagationContext(propagationContext); | ||
const scope = getCurrentScope(); | ||
scope.setPropagationContext(propagationContext); | ||
// We store the normalized request data on the scope, so we get the request data at time of span creation | ||
// otherwise, the URL etc. may already be of the following navigation, and we'd report the wrong URL | ||
scope.setSDKProcessingMetadata({ | ||
normalizedRequest: getHttpRequestData(), | ||
}); | ||
_createRouteSpan(client, { | ||
@@ -254,12 +269,21 @@ op: 'pageload', | ||
if (from !== to) { | ||
startingUrl = undefined; | ||
startBrowserTracingNavigationSpan(client, { | ||
name: WINDOW.location.pathname, | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser', | ||
}, | ||
}); | ||
} | ||
startingUrl = undefined; | ||
const parsed = parseStringToURLObject(to); | ||
startBrowserTracingNavigationSpan(client, { | ||
name: parsed?.pathname || WINDOW.location.pathname, | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser', | ||
}, | ||
}); | ||
// We store the normalized request data on the scope, so we get the request data at time of span creation | ||
// otherwise, the URL etc. may already be of the following navigation, and we'd report the wrong URL | ||
getCurrentScope().setSDKProcessingMetadata({ | ||
normalizedRequest: { | ||
...getHttpRequestData(), | ||
// Ensure to set this, so this matches the target route even if the URL has not yet been updated | ||
url: to, | ||
}, | ||
}); | ||
}); | ||
@@ -266,0 +290,0 @@ } |
@@ -44,3 +44,10 @@ import { Mechanism, WrappedFunction } from '@sentry/core'; | ||
}): NonFunction; | ||
/** | ||
* Get HTTP request data from the current page. | ||
*/ | ||
export declare function getHttpRequestData(): { | ||
url: string; | ||
headers: Record<string, string>; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=helpers.d.ts.map |
@@ -44,3 +44,10 @@ import type { Mechanism, WrappedFunction } from '@sentry/core'; | ||
}): NonFunction; | ||
/** | ||
* Get HTTP request data from the current page. | ||
*/ | ||
export declare function getHttpRequestData(): { | ||
url: string; | ||
headers: Record<string, string>; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=helpers.d.ts.map |
{ | ||
"name": "@sentry/browser", | ||
"version": "9.19.0", | ||
"version": "9.20.0", | ||
"description": "Official Sentry SDK for browsers", | ||
@@ -42,10 +42,10 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry-internal/browser-utils": "9.19.0", | ||
"@sentry-internal/feedback": "9.19.0", | ||
"@sentry-internal/replay": "9.19.0", | ||
"@sentry-internal/replay-canvas": "9.19.0", | ||
"@sentry/core": "9.19.0" | ||
"@sentry-internal/browser-utils": "9.20.0", | ||
"@sentry-internal/feedback": "9.20.0", | ||
"@sentry-internal/replay": "9.20.0", | ||
"@sentry-internal/replay-canvas": "9.20.0", | ||
"@sentry/core": "9.20.0" | ||
}, | ||
"devDependencies": { | ||
"@sentry-internal/integration-shims": "9.19.0", | ||
"@sentry-internal/integration-shims": "9.20.0", | ||
"fake-indexeddb": "^4.0.1" | ||
@@ -52,0 +52,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1215118
0.64%13178
0.62%10
11.11%116
0.87%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated