Skip to content

Commit a0efb9b

Browse files
committed
replace usages/add eslint ignores in core
1 parent 61be37b commit a0efb9b

File tree

9 files changed

+36
-23
lines changed

9 files changed

+36
-23
lines changed

packages/core/src/scope.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ export class Scope implements ScopeInterface {
334334
// Often, this span (if it exists at all) will be a transaction, but it's not guaranteed to be. Regardless, it will
335335
// have a pointer to the currently-active transaction.
336336
const span = this._span;
337+
// Cannot replace with getRootSpan because getRootSpan returns a span, not a transaction
338+
// Also, this method will be removed anyway.
339+
// eslint-disable-next-line deprecation/deprecation
337340
return span && span.transaction;
338341
}
339342

packages/core/src/server-runtime-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
getDynamicSamplingContextFromClient,
2727
getDynamicSamplingContextFromSpan,
2828
} from './tracing';
29-
import { spanToTraceContext } from './utils/spanUtils';
29+
import { getRootSpan, spanToTraceContext } from './utils/spanUtils';
3030

3131
export interface ServerRuntimeClientOptions extends ClientOptions<BaseTransportOptions> {
3232
platform?: string;
@@ -262,7 +262,7 @@ export class ServerRuntimeClient<
262262
// eslint-disable-next-line deprecation/deprecation
263263
const span = scope.getSpan();
264264
if (span) {
265-
const samplingContext = span.transaction ? getDynamicSamplingContextFromSpan(span) : undefined;
265+
const samplingContext = getRootSpan(span) ? getDynamicSamplingContextFromSpan(span) : undefined;
266266
return [samplingContext, spanToTraceContext(span)];
267267
}
268268

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils';
33

44
import { DEFAULT_ENVIRONMENT } from '../constants';
55
import { getClient, getCurrentScope } from '../exports';
6-
import { spanIsSampled, spanToJSON } from '../utils/spanUtils';
6+
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';
77

88
/**
99
* Creates a dynamic sampling context from a client.
@@ -54,9 +54,8 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
5454
// passing emit=false here to only emit later once the DSC is actually populated
5555
const dsc = getDynamicSamplingContextFromClient(spanToJSON(span).trace_id || '', client, getCurrentScope());
5656

57-
// As long as we use `Transaction`s internally, this should be fine.
58-
// TODO: We need to replace this with a `getRootSpan(span)` function though
59-
const txn = span.transaction as TransactionWithV7FrozenDsc | undefined;
57+
// TODO (v8): Remove v7FrozenDsc as a Transaction will no longer have _frozenDynamicSamplingContext
58+
const txn = getRootSpan(span) as TransactionWithV7FrozenDsc | undefined;
6059
if (!txn) {
6160
return dsc;
6261
}

packages/core/src/tracing/span.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { DEBUG_BUILD } from '../debug-build';
1919
import {
2020
TRACE_FLAG_NONE,
2121
TRACE_FLAG_SAMPLED,
22+
getRootSpan,
2223
spanTimeInputToSeconds,
2324
spanToJSON,
2425
spanToTraceContext,
@@ -305,12 +306,16 @@ export class Span implements SpanInterface {
305306
childSpan.spanRecorder.add(childSpan);
306307
}
307308

308-
childSpan.transaction = this.transaction;
309+
const rootSpan = getRootSpan(this);
310+
// TODO: still set span.transaction here until we have a more permanent solution
311+
// Probably similarly to the weakmap we hold in node-experimental
312+
// eslint-disable-next-line deprecation/deprecation
313+
childSpan.transaction = rootSpan as Transaction;
309314

310-
if (DEBUG_BUILD && childSpan.transaction) {
315+
if (DEBUG_BUILD && rootSpan) {
311316
const opStr = (spanContext && spanContext.op) || '< unknown op >';
312317
const nameStr = spanToJSON(childSpan).description || '< unknown name >';
313-
const idStr = childSpan.transaction.spanContext().spanId;
318+
const idStr = rootSpan.spanContext().spanId;
314319

315320
const logMessage = `[Tracing] Starting '${opStr}' span on transaction '${nameStr}' (${idStr}).`;
316321
logger.log(logMessage);
@@ -417,11 +422,12 @@ export class Span implements SpanInterface {
417422

418423
/** @inheritdoc */
419424
public end(endTimestamp?: SpanTimeInput): void {
425+
const rootSpan = getRootSpan(this);
420426
if (
421427
DEBUG_BUILD &&
422428
// Don't call this for transactions
423-
this.transaction &&
424-
this.transaction.spanContext().spanId !== this._spanId
429+
rootSpan &&
430+
rootSpan.spanContext().spanId !== this._spanId
425431
) {
426432
const logMessage = this._logMessage;
427433
if (logMessage) {

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
6666
this._trimEnd = transactionContext.trimEnd;
6767

6868
// this is because transactions are also spans, and spans have a transaction pointer
69+
// TODO (v8): Replace this with another way to set the root span
70+
// eslint-disable-next-line deprecation/deprecation
6971
this.transaction = this;
7072

7173
// If Dynamic Sampling Context is provided during the creation of the transaction, we freeze it as it usually means

packages/core/src/utils/applyScopeDataToEvent.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Breadcrumb, Event, PropagationContext, ScopeData, Span } from '@sentry/types';
22
import { arrayify } from '@sentry/utils';
33
import { getDynamicSamplingContextFromSpan } from '../tracing/dynamicSamplingContext';
4-
import { spanToJSON, spanToTraceContext } from './spanUtils';
4+
import { getRootSpan, spanToJSON, spanToTraceContext } from './spanUtils';
55

66
/**
77
* Applies data from the scope to the event and runs all event processors on it.
@@ -174,13 +174,13 @@ function applySdkMetadataToEvent(
174174

175175
function applySpanToEvent(event: Event, span: Span): void {
176176
event.contexts = { trace: spanToTraceContext(span), ...event.contexts };
177-
const transaction = span.transaction;
178-
if (transaction) {
177+
const rootSpan = getRootSpan(span);
178+
if (rootSpan) {
179179
event.sdkProcessingMetadata = {
180180
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
181181
...event.sdkProcessingMetadata,
182182
};
183-
const transactionName = spanToJSON(transaction).description;
183+
const transactionName = spanToJSON(rootSpan).description;
184184
if (transactionName) {
185185
event.tags = { transaction: transactionName, ...event.tags };
186186
}

packages/core/src/utils/spanUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@ export function spanIsSampled(span: Span): boolean {
117117
* If the given span has no root span or transaction, `undefined` is returned.
118118
*/
119119
export function getRootSpan(span: Span): Span | undefined {
120+
// TODO (v8): Remove this check and just return span
121+
// eslint-disable-next-line deprecation/deprecation
120122
return span.transaction;
121123
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
2020
});
2121

2222
test('returns the DSC provided during transaction creation', () => {
23-
// eslint-disable-next-line deprecation/deprecation
23+
// eslint-disable-next-line deprecation/deprecation -- using old API on purpose
2424
const transaction = new Transaction({
2525
name: 'tx',
2626
metadata: { dynamicSamplingContext: { environment: 'myEnv' } },
@@ -68,7 +68,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
6868
});
6969

7070
test('returns a new DSC, if no DSC was provided during transaction creation (via new Txn and deprecated metadata)', () => {
71-
// eslint-disable-next-line deprecation/deprecation
71+
// eslint-disable-next-line deprecation/deprecation -- using old API on purpose
7272
const transaction = new Transaction({
7373
name: 'tx',
7474
metadata: {
@@ -92,7 +92,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
9292

9393
describe('Including transaction name in DSC', () => {
9494
test('is not included if transaction source is url', () => {
95-
// eslint-disable-next-line deprecation/deprecation
95+
// eslint-disable-next-line deprecation/deprecation -- using old API on purpose
9696
const transaction = new Transaction({
9797
name: 'tx',
9898
metadata: {
@@ -109,8 +109,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
109109
['is included if transaction source is parameterized route/url', 'route'],
110110
['is included if transaction source is a custom name', 'custom'],
111111
])('%s', (_: string, source) => {
112-
// eslint-disable-next-line deprecation/deprecation
113-
const transaction = new Transaction({
112+
const transaction = startInactiveSpan({
114113
name: 'tx',
115114
metadata: {
116115
...(source && { source: source as TransactionSource }),
@@ -120,7 +119,7 @@ describe('getDynamicSamplingContextFromSpan', () => {
120119
// Only setting the attribute manually because we're directly calling new Transaction()
121120
transaction?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
122121

123-
const dsc = getDynamicSamplingContextFromSpan(transaction);
122+
const dsc = getDynamicSamplingContextFromSpan(transaction!);
124123

125124
expect(dsc.transaction).toEqual('tx');
126125
});

packages/core/test/lib/utils/spanUtils.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { TRACEPARENT_REGEXP, timestampInSeconds } from '@sentry/utils';
2-
import { Transaction } from '../../../build/types';
3-
import { Span, spanToTraceHeader } from '../../../src';
2+
import { Span, Transaction, spanToTraceHeader } from '../../../src';
43
import { getRootSpan, spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../../../src/utils/spanUtils';
54

65
describe('spanToTraceHeader', () => {
@@ -133,6 +132,7 @@ describe('getRootSpan', () => {
133132
it('returns the root span of a span (Span)', () => {
134133
const root = new Span({ name: 'test' });
135134
// @ts-expect-error this is highly illegal and shouldn't happen IRL
135+
// eslint-disable-next-line deprecation/deprecation
136136
root.transaction = root;
137137

138138
// eslint-disable-next-line deprecation/deprecation
@@ -141,6 +141,7 @@ describe('getRootSpan', () => {
141141
});
142142

143143
it('returns the root span of a span (Transaction)', () => {
144+
// eslint-disable-next-line deprecation/deprecation
144145
const root = new Transaction({ name: 'test' });
145146

146147
// eslint-disable-next-line deprecation/deprecation
@@ -149,6 +150,7 @@ describe('getRootSpan', () => {
149150
});
150151

151152
it('returns the span itself if it is a root span', () => {
153+
// eslint-disable-next-line deprecation/deprecation
152154
const span = new Transaction({ name: 'test' });
153155

154156
expect(getRootSpan(span)).toBe(span);

0 commit comments

Comments
 (0)