This commit is contained in:
MarSeventh
2024-07-19 23:26:06 +08:00
commit 4e0c55d1f9
1401 changed files with 69819 additions and 0 deletions

View File

@@ -0,0 +1,189 @@
import { dropUndefinedKeys, arrayify } from '@sentry/utils';
import { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext.js';
import { getRootSpan } from './getRootSpan.js';
import { spanToTraceContext, spanToJSON } from './spanUtils.js';
/**
* Applies data from the scope to the event and runs all event processors on it.
*/
function applyScopeDataToEvent(event, data) {
const { fingerprint, span, breadcrumbs, sdkProcessingMetadata } = data;
// Apply general data
applyDataToEvent(event, data);
// We want to set the trace context for normal events only if there isn't already
// a trace context on the event. There is a product feature in place where we link
// errors with transaction and it relies on that.
if (span) {
applySpanToEvent(event, span);
}
applyFingerprintToEvent(event, fingerprint);
applyBreadcrumbsToEvent(event, breadcrumbs);
applySdkMetadataToEvent(event, sdkProcessingMetadata);
}
/** Merge data of two scopes together. */
function mergeScopeData(data, mergeData) {
const {
extra,
tags,
user,
contexts,
level,
sdkProcessingMetadata,
breadcrumbs,
fingerprint,
eventProcessors,
attachments,
propagationContext,
// eslint-disable-next-line deprecation/deprecation
transactionName,
span,
} = mergeData;
mergeAndOverwriteScopeData(data, 'extra', extra);
mergeAndOverwriteScopeData(data, 'tags', tags);
mergeAndOverwriteScopeData(data, 'user', user);
mergeAndOverwriteScopeData(data, 'contexts', contexts);
mergeAndOverwriteScopeData(data, 'sdkProcessingMetadata', sdkProcessingMetadata);
if (level) {
data.level = level;
}
if (transactionName) {
// eslint-disable-next-line deprecation/deprecation
data.transactionName = transactionName;
}
if (span) {
data.span = span;
}
if (breadcrumbs.length) {
data.breadcrumbs = [...data.breadcrumbs, ...breadcrumbs];
}
if (fingerprint.length) {
data.fingerprint = [...data.fingerprint, ...fingerprint];
}
if (eventProcessors.length) {
data.eventProcessors = [...data.eventProcessors, ...eventProcessors];
}
if (attachments.length) {
data.attachments = [...data.attachments, ...attachments];
}
data.propagationContext = { ...data.propagationContext, ...propagationContext };
}
/**
* Merges certain scope data. Undefined values will overwrite any existing values.
* Exported only for tests.
*/
function mergeAndOverwriteScopeData
(data, prop, mergeVal) {
if (mergeVal && Object.keys(mergeVal).length) {
// Clone object
data[prop] = { ...data[prop] };
for (const key in mergeVal) {
if (Object.prototype.hasOwnProperty.call(mergeVal, key)) {
data[prop][key] = mergeVal[key];
}
}
}
}
function applyDataToEvent(event, data) {
const {
extra,
tags,
user,
contexts,
level,
// eslint-disable-next-line deprecation/deprecation
transactionName,
} = data;
const cleanedExtra = dropUndefinedKeys(extra);
if (cleanedExtra && Object.keys(cleanedExtra).length) {
event.extra = { ...cleanedExtra, ...event.extra };
}
const cleanedTags = dropUndefinedKeys(tags);
if (cleanedTags && Object.keys(cleanedTags).length) {
event.tags = { ...cleanedTags, ...event.tags };
}
const cleanedUser = dropUndefinedKeys(user);
if (cleanedUser && Object.keys(cleanedUser).length) {
event.user = { ...cleanedUser, ...event.user };
}
const cleanedContexts = dropUndefinedKeys(contexts);
if (cleanedContexts && Object.keys(cleanedContexts).length) {
event.contexts = { ...cleanedContexts, ...event.contexts };
}
if (level) {
event.level = level;
}
if (transactionName) {
event.transaction = transactionName;
}
}
function applyBreadcrumbsToEvent(event, breadcrumbs) {
const mergedBreadcrumbs = [...(event.breadcrumbs || []), ...breadcrumbs];
event.breadcrumbs = mergedBreadcrumbs.length ? mergedBreadcrumbs : undefined;
}
function applySdkMetadataToEvent(event, sdkProcessingMetadata) {
event.sdkProcessingMetadata = {
...event.sdkProcessingMetadata,
...sdkProcessingMetadata,
};
}
function applySpanToEvent(event, span) {
event.contexts = { trace: spanToTraceContext(span), ...event.contexts };
const rootSpan = getRootSpan(span);
if (rootSpan) {
event.sdkProcessingMetadata = {
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
...event.sdkProcessingMetadata,
};
const transactionName = spanToJSON(rootSpan).description;
if (transactionName) {
event.tags = { transaction: transactionName, ...event.tags };
}
}
}
/**
* Applies fingerprint from the scope to the event if there's one,
* uses message if there's one instead or get rid of empty fingerprint
*/
function applyFingerprintToEvent(event, fingerprint) {
// Make sure it's an array first and we actually have something in place
event.fingerprint = event.fingerprint ? arrayify(event.fingerprint) : [];
// If we have something on the scope, then merge it with event
if (fingerprint) {
event.fingerprint = event.fingerprint.concat(fingerprint);
}
// If we have no data at all, remove empty array default
if (event.fingerprint && !event.fingerprint.length) {
delete event.fingerprint;
}
}
export { applyScopeDataToEvent, mergeAndOverwriteScopeData, mergeScopeData };
//# sourceMappingURL=applyScopeDataToEvent.js.map

File diff suppressed because one or more lines are too long

16
node_modules/@sentry/core/esm/utils/getRootSpan.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* Returns the root span of a given span.
*
* As long as we use `Transaction`s internally, the returned root span
* will be a `Transaction` but be aware that this might change in the future.
*
* If the given span has no root span or transaction, `undefined` is returned.
*/
function getRootSpan(span) {
// TODO (v8): Remove this check and just return span
// eslint-disable-next-line deprecation/deprecation
return span.transaction;
}
export { getRootSpan };
//# sourceMappingURL=getRootSpan.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getRootSpan.js","sources":["../../../src/utils/getRootSpan.ts"],"sourcesContent":["import type { Span } from '@sentry/types';\n\n/**\n * Returns the root span of a given span.\n *\n * As long as we use `Transaction`s internally, the returned root span\n * will be a `Transaction` but be aware that this might change in the future.\n *\n * If the given span has no root span or transaction, `undefined` is returned.\n */\nexport function getRootSpan(span: Span): Span | undefined {\n // TODO (v8): Remove this check and just return span\n // eslint-disable-next-line deprecation/deprecation\n return span.transaction;\n}\n"],"names":[],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,WAAW,CAAC,IAAI,EAA0B;AAC1D;AACA;AACA,EAAE,OAAO,IAAI,CAAC,WAAW,CAAA;AACzB;;;;"}

View File

@@ -0,0 +1,65 @@
import { isThenable } from '@sentry/utils';
/**
* Wrap a callback function with error handling.
* If an error is thrown, it will be passed to the `onError` callback and re-thrown.
*
* If the return value of the function is a promise, it will be handled with `maybeHandlePromiseRejection`.
*
* If an `onFinally` callback is provided, this will be called when the callback has finished
* - so if it returns a promise, once the promise resolved/rejected,
* else once the callback has finished executing.
* The `onFinally` callback will _always_ be called, no matter if an error was thrown or not.
*/
function handleCallbackErrors
(
fn,
onError,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onFinally = () => {},
) {
let maybePromiseResult;
try {
maybePromiseResult = fn();
} catch (e) {
onError(e);
onFinally();
throw e;
}
return maybeHandlePromiseRejection(maybePromiseResult, onError, onFinally);
}
/**
* Maybe handle a promise rejection.
* This expects to be given a value that _may_ be a promise, or any other value.
* If it is a promise, and it rejects, it will call the `onError` callback.
* Other than this, it will generally return the given value as-is.
*/
function maybeHandlePromiseRejection(
value,
onError,
onFinally,
) {
if (isThenable(value)) {
// @ts-expect-error - the isThenable check returns the "wrong" type here
return value.then(
res => {
onFinally();
return res;
},
e => {
onError(e);
onFinally();
throw e;
},
);
}
onFinally();
return value;
}
export { handleCallbackErrors };
//# sourceMappingURL=handleCallbackErrors.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"handleCallbackErrors.js","sources":["../../../src/utils/handleCallbackErrors.ts"],"sourcesContent":["import { isThenable } from '@sentry/utils';\n\n/**\n * Wrap a callback function with error handling.\n * If an error is thrown, it will be passed to the `onError` callback and re-thrown.\n *\n * If the return value of the function is a promise, it will be handled with `maybeHandlePromiseRejection`.\n *\n * If an `onFinally` callback is provided, this will be called when the callback has finished\n * - so if it returns a promise, once the promise resolved/rejected,\n * else once the callback has finished executing.\n * The `onFinally` callback will _always_ be called, no matter if an error was thrown or not.\n */\nexport function handleCallbackErrors<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Fn extends () => any,\n>(\n fn: Fn,\n onError: (error: unknown) => void,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n onFinally: () => void = () => {},\n): ReturnType<Fn> {\n let maybePromiseResult: ReturnType<Fn>;\n try {\n maybePromiseResult = fn();\n } catch (e) {\n onError(e);\n onFinally();\n throw e;\n }\n\n return maybeHandlePromiseRejection(maybePromiseResult, onError, onFinally);\n}\n\n/**\n * Maybe handle a promise rejection.\n * This expects to be given a value that _may_ be a promise, or any other value.\n * If it is a promise, and it rejects, it will call the `onError` callback.\n * Other than this, it will generally return the given value as-is.\n */\nfunction maybeHandlePromiseRejection<MaybePromise>(\n value: MaybePromise,\n onError: (error: unknown) => void,\n onFinally: () => void,\n): MaybePromise {\n if (isThenable(value)) {\n // @ts-expect-error - the isThenable check returns the \"wrong\" type here\n return value.then(\n res => {\n onFinally();\n return res;\n },\n e => {\n onError(e);\n onFinally();\n throw e;\n },\n );\n }\n\n onFinally();\n return value;\n}\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB;;AAGpC;AACA,EAAE,EAAE;AACJ,EAAE,OAAO;AACT;AACA,EAAE,SAAS,GAAe,MAAM,EAAE;AAClC,EAAkB;AAClB,EAAE,IAAI,kBAAkB,CAAA;AACxB,EAAE,IAAI;AACN,IAAI,kBAAmB,GAAE,EAAE,EAAE,CAAA;AAC7B,GAAI,CAAA,OAAO,CAAC,EAAE;AACd,IAAI,OAAO,CAAC,CAAC,CAAC,CAAA;AACd,IAAI,SAAS,EAAE,CAAA;AACf,IAAI,MAAM,CAAC,CAAA;AACX,GAAE;AACF;AACA,EAAE,OAAO,2BAA2B,CAAC,kBAAkB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AAC5E,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,2BAA2B;AACpC,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,SAAS;AACX,EAAgB;AAChB,EAAE,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;AACzB;AACA,IAAI,OAAO,KAAK,CAAC,IAAI;AACrB,MAAM,OAAO;AACb,QAAQ,SAAS,EAAE,CAAA;AACnB,QAAQ,OAAO,GAAG,CAAA;AAClB,OAAO;AACP,MAAM,KAAK;AACX,QAAQ,OAAO,CAAC,CAAC,CAAC,CAAA;AAClB,QAAQ,SAAS,EAAE,CAAA;AACnB,QAAQ,MAAM,CAAC,CAAA;AACf,OAAO;AACP,KAAK,CAAA;AACL,GAAE;AACF;AACA,EAAE,SAAS,EAAE,CAAA;AACb,EAAE,OAAO,KAAK,CAAA;AACd;;;;"}

View File

@@ -0,0 +1,23 @@
import { getClient } from '../exports.js';
// Treeshakable guard to remove all code related to tracing
/**
* Determines if tracing is currently enabled.
*
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
*/
function hasTracingEnabled(
maybeOptions,
) {
if (typeof __SENTRY_TRACING__ === 'boolean' && !__SENTRY_TRACING__) {
return false;
}
const client = getClient();
const options = maybeOptions || (client && client.getOptions());
return !!options && (options.enableTracing || 'tracesSampleRate' in options || 'tracesSampler' in options);
}
export { hasTracingEnabled };
//# sourceMappingURL=hasTracingEnabled.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hasTracingEnabled.js","sources":["../../../src/utils/hasTracingEnabled.ts"],"sourcesContent":["import type { Options } from '@sentry/types';\n\nimport { getClient } from '../exports';\n\n// Treeshakable guard to remove all code related to tracing\ndeclare const __SENTRY_TRACING__: boolean | undefined;\n\n/**\n * Determines if tracing is currently enabled.\n *\n * Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.\n */\nexport function hasTracingEnabled(\n maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler' | 'enableTracing'> | undefined,\n): boolean {\n if (typeof __SENTRY_TRACING__ === 'boolean' && !__SENTRY_TRACING__) {\n return false;\n }\n\n const client = getClient();\n const options = maybeOptions || (client && client.getOptions());\n return !!options && (options.enableTracing || 'tracesSampleRate' in options || 'tracesSampler' in options);\n}\n"],"names":[],"mappings":";;AAIA;;AAGA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB;AACjC,EAAE,YAAY;AACd,EAAW;AACX,EAAE,IAAI,OAAO,kBAAA,KAAuB,SAAU,IAAG,CAAC,kBAAkB,EAAE;AACtE,IAAI,OAAO,KAAK,CAAA;AAChB,GAAE;AACF;AACA,EAAE,MAAM,MAAA,GAAS,SAAS,EAAE,CAAA;AAC5B,EAAE,MAAM,OAAA,GAAU,YAAA,KAAiB,MAAO,IAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAA;AACjE,EAAE,OAAO,CAAC,CAAC,OAAQ,KAAI,OAAO,CAAC,aAAc,IAAG,sBAAsB,OAAA,IAAW,eAAgB,IAAG,OAAO,CAAC,CAAA;AAC5G;;;;"}

View File

@@ -0,0 +1,43 @@
/**
* Checks whether given url points to Sentry server
* @param url url to verify
*
* TODO(v8): Remove Hub fallback type
*/
// eslint-disable-next-line deprecation/deprecation
function isSentryRequestUrl(url, hubOrClient) {
const client =
hubOrClient && isHub(hubOrClient)
? // eslint-disable-next-line deprecation/deprecation
hubOrClient.getClient()
: hubOrClient;
const dsn = client && client.getDsn();
const tunnel = client && client.getOptions().tunnel;
return checkDsn(url, dsn) || checkTunnel(url, tunnel);
}
function checkTunnel(url, tunnel) {
if (!tunnel) {
return false;
}
return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
}
function checkDsn(url, dsn) {
return dsn ? url.includes(dsn.host) : false;
}
function removeTrailingSlash(str) {
return str[str.length - 1] === '/' ? str.slice(0, -1) : str;
}
// eslint-disable-next-line deprecation/deprecation
function isHub(hubOrClient) {
// eslint-disable-next-line deprecation/deprecation
return (hubOrClient ).getClient !== undefined;
}
export { isSentryRequestUrl };
//# sourceMappingURL=isSentryRequestUrl.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"isSentryRequestUrl.js","sources":["../../../src/utils/isSentryRequestUrl.ts"],"sourcesContent":["import type { Client, DsnComponents, Hub } from '@sentry/types';\n\n/**\n * Checks whether given url points to Sentry server\n * @param url url to verify\n *\n * TODO(v8): Remove Hub fallback type\n */\n// eslint-disable-next-line deprecation/deprecation\nexport function isSentryRequestUrl(url: string, hubOrClient: Hub | Client | undefined): boolean {\n const client =\n hubOrClient && isHub(hubOrClient)\n ? // eslint-disable-next-line deprecation/deprecation\n hubOrClient.getClient()\n : hubOrClient;\n const dsn = client && client.getDsn();\n const tunnel = client && client.getOptions().tunnel;\n\n return checkDsn(url, dsn) || checkTunnel(url, tunnel);\n}\n\nfunction checkTunnel(url: string, tunnel: string | undefined): boolean {\n if (!tunnel) {\n return false;\n }\n\n return removeTrailingSlash(url) === removeTrailingSlash(tunnel);\n}\n\nfunction checkDsn(url: string, dsn: DsnComponents | undefined): boolean {\n return dsn ? url.includes(dsn.host) : false;\n}\n\nfunction removeTrailingSlash(str: string): string {\n return str[str.length - 1] === '/' ? str.slice(0, -1) : str;\n}\n\n// eslint-disable-next-line deprecation/deprecation\nfunction isHub(hubOrClient: Hub | Client | undefined): hubOrClient is Hub {\n // eslint-disable-next-line deprecation/deprecation\n return (hubOrClient as Hub).getClient !== undefined;\n}\n"],"names":[],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,GAAG,EAAU,WAAW,EAAqC;AAChG,EAAE,MAAM,MAAO;AACf,IAAI,WAAY,IAAG,KAAK,CAAC,WAAW,CAAA;AACpC;AACA,QAAQ,WAAW,CAAC,SAAS,EAAC;AAC9B,QAAQ,WAAW,CAAA;AACnB,EAAE,MAAM,MAAM,MAAA,IAAU,MAAM,CAAC,MAAM,EAAE,CAAA;AACvC,EAAE,MAAM,MAAO,GAAE,MAAO,IAAG,MAAM,CAAC,UAAU,EAAE,CAAC,MAAM,CAAA;AACrD;AACA,EAAE,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAE,IAAG,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AACvD,CAAA;AACA;AACA,SAAS,WAAW,CAAC,GAAG,EAAU,MAAM,EAA+B;AACvE,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI,OAAO,KAAK,CAAA;AAChB,GAAE;AACF;AACA,EAAE,OAAO,mBAAmB,CAAC,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;AACjE,CAAA;AACA;AACA,SAAS,QAAQ,CAAC,GAAG,EAAU,GAAG,EAAsC;AACxE,EAAE,OAAO,GAAA,GAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAE,GAAE,KAAK,CAAA;AAC7C,CAAA;AACA;AACA,SAAS,mBAAmB,CAAC,GAAG,EAAkB;AAClD,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,MAAO,GAAE,CAAC,CAAA,KAAM,GAAA,GAAM,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,GAAE,GAAG,CAAA;AAC7D,CAAA;AACA;AACA;AACA,SAAS,KAAK,CAAC,WAAW,EAAgD;AAC1E;AACA,EAAE,OAAO,CAAC,WAAA,GAAoB,SAAA,KAAc,SAAS,CAAA;AACrD;;;;"}

18
node_modules/@sentry/core/esm/utils/parameterize.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
/**
* Tagged template function which returns paramaterized representation of the message
* For example: parameterize`This is a log statement with ${x} and ${y} params`, would return:
* "__sentry_template_string__": 'This is a log statement with %s and %s params',
* "__sentry_template_values__": ['first', 'second']
* @param strings An array of string values splitted between expressions
* @param values Expressions extracted from template string
* @returns String with template information in __sentry_template_string__ and __sentry_template_values__ properties
*/
function parameterize(strings, ...values) {
const formatted = new String(String.raw(strings, ...values)) ;
formatted.__sentry_template_string__ = strings.join('\x00').replace(/%/g, '%%').replace(/\0/g, '%s');
formatted.__sentry_template_values__ = values;
return formatted;
}
export { parameterize };
//# sourceMappingURL=parameterize.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"parameterize.js","sources":["../../../src/utils/parameterize.ts"],"sourcesContent":["import type { ParameterizedString } from '@sentry/types';\n\n/**\n * Tagged template function which returns paramaterized representation of the message\n * For example: parameterize`This is a log statement with ${x} and ${y} params`, would return:\n * \"__sentry_template_string__\": 'This is a log statement with %s and %s params',\n * \"__sentry_template_values__\": ['first', 'second']\n * @param strings An array of string values splitted between expressions\n * @param values Expressions extracted from template string\n * @returns String with template information in __sentry_template_string__ and __sentry_template_values__ properties\n */\nexport function parameterize(strings: TemplateStringsArray, ...values: string[]): ParameterizedString {\n const formatted = new String(String.raw(strings, ...values)) as ParameterizedString;\n formatted.__sentry_template_string__ = strings.join('\\x00').replace(/%/g, '%%').replace(/\\0/g, '%s');\n formatted.__sentry_template_values__ = values;\n return formatted;\n}\n"],"names":[],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY,CAAC,OAAO,EAAwB,GAAG,MAAM,EAAiC;AACtG,EAAE,MAAM,SAAA,GAAY,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAE,EAAA;AAC/D,EAAE,SAAS,CAAC,0BAA2B,GAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AACtG,EAAE,SAAS,CAAC,0BAA2B,GAAE,MAAM,CAAA;AAC/C,EAAE,OAAO,SAAS,CAAA;AAClB;;;;"}

387
node_modules/@sentry/core/esm/utils/prepareEvent.js generated vendored Normal file
View File

@@ -0,0 +1,387 @@
import { uuid4, dateTimestampInSeconds, addExceptionMechanism, truncate, GLOBAL_OBJ, normalize } from '@sentry/utils';
import { DEFAULT_ENVIRONMENT } from '../constants.js';
import { getGlobalEventProcessors, notifyEventProcessors } from '../eventProcessors.js';
import { getGlobalScope, Scope } from '../scope.js';
import { mergeScopeData, applyScopeDataToEvent } from './applyScopeDataToEvent.js';
import { spanToJSON } from './spanUtils.js';
/**
* This type makes sure that we get either a CaptureContext, OR an EventHint.
* It does not allow mixing them, which could lead to unexpected outcomes, e.g. this is disallowed:
* { user: { id: '123' }, mechanism: { handled: false } }
*/
/**
* Adds common information to events.
*
* The information includes release and environment from `options`,
* breadcrumbs and context (extra, tags and user) from the scope.
*
* Information that is already present in the event is never overwritten. For
* nested objects, such as the context, keys are merged.
*
* Note: This also triggers callbacks for `addGlobalEventProcessor`, but not `beforeSend`.
*
* @param event The original event.
* @param hint May contain additional information about the original exception.
* @param scope A scope containing event metadata.
* @returns A new event with more information.
* @hidden
*/
function prepareEvent(
options,
event,
hint,
scope,
client,
isolationScope,
) {
const { normalizeDepth = 3, normalizeMaxBreadth = 1000 } = options;
const prepared = {
...event,
event_id: event.event_id || hint.event_id || uuid4(),
timestamp: event.timestamp || dateTimestampInSeconds(),
};
const integrations = hint.integrations || options.integrations.map(i => i.name);
applyClientOptions(prepared, options);
applyIntegrationsMetadata(prepared, integrations);
// Only put debug IDs onto frames for error events.
if (event.type === undefined) {
applyDebugIds(prepared, options.stackParser);
}
// If we have scope given to us, use it as the base for further modifications.
// This allows us to prevent unnecessary copying of data if `captureContext` is not provided.
const finalScope = getFinalScope(scope, hint.captureContext);
if (hint.mechanism) {
addExceptionMechanism(prepared, hint.mechanism);
}
const clientEventProcessors = client && client.getEventProcessors ? client.getEventProcessors() : [];
// This should be the last thing called, since we want that
// {@link Hub.addEventProcessor} gets the finished prepared event.
// Merge scope data together
const data = getGlobalScope().getScopeData();
if (isolationScope) {
const isolationData = isolationScope.getScopeData();
mergeScopeData(data, isolationData);
}
if (finalScope) {
const finalScopeData = finalScope.getScopeData();
mergeScopeData(data, finalScopeData);
}
const attachments = [...(hint.attachments || []), ...data.attachments];
if (attachments.length) {
hint.attachments = attachments;
}
applyScopeDataToEvent(prepared, data);
// TODO (v8): Update this order to be: Global > Client > Scope
const eventProcessors = [
...clientEventProcessors,
// eslint-disable-next-line deprecation/deprecation
...getGlobalEventProcessors(),
// Run scope event processors _after_ all other processors
...data.eventProcessors,
];
const result = notifyEventProcessors(eventProcessors, prepared, hint);
return result.then(evt => {
if (evt) {
// We apply the debug_meta field only after all event processors have ran, so that if any event processors modified
// file names (e.g.the RewriteFrames integration) the filename -> debug ID relationship isn't destroyed.
// This should not cause any PII issues, since we're only moving data that is already on the event and not adding
// any new data
applyDebugMeta(evt);
}
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
return normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
}
return evt;
});
}
/**
* Enhances event using the client configuration.
* It takes care of all "static" values like environment, release and `dist`,
* as well as truncating overly long values.
* @param event event instance to be enhanced
*/
function applyClientOptions(event, options) {
const { environment, release, dist, maxValueLength = 250 } = options;
if (!('environment' in event)) {
event.environment = 'environment' in options ? environment : DEFAULT_ENVIRONMENT;
}
if (event.release === undefined && release !== undefined) {
event.release = release;
}
if (event.dist === undefined && dist !== undefined) {
event.dist = dist;
}
if (event.message) {
event.message = truncate(event.message, maxValueLength);
}
const exception = event.exception && event.exception.values && event.exception.values[0];
if (exception && exception.value) {
exception.value = truncate(exception.value, maxValueLength);
}
const request = event.request;
if (request && request.url) {
request.url = truncate(request.url, maxValueLength);
}
}
const debugIdStackParserCache = new WeakMap();
/**
* Puts debug IDs into the stack frames of an error event.
*/
function applyDebugIds(event, stackParser) {
const debugIdMap = GLOBAL_OBJ._sentryDebugIds;
if (!debugIdMap) {
return;
}
let debugIdStackFramesCache;
const cachedDebugIdStackFrameCache = debugIdStackParserCache.get(stackParser);
if (cachedDebugIdStackFrameCache) {
debugIdStackFramesCache = cachedDebugIdStackFrameCache;
} else {
debugIdStackFramesCache = new Map();
debugIdStackParserCache.set(stackParser, debugIdStackFramesCache);
}
// Build a map of filename -> debug_id
const filenameDebugIdMap = Object.keys(debugIdMap).reduce((acc, debugIdStackTrace) => {
let parsedStack;
const cachedParsedStack = debugIdStackFramesCache.get(debugIdStackTrace);
if (cachedParsedStack) {
parsedStack = cachedParsedStack;
} else {
parsedStack = stackParser(debugIdStackTrace);
debugIdStackFramesCache.set(debugIdStackTrace, parsedStack);
}
for (let i = parsedStack.length - 1; i >= 0; i--) {
const stackFrame = parsedStack[i];
if (stackFrame.filename) {
acc[stackFrame.filename] = debugIdMap[debugIdStackTrace];
break;
}
}
return acc;
}, {});
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
event.exception.values.forEach(exception => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
exception.stacktrace.frames.forEach(frame => {
if (frame.filename) {
frame.debug_id = filenameDebugIdMap[frame.filename];
}
});
});
} catch (e) {
// To save bundle size we're just try catching here instead of checking for the existence of all the different objects.
}
}
/**
* Moves debug IDs from the stack frames of an error event into the debug_meta field.
*/
function applyDebugMeta(event) {
// Extract debug IDs and filenames from the stack frames on the event.
const filenameDebugIdMap = {};
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
event.exception.values.forEach(exception => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
exception.stacktrace.frames.forEach(frame => {
if (frame.debug_id) {
if (frame.abs_path) {
filenameDebugIdMap[frame.abs_path] = frame.debug_id;
} else if (frame.filename) {
filenameDebugIdMap[frame.filename] = frame.debug_id;
}
delete frame.debug_id;
}
});
});
} catch (e) {
// To save bundle size we're just try catching here instead of checking for the existence of all the different objects.
}
if (Object.keys(filenameDebugIdMap).length === 0) {
return;
}
// Fill debug_meta information
event.debug_meta = event.debug_meta || {};
event.debug_meta.images = event.debug_meta.images || [];
const images = event.debug_meta.images;
Object.keys(filenameDebugIdMap).forEach(filename => {
images.push({
type: 'sourcemap',
code_file: filename,
debug_id: filenameDebugIdMap[filename],
});
});
}
/**
* This function adds all used integrations to the SDK info in the event.
* @param event The event that will be filled with all integrations.
*/
function applyIntegrationsMetadata(event, integrationNames) {
if (integrationNames.length > 0) {
event.sdk = event.sdk || {};
event.sdk.integrations = [...(event.sdk.integrations || []), ...integrationNames];
}
}
/**
* Applies `normalize` function on necessary `Event` attributes to make them safe for serialization.
* Normalized keys:
* - `breadcrumbs.data`
* - `user`
* - `contexts`
* - `extra`
* @param event Event
* @returns Normalized event
*/
function normalizeEvent(event, depth, maxBreadth) {
if (!event) {
return null;
}
const normalized = {
...event,
...(event.breadcrumbs && {
breadcrumbs: event.breadcrumbs.map(b => ({
...b,
...(b.data && {
data: normalize(b.data, depth, maxBreadth),
}),
})),
}),
...(event.user && {
user: normalize(event.user, depth, maxBreadth),
}),
...(event.contexts && {
contexts: normalize(event.contexts, depth, maxBreadth),
}),
...(event.extra && {
extra: normalize(event.extra, depth, maxBreadth),
}),
};
// event.contexts.trace stores information about a Transaction. Similarly,
// event.spans[] stores information about child Spans. Given that a
// Transaction is conceptually a Span, normalization should apply to both
// Transactions and Spans consistently.
// For now the decision is to skip normalization of Transactions and Spans,
// so this block overwrites the normalized event to add back the original
// Transaction information prior to normalization.
if (event.contexts && event.contexts.trace && normalized.contexts) {
normalized.contexts.trace = event.contexts.trace;
// event.contexts.trace.data may contain circular/dangerous data so we need to normalize it
if (event.contexts.trace.data) {
normalized.contexts.trace.data = normalize(event.contexts.trace.data, depth, maxBreadth);
}
}
// event.spans[].data may contain circular/dangerous data so we need to normalize it
if (event.spans) {
normalized.spans = event.spans.map(span => {
const data = spanToJSON(span).data;
if (data) {
// This is a bit weird, as we generally have `Span` instances here, but to be safe we do not assume so
// eslint-disable-next-line deprecation/deprecation
span.data = normalize(data, depth, maxBreadth);
}
return span;
});
}
return normalized;
}
function getFinalScope(scope, captureContext) {
if (!captureContext) {
return scope;
}
const finalScope = scope ? scope.clone() : new Scope();
finalScope.update(captureContext);
return finalScope;
}
/**
* Parse either an `EventHint` directly, or convert a `CaptureContext` to an `EventHint`.
* This is used to allow to update method signatures that used to accept a `CaptureContext` but should now accept an `EventHint`.
*/
function parseEventHintOrCaptureContext(
hint,
) {
if (!hint) {
return undefined;
}
// If you pass a Scope or `() => Scope` as CaptureContext, we just return this as captureContext
if (hintIsScopeOrFunction(hint)) {
return { captureContext: hint };
}
if (hintIsScopeContext(hint)) {
return {
captureContext: hint,
};
}
return hint;
}
function hintIsScopeOrFunction(
hint,
) {
return hint instanceof Scope || typeof hint === 'function';
}
const captureContextKeys = [
'user',
'level',
'extra',
'contexts',
'tags',
'fingerprint',
'requestSession',
'propagationContext',
] ;
function hintIsScopeContext(hint) {
return Object.keys(hint).some(key => captureContextKeys.includes(key ));
}
export { applyDebugIds, applyDebugMeta, parseEventHintOrCaptureContext, prepareEvent };
//# sourceMappingURL=prepareEvent.js.map

File diff suppressed because one or more lines are too long

34
node_modules/@sentry/core/esm/utils/sdkMetadata.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
import { SDK_VERSION } from '../version.js';
/**
* A builder for the SDK metadata in the options for the SDK initialization.
*
* Note: This function is identical to `buildMetadata` in Remix and NextJS and SvelteKit.
* We don't extract it for bundle size reasons.
* @see https://github.com/getsentry/sentry-javascript/pull/7404
* @see https://github.com/getsentry/sentry-javascript/pull/4196
*
* If you make changes to this function consider updating the others as well.
*
* @param options SDK options object that gets mutated
* @param names list of package names
*/
function applySdkMetadata(options, name, names = [name], source = 'npm') {
const metadata = options._metadata || {};
if (!metadata.sdk) {
metadata.sdk = {
name: `sentry.javascript.${name}`,
packages: names.map(name => ({
name: `${source}:@sentry/${name}`,
version: SDK_VERSION,
})),
version: SDK_VERSION,
};
}
options._metadata = metadata;
}
export { applySdkMetadata };
//# sourceMappingURL=sdkMetadata.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sdkMetadata.js","sources":["../../../src/utils/sdkMetadata.ts"],"sourcesContent":["import type { Options } from '@sentry/types';\nimport { SDK_VERSION } from '../version';\n\n/**\n * A builder for the SDK metadata in the options for the SDK initialization.\n *\n * Note: This function is identical to `buildMetadata` in Remix and NextJS and SvelteKit.\n * We don't extract it for bundle size reasons.\n * @see https://github.com/getsentry/sentry-javascript/pull/7404\n * @see https://github.com/getsentry/sentry-javascript/pull/4196\n *\n * If you make changes to this function consider updating the others as well.\n *\n * @param options SDK options object that gets mutated\n * @param names list of package names\n */\nexport function applySdkMetadata(options: Options, name: string, names = [name], source = 'npm'): void {\n const metadata = options._metadata || {};\n\n if (!metadata.sdk) {\n metadata.sdk = {\n name: `sentry.javascript.${name}`,\n packages: names.map(name => ({\n name: `${source}:@sentry/${name}`,\n version: SDK_VERSION,\n })),\n version: SDK_VERSION,\n };\n }\n\n options._metadata = metadata;\n}\n"],"names":[],"mappings":";;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,OAAO,EAAW,IAAI,EAAU,KAAA,GAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,KAAK,EAAQ;AACvG,EAAE,MAAM,WAAW,OAAO,CAAC,SAAU,IAAG,EAAE,CAAA;AAC1C;AACA,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;AACrB,IAAI,QAAQ,CAAC,GAAA,GAAM;AACnB,MAAM,IAAI,EAAE,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;AACA,MAAA,QAAA,EAAA,KAAA,CAAA,GAAA,CAAA,IAAA,KAAA;AACA,QAAA,IAAA,EAAA,CAAA,EAAA,MAAA,CAAA,SAAA,EAAA,IAAA,CAAA,CAAA;AACA,QAAA,OAAA,EAAA,WAAA;AACA,OAAA,CAAA,CAAA;AACA,MAAA,OAAA,EAAA,WAAA;AACA,KAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,CAAA,SAAA,GAAA,QAAA,CAAA;AACA;;;;"}

110
node_modules/@sentry/core/esm/utils/spanUtils.js generated vendored Normal file
View File

@@ -0,0 +1,110 @@
import { dropUndefinedKeys, generateSentryTraceHeader, timestampInSeconds } from '@sentry/utils';
// These are aligned with OpenTelemetry trace flags
const TRACE_FLAG_NONE = 0x0;
const TRACE_FLAG_SAMPLED = 0x1;
/**
* Convert a span to a trace context, which can be sent as the `trace` context in an event.
*/
function spanToTraceContext(span) {
const { spanId: span_id, traceId: trace_id } = span.spanContext();
const { data, op, parent_span_id, status, tags, origin } = spanToJSON(span);
return dropUndefinedKeys({
data,
op,
parent_span_id,
span_id,
status,
tags,
trace_id,
origin,
});
}
/**
* Convert a Span to a Sentry trace header.
*/
function spanToTraceHeader(span) {
const { traceId, spanId } = span.spanContext();
const sampled = spanIsSampled(span);
return generateSentryTraceHeader(traceId, spanId, sampled);
}
/**
* Convert a span time input intp a timestamp in seconds.
*/
function spanTimeInputToSeconds(input) {
if (typeof input === 'number') {
return ensureTimestampInSeconds(input);
}
if (Array.isArray(input)) {
// See {@link HrTime} for the array-based time format
return input[0] + input[1] / 1e9;
}
if (input instanceof Date) {
return ensureTimestampInSeconds(input.getTime());
}
return timestampInSeconds();
}
/**
* Converts a timestamp to second, if it was in milliseconds, or keeps it as second.
*/
function ensureTimestampInSeconds(timestamp) {
const isMs = timestamp > 9999999999;
return isMs ? timestamp / 1000 : timestamp;
}
/**
* Convert a span to a JSON representation.
* Note that all fields returned here are optional and need to be guarded against.
*
* Note: Because of this, we currently have a circular type dependency (which we opted out of in package.json).
* This is not avoidable as we need `spanToJSON` in `spanUtils.ts`, which in turn is needed by `span.ts` for backwards compatibility.
* And `spanToJSON` needs the Span class from `span.ts` to check here.
* TODO v8: When we remove the deprecated stuff from `span.ts`, we can remove the circular dependency again.
*/
function spanToJSON(span) {
if (spanIsSpanClass(span)) {
return span.getSpanJSON();
}
// Fallback: We also check for `.toJSON()` here...
// eslint-disable-next-line deprecation/deprecation
if (typeof span.toJSON === 'function') {
// eslint-disable-next-line deprecation/deprecation
return span.toJSON();
}
return {};
}
/**
* Sadly, due to circular dependency checks we cannot actually import the Span class here and check for instanceof.
* :( So instead we approximate this by checking if it has the `getSpanJSON` method.
*/
function spanIsSpanClass(span) {
return typeof (span ).getSpanJSON === 'function';
}
/**
* Returns true if a span is sampled.
* In most cases, you should just use `span.isRecording()` instead.
* However, this has a slightly different semantic, as it also returns false if the span is finished.
* So in the case where this distinction is important, use this method.
*/
function spanIsSampled(span) {
// We align our trace flags with the ones OpenTelemetry use
// So we also check for sampled the same way they do.
const { traceFlags } = span.spanContext();
// eslint-disable-next-line no-bitwise
return Boolean(traceFlags & TRACE_FLAG_SAMPLED);
}
export { TRACE_FLAG_NONE, TRACE_FLAG_SAMPLED, spanIsSampled, spanTimeInputToSeconds, spanToJSON, spanToTraceContext, spanToTraceHeader };
//# sourceMappingURL=spanUtils.js.map

1
node_modules/@sentry/core/esm/utils/spanUtils.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long