MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / _processEvent

Function _processEvent

packages/core/src/client.ts:1424–1529  ·  view source on GitHub ↗

* Processes an event (either error or message) and sends it to Sentry. * * This also adds breadcrumbs and context information to the event. However, * platform specific meta data (such as the User's IP address) must be added * by the SDK implementor. * * * @param event The event

(
    event: Event,
    hint: EventHint,
    currentScope: Scope,
    isolationScope: Scope,
  )

Source from the content-addressed store, hash-verified

1422 * @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
1423 */
1424 protected _processEvent(
1425 event: Event,
1426 hint: EventHint,
1427 currentScope: Scope,
1428 isolationScope: Scope,
1429 ): PromiseLike<Event> {
1430 const options = this.getOptions();
1431 const { sampleRate } = options;
1432
1433 const isTransaction = isTransactionEvent(event);
1434 const isError = isErrorEvent(event);
1435 const eventType = event.type || 'error';
1436 const beforeSendLabel = `before send for type \`${eventType}\``;
1437
1438 // 1.0 === 100% events are sent
1439 // 0.0 === 0% events are sent
1440 // Sampling for transaction happens somewhere else
1441 const parsedSampleRate = typeof sampleRate === 'undefined' ? undefined : parseSampleRate(sampleRate);
1442 if (isError && typeof parsedSampleRate === 'number' && safeMathRandom() > parsedSampleRate) {
1443 this.recordDroppedEvent('sample_rate', 'error');
1444 return rejectedSyncPromise(
1445 _makeDoNotSendEventError(
1446 `Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
1447 ),
1448 );
1449 }
1450
1451 const dataCategory = getDataCategoryByType(event.type);
1452
1453 return this._prepareEvent(event, hint, currentScope, isolationScope)
1454 .then(prepared => {
1455 if (prepared === null) {
1456 this.recordDroppedEvent('event_processor', dataCategory);
1457 throw _makeDoNotSendEventError('An event processor returned `null`, will not send event.');
1458 }
1459
1460 const isInternalException = (hint.data as { __sentry__: boolean })?.__sentry__ === true;
1461 if (isInternalException) {
1462 return prepared;
1463 }
1464
1465 const result = processBeforeSend(this, options, prepared, hint);
1466 return _validateBeforeSendResult(result, beforeSendLabel);
1467 })
1468 .then(processedEvent => {
1469 if (processedEvent === null) {
1470 this.recordDroppedEvent('before_send', dataCategory);
1471 if (isTransaction) {
1472 const spans = event.spans || [];
1473 // the transaction itself counts as one span, plus all the child spans that are added
1474 const spanCount = 1 + spans.length;
1475 this.recordDroppedEvent('before_send', 'span', spanCount);
1476 }
1477 throw _makeDoNotSendEventError(`${beforeSendLabel} returned \`null\`, will not send event.`);
1478 }
1479
1480 const session = currentScope.getSession() || isolationScope.getSession();
1481 if (isError && session) {

Callers

nothing calls this directly

Calls 15

parseSampleRateFunction · 0.90
safeMathRandomFunction · 0.90
rejectedSyncPromiseFunction · 0.90
_makeDoNotSendEventErrorFunction · 0.85
getDataCategoryByTypeFunction · 0.85
processBeforeSendFunction · 0.85
_isDoNotSendEventErrorFunction · 0.85
_isInternalErrorFunction · 0.85
_makeInternalErrorFunction · 0.85
getSessionMethod · 0.80
isTransactionEventFunction · 0.70

Tested by

no test coverage detected