Skip to content

Commit 1cdab67

Browse files
authored
feat: Export getSpanDescendants() everywhere (#10924)
This can be used instead of `spanRecorder` going forward.
1 parent cd9b896 commit 1cdab67

File tree

15 files changed

+19
-8
lines changed

15 files changed

+19
-8
lines changed

packages/astro/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export {
6666
startInactiveSpan,
6767
startSpanManual,
6868
withActiveSpan,
69+
getSpanDescendants,
6970
continueTrace,
7071
cron,
7172
parameterize,

packages/browser/src/index.bundle.tracing.replay.feedback.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
startInactiveSpan,
1313
startSpanManual,
1414
withActiveSpan,
15+
getSpanDescendants,
1516
} from '@sentry/core';
1617

1718
export { feedbackIntegration, replayIntegration, browserTracingIntegration, addTracingExtensions };

packages/browser/src/index.bundle.tracing.replay.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
startInactiveSpan,
1313
startSpanManual,
1414
withActiveSpan,
15+
getSpanDescendants,
1516
} from '@sentry/core';
1617

1718
export {

packages/browser/src/index.bundle.tracing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export {
1212
startInactiveSpan,
1313
startSpanManual,
1414
withActiveSpan,
15+
getSpanDescendants,
1516
} from '@sentry/core';
1617

1718
export {

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export {
6767
startInactiveSpan,
6868
startSpanManual,
6969
withActiveSpan,
70+
getSpanDescendants,
7071
setMeasurement,
7172
// eslint-disable-next-line deprecation/deprecation
7273
getActiveTransaction,

packages/bun/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export {
6868
startInactiveSpan,
6969
startSpanManual,
7070
withActiveSpan,
71+
getSpanDescendants,
7172
continueTrace,
7273
metricsDefault as metrics,
7374
functionToStringIntegration,

packages/core/src/tracing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type { BeforeFinishCallback } from './idletransaction';
44
export { SentrySpan } from './sentrySpan';
55
export { Transaction } from './transaction';
66
// eslint-disable-next-line deprecation/deprecation
7-
export { getActiveTransaction, getActiveSpan } from './utils';
7+
export { getActiveTransaction, getActiveSpan, getSpanDescendants } from './utils';
88
export {
99
setHttpStatus,
1010
getSpanStatusFromHttpCode,

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE
2222
import { spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
2323
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
2424
import { SentrySpan, SpanRecorder } from './sentrySpan';
25-
import { getCapturedScopesOnSpan, getSpanTree } from './utils';
25+
import { getCapturedScopesOnSpan, getSpanDescendants } from './utils';
2626

2727
/** JSDoc */
2828
export class Transaction extends SentrySpan implements TransactionInterface {
@@ -255,7 +255,7 @@ export class Transaction extends SentrySpan implements TransactionInterface {
255255
}
256256

257257
// The transaction span itself should be filtered out
258-
const finishedSpans = getSpanTree(this).filter(span => span !== this);
258+
const finishedSpans = getSpanDescendants(this).filter(span => span !== this);
259259

260260
if (this._trimEnd && finishedSpans.length > 0) {
261261
const endTimes = finishedSpans.map(span => spanToJSON(span).timestamp).filter(Boolean) as number[];

packages/core/src/tracing/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: S
4949
}
5050

5151
/**
52-
* Obtains the entire span tree, meaning a span + all of its descendants for a particular span.
52+
* Returns an array of the given span and all of its descendants.
5353
*/
54-
export function getSpanTree(span: SpanWithPotentialChildren): Span[] {
54+
export function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {
5555
const resultSet = new Set<Span>();
5656

5757
function addSpanChildren(span: SpanWithPotentialChildren): void {

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
startSpan,
2020
startSpanManual,
2121
} from '../../../src/tracing';
22-
import { getSpanTree } from '../../../src/tracing/utils';
22+
import { getSpanDescendants } from '../../../src/tracing/utils';
2323
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
2424

2525
beforeAll(() => {
@@ -173,7 +173,7 @@ describe('startSpan', () => {
173173
}
174174

175175
expect(_span).toBeDefined();
176-
const spans = getSpanTree(_span!);
176+
const spans = getSpanDescendants(_span!);
177177

178178
expect(spans).toHaveLength(2);
179179
expect(spanToJSON(spans[1]).description).toEqual('SELECT * from users');
@@ -200,7 +200,7 @@ describe('startSpan', () => {
200200
}
201201

202202
expect(_span).toBeDefined();
203-
const spans = getSpanTree(_span!);
203+
const spans = getSpanDescendants(_span!);
204204

205205
expect(spans).toHaveLength(2);
206206
expect(spanToJSON(spans[1]).op).toEqual('db.query');

packages/node-experimental/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export {
8686
Scope,
8787
setMeasurement,
8888
continueTrace,
89+
getSpanDescendants,
8990
parameterize,
9091
getCurrentScope,
9192
getIsolationScope,

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export {
6767
startInactiveSpan,
6868
startSpanManual,
6969
withActiveSpan,
70+
getSpanDescendants,
7071
continueTrace,
7172
parameterize,
7273
functionToStringIntegration,

packages/remix/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export {
7777
startSpanManual,
7878
startInactiveSpan,
7979
withActiveSpan,
80+
getSpanDescendants,
8081
continueTrace,
8182
isInitialized,
8283
cron,

packages/serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export {
7070
startInactiveSpan,
7171
startSpanManual,
7272
withActiveSpan,
73+
getSpanDescendants,
7374
continueTrace,
7475
parameterize,
7576
requestDataIntegration,

packages/vercel-edge/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export {
6767
startInactiveSpan,
6868
startSpanManual,
6969
withActiveSpan,
70+
getSpanDescendants,
7071
continueTrace,
7172
metrics,
7273
functionToStringIntegration,

0 commit comments

Comments
 (0)