Skip to content

Commit 74b2876

Browse files
committed
refactor(core): Streamline standalone span handling in _onSpanEnded
Drop the redundant `client` and `!_isStandaloneSpan` re-checks: emit `spanEnd` via optional chaining, let the standalone branch own its early return with guard-style returns, and emit `afterSpanEnd` only on the non-standalone path. No behavior change.
1 parent 67acaa5 commit 74b2876

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

packages/core/src/tracing/sentrySpan.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,32 +376,29 @@ export class SentrySpan implements Span {
376376
/** Emit `spanEnd` when the span is ended. */
377377
private _onSpanEnded(): void {
378378
const client = getClient();
379-
if (client) {
380-
client.emit('spanEnd', this);
381-
// Standalone spans send themselves below and must not also be streamed / captured elsewhere.
382-
if (!this._isStandaloneSpan) {
383-
client.emit('afterSpanEnd', this);
384-
}
385-
}
379+
client?.emit('spanEnd', this);
386380

387381
// A standalone span is sent on its own as a v2 streamed span and never becomes/joins a
388382
// transaction, so we send it here and stop.
389383
// TODO(standalone): once we drop the static (transaction) trace lifecycle entirely and everything
390384
// streams, standalone spans are no longer needed (every span streams on its own) and this branch,
391385
// the `_isStandaloneSpan` flag, and the `_convertSpanToTransaction` exclusion can all be removed.
392386
if (this._isStandaloneSpan) {
393-
if (client) {
394-
if (this._sampled) {
395-
sendStandaloneSpan(this, client);
396-
} else {
397-
DEBUG_BUILD &&
398-
debug.log('[Tracing] Discarding standalone span because its trace was not chosen to be sampled.');
399-
client.recordDroppedEvent('sample_rate', 'span');
400-
}
387+
if (!client) return;
388+
389+
if (this._sampled) {
390+
sendStandaloneSpan(this, client);
391+
return;
401392
}
393+
394+
DEBUG_BUILD && debug.log('[Tracing] Discarding standalone span because its trace was not chosen to be sampled.');
395+
client.recordDroppedEvent('sample_rate', 'span');
396+
402397
return;
403398
}
404399

400+
client?.emit('afterSpanEnd', this);
401+
405402
// A segment span is basically the root span of a local span tree.
406403
const rootSpan = getRootSpan(this);
407404
const isSegmentSpan = this === rootSpan;

0 commit comments

Comments
 (0)