GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(core): Capture # of dropped spans through `beforeSendTransaction` by mydea · Pull Request #13022 · getsentry/sentry-javascript
feat(core): Capture # of dropped spans through
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,20 +371,21 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> { | |
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public recordDroppedEvent(reason: EventDropReason, category: DataCategory, _event?: Event): void { | ||
| // Note: we use `event` in replay, where we overwrite this hook. | ||
|
|
||
| public recordDroppedEvent(reason: EventDropReason, category: DataCategory, eventOrCount?: Event | number): void { | ||
| if (this._options.sendClientReports) { | ||
| // TODO v9: We do not need the `event` passed as third argument anymore, and can possibly remove this overload | ||
| // If event is passed as third argument, we assume this is a count of 1 | ||
| const count = typeof eventOrCount === 'number' ? eventOrCount : 1; | ||
|
|
||
| // We want to track each category (error, transaction, session, replay_event) separately | ||
| // but still keep the distinction between different type of outcomes. | ||
| // We could use nested maps, but it's much easier to read and type this way. | ||
| // A correct type for map-based implementation if we want to go that route | ||
| // would be `Partial<Record<SentryRequestType, Partial<Record<Outcome, number>>>>` | ||
| // With typescript 4.1 we could even use template literal types | ||
| const key = `${reason}:${category}`; | ||
| DEBUG_BUILD && logger.log(`Adding outcome: "${key}"`); | ||
|
|
||
| this._outcomes[key] = (this._outcomes[key] || 0) + 1; | ||
| DEBUG_BUILD && logger.log(`Recording outcome: "${key}"${count > 1 ? ` (${count} times)` : ''}`); | ||
| this._outcomes[key] = (this._outcomes[key] || 0) + count; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -794,11 +795,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> { | |
| .then(processedEvent => { | ||
| if (processedEvent === null) { | ||
| this.recordDroppedEvent('before_send', dataCategory, event); | ||
| if (isTransactionEvent(event)) { | ||
| if (isTransaction) { | ||
| const spans = event.spans || []; | ||
| // the transaction itself counts as one span, plus all the child spans that are added | ||
| const spanCount = 1 + spans.length; | ||
| this._outcomes['span'] = (this._outcomes['span'] || 0) + spanCount; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed that this was actually buggy, because the key is built from reason + category 😬 now this is unified and should work consistently.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
||
| this.recordDroppedEvent('before_send', 'span', spanCount); | ||
| } | ||
| throw new SentryError(`${beforeSendLabel} returned \`null\`, will not send event.`, 'log'); | ||
| } | ||
|
|
@@ -808,6 +809,18 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> { | |
| this._updateSessionFromEvent(session, processedEvent); | ||
| } | ||
|
|
||
| if (isTransaction) { | ||
| const spanCountBefore = | ||
| (processedEvent.sdkProcessingMetadata && processedEvent.sdkProcessingMetadata.spanCountBeforeProcessing) || | ||
| 0; | ||
| const spanCountAfter = processedEvent.spans ? processedEvent.spans.length : 0; | ||
|
|
||
| const droppedSpanCount = spanCountBefore - spanCountAfter; | ||
| if (droppedSpanCount > 0) { | ||
| this.recordDroppedEvent('before_send', 'span', droppedSpanCount); | ||
| } | ||
| } | ||
|
|
||
| // None of the Sentry built event processor will update transaction name, | ||
| // so if the transaction name has been changed by an event processor, we know | ||
| // it has to come from custom event processor added by a user | ||
|
|
@@ -973,6 +986,15 @@ function processBeforeSend( | |
| } | ||
|
|
||
| if (beforeSendTransaction) { | ||
| if (event.spans) { | ||
| // We store the # of spans before processing in SDK metadata, | ||
| // so we can compare it afterwards to determine how many spans were dropped | ||
| const spanCountBefore = event.spans.length; | ||
| event.sdkProcessingMetadata = { | ||
| ...event.sdkProcessingMetadata, | ||
| spanCountBeforeProcessing: spanCountBefore, | ||
| }; | ||
| } | ||
| return beforeSendTransaction(event, hint); | ||
| } | ||
| } | ||
|
|
||