Skip to content

Commit ef7e5b6

Browse files
authored
fix(tracing): Report dropped spans for transactions (#12751)
We already report a client report for dropped standalone spans. However, so far we did not report any for spans dropped for transactions. This PR also emits a client report when `beforeSendSpan` is used to filter a span of a transaction, as well as when the whole transaction is dropped in `beforeSendTransaction`. For now, we _do not_ emit this if users manually drop single spans in e.g. `beforeSendTransaction`, which I'd say is OK for now. Closes #12727
1 parent 506e6ca commit ef7e5b6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/core/src/baseclient.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,18 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
789789
return prepared;
790790
}
791791

792-
const result = processBeforeSend(options, prepared, hint);
792+
const result = processBeforeSend(this, options, prepared, hint);
793793
return _validateBeforeSendResult(result, beforeSendLabel);
794794
})
795795
.then(processedEvent => {
796796
if (processedEvent === null) {
797797
this.recordDroppedEvent('before_send', dataCategory, event);
798+
if (isTransactionEvent(event)) {
799+
const spans = event.spans || [];
800+
// the transaction itself counts as one span, plus all the child spans that are added
801+
const spanCount = 1 + spans.length;
802+
this._outcomes['span'] = (this._outcomes['span'] || 0) + spanCount;
803+
}
798804
throw new SentryError(`${beforeSendLabel} returned \`null\`, will not send event.`, 'log');
799805
}
800806

@@ -914,6 +920,7 @@ function _validateBeforeSendResult(
914920
* Process the matching `beforeSendXXX` callback.
915921
*/
916922
function processBeforeSend(
923+
client: Client,
917924
options: ClientOptions,
918925
event: Event,
919926
hint: EventHint,
@@ -931,6 +938,8 @@ function processBeforeSend(
931938
const processedSpan = beforeSendSpan(span);
932939
if (processedSpan) {
933940
processedSpans.push(processedSpan);
941+
} else {
942+
client.recordDroppedEvent('before_send', 'span');
934943
}
935944
}
936945
event.spans = processedSpans;

0 commit comments

Comments
 (0)