Skip to content

Commit 4de88db

Browse files
authored
Merge pull request #10759 from getsentry/fn/backport-fixes
meta: Backport fixes to v7
2 parents a77153c + f40cba0 commit 4de88db

File tree

11 files changed

+53
-48
lines changed

11 files changed

+53
-48
lines changed

packages/core/src/tracing/span.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ export class Span implements SpanInterface {
105105

106106
protected _traceId: string;
107107
protected _spanId: string;
108-
protected _parentSpanId?: string;
108+
protected _parentSpanId?: string | undefined;
109109
protected _sampled: boolean | undefined;
110-
protected _name?: string;
110+
protected _name?: string | undefined;
111111
protected _attributes: SpanAttributes;
112112
/** Epoch timestamp in seconds when the span started. */
113113
protected _startTime: number;
114114
/** Epoch timestamp in seconds when the span ended. */
115-
protected _endTime?: number;
115+
protected _endTime?: number | undefined;
116116
/** Internal keeper of the status */
117-
protected _status?: SpanStatusType | string;
117+
protected _status?: SpanStatusType | string | undefined;
118118

119119
private _logMessage?: string;
120120

@@ -385,7 +385,7 @@ export class Span implements SpanInterface {
385385
*/
386386
public startChild(
387387
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>,
388-
): Span {
388+
): SpanInterface {
389389
const childSpan = new Span({
390390
...spanContext,
391391
parentSpanId: this._spanId,

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Transaction extends SpanClass implements TransactionInterface {
3535

3636
private _contexts: Contexts;
3737

38-
private _trimEnd?: boolean;
38+
private _trimEnd?: boolean | undefined;
3939

4040
// DO NOT yet remove this property, it is used in a hack for v7 backwards compatibility.
4141
private _frozenDynamicSamplingContext: Readonly<Partial<DynamicSamplingContext>> | undefined;

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
257257
isPageloadTransaction, // should wait for finish signal if it's a pageload transaction
258258
);
259259

260-
if (isPageloadTransaction) {
260+
if (isPageloadTransaction && WINDOW.document) {
261261
WINDOW.document.addEventListener('readystatechange', () => {
262262
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {
263263
idleTransaction.sendAutoFinishSignal();
@@ -307,7 +307,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
307307
}
308308

309309
let activeSpan: Span | undefined;
310-
let startingUrl: string | undefined = WINDOW.location.href;
310+
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;
311311

312312
if (client.on) {
313313
client.on('startNavigationSpan', (context: StartSpanOptions) => {
@@ -335,7 +335,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
335335
});
336336
}
337337

338-
if (options.instrumentPageLoad && client.emit) {
338+
if (options.instrumentPageLoad && client.emit && WINDOW.location) {
339339
const context: StartSpanOptions = {
340340
name: WINDOW.location.pathname,
341341
// pageload should always start at timeOrigin (and needs to be in s, not ms)
@@ -348,7 +348,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
348348
startBrowserTracingPageLoadSpan(client, context);
349349
}
350350

351-
if (options.instrumentNavigation && client.emit) {
351+
if (options.instrumentNavigation && client.emit && WINDOW.location) {
352352
addHistoryInstrumentationHandler(({ to, from }) => {
353353
/**
354354
* This early return is there to account for some cases where a navigation transaction starts right after

packages/tracing/test/integrations/apollo-nestjs.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { Hub, Scope } from '@sentry/core';
3+
import { Hub, Scope, Span as SpanClass } from '@sentry/core';
4+
import type { Span } from '@sentry/types';
45
import { logger } from '@sentry/utils';
56

6-
import { Integrations, Span } from '../../src';
7+
import { Integrations } from '../../src';
78
import { getTestClient } from '../testutils';
89

910
type ApolloResolverGroup = {
@@ -79,7 +80,7 @@ describe('setupOnce', () => {
7980

8081
beforeEach(() => {
8182
scope = new Scope();
82-
parentSpan = new Span();
83+
parentSpan = new SpanClass();
8384
childSpan = parentSpan.startChild();
8485
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(parentSpan);
8586
jest.spyOn(scope, 'setSpan');

packages/tracing/test/integrations/apollo.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { Hub, Scope } from '@sentry/core';
3+
import { Hub, Scope, Span as SpanClass } from '@sentry/core';
4+
import type { Span } from '@sentry/types';
45
import { logger } from '@sentry/utils';
56

6-
import { Integrations, Span } from '../../src';
7+
import { Integrations } from '../../src';
78
import { getTestClient } from '../testutils';
89

910
type ApolloResolverGroup = {
@@ -79,7 +80,7 @@ describe('setupOnce', () => {
7980

8081
beforeEach(() => {
8182
scope = new Scope();
82-
parentSpan = new Span();
83+
parentSpan = new SpanClass();
8384
childSpan = parentSpan.startChild();
8485
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(parentSpan);
8586
jest.spyOn(scope, 'setSpan');

packages/tracing/test/integrations/graphql.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { Hub, Scope } from '@sentry/core';
3+
import { Hub, Scope, Span as SpanClass } from '@sentry/core';
4+
import type { Span } from '@sentry/types';
45
import { logger } from '@sentry/utils';
56

6-
import { Integrations, Span } from '../../src';
7+
import { Integrations } from '../../src';
78
import { getTestClient } from '../testutils';
89

910
const GQLExecute = {
@@ -41,7 +42,7 @@ describe('setupOnce', () => {
4142

4243
beforeEach(() => {
4344
scope = new Scope();
44-
parentSpan = new Span();
45+
parentSpan = new SpanClass();
4546
childSpan = parentSpan.startChild();
4647
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(parentSpan);
4748
jest.spyOn(scope, 'setSpan');

packages/tracing/test/integrations/node/mongo.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { Hub, Scope } from '@sentry/core';
3+
import { Hub, Scope, Span as SpanClass } from '@sentry/core';
4+
import type { Span } from '@sentry/types';
45
import { logger } from '@sentry/utils';
56

6-
import { Integrations, Span } from '../../../src';
7+
import { Integrations } from '../../../src';
78
import { getTestClient } from '../../testutils';
89

910
class Collection {
@@ -63,7 +64,7 @@ describe('patchOperation()', () => {
6364

6465
beforeEach(() => {
6566
scope = new Scope();
66-
parentSpan = new Span();
67+
parentSpan = new SpanClass();
6768
childSpan = parentSpan.startChild();
6869
testClient = getTestClient({});
6970
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(parentSpan);

packages/tracing/test/integrations/node/postgres.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable deprecation/deprecation */
22
/* eslint-disable @typescript-eslint/unbound-method */
3-
import { Hub, Scope } from '@sentry/core';
3+
import { Hub, Scope, Span as SpanClass } from '@sentry/core';
4+
import type { Span } from '@sentry/types';
45
import { loadModule, logger } from '@sentry/utils';
56
import pg from 'pg';
67

7-
import { Integrations, Span } from '../../../src';
8+
import { Integrations } from '../../../src';
89
import { getTestClient } from '../../testutils';
910

1011
class PgClient {
@@ -63,7 +64,7 @@ describe('setupOnce', () => {
6364

6465
beforeEach(() => {
6566
scope = new Scope();
66-
parentSpan = new Span();
67+
parentSpan = new SpanClass();
6768
childSpan = parentSpan.startChild();
6869
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(parentSpan);
6970
jest.spyOn(parentSpan, 'startChild').mockReturnValueOnce(childSpan);
@@ -134,7 +135,7 @@ describe('setupOnce', () => {
134135

135136
it('does not attempt resolution when module is passed directly', async () => {
136137
const scope = new Scope();
137-
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(new Span());
138+
jest.spyOn(scope, 'getSpan').mockReturnValueOnce(new SpanClass());
138139

139140
new Integrations.Postgres({ module: mockModule }).setupOnce(
140141
() => undefined,

packages/tracing/test/span.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ describe('Span', () => {
5757
const span2 = transaction.startChild();
5858
const span3 = span2.startChild();
5959
span3.end();
60-
expect(transaction.spanRecorder).toBe(span2.spanRecorder);
61-
expect(transaction.spanRecorder).toBe(span3.spanRecorder);
60+
expect(transaction.spanRecorder).toBe((span2 as Span).spanRecorder);
61+
expect(transaction.spanRecorder).toBe((span3 as Span).spanRecorder);
6262
});
6363
});
6464

packages/types/src/span.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,43 +104,43 @@ export interface SpanContext {
104104
*
105105
* @deprecated Use `name` instead.
106106
*/
107-
description?: string;
107+
description?: string | undefined;
108108

109109
/**
110110
* Human-readable identifier for the span. Alias for span.description.
111111
*/
112-
name?: string;
112+
name?: string | undefined;
113113

114114
/**
115115
* Operation of the Span.
116116
*/
117-
op?: string;
117+
op?: string | undefined;
118118

119119
/**
120120
* Completion status of the Span.
121121
* See: {@sentry/tracing SpanStatus} for possible values
122122
*/
123-
status?: string;
123+
status?: string | undefined;
124124

125125
/**
126126
* Parent Span ID
127127
*/
128-
parentSpanId?: string;
128+
parentSpanId?: string | undefined;
129129

130130
/**
131131
* Was this span chosen to be sent as part of the sample?
132132
*/
133-
sampled?: boolean;
133+
sampled?: boolean | undefined;
134134

135135
/**
136136
* Span ID
137137
*/
138-
spanId?: string;
138+
spanId?: string | undefined;
139139

140140
/**
141141
* Trace ID
142142
*/
143-
traceId?: string;
143+
traceId?: string | undefined;
144144

145145
/**
146146
* Tags of the Span.
@@ -162,22 +162,22 @@ export interface SpanContext {
162162
/**
163163
* Timestamp in seconds (epoch time) indicating when the span started.
164164
*/
165-
startTimestamp?: number;
165+
startTimestamp?: number | undefined;
166166

167167
/**
168168
* Timestamp in seconds (epoch time) indicating when the span ended.
169169
*/
170-
endTimestamp?: number;
170+
endTimestamp?: number | undefined;
171171

172172
/**
173173
* The instrumenter that created this span.
174174
*/
175-
instrumenter?: Instrumenter;
175+
instrumenter?: Instrumenter | undefined;
176176

177177
/**
178178
* The origin of the span, giving context about what created the span.
179179
*/
180-
origin?: SpanOrigin;
180+
origin?: SpanOrigin | undefined;
181181
}
182182

183183
/** Span holding trace_id, span_id */
@@ -194,7 +194,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
194194
* @deprecated Use `startSpan()` functions to set, `span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'op')
195195
* to update and `spanToJSON().op` to read the op instead
196196
*/
197-
op?: string;
197+
op?: string | undefined;
198198

199199
/**
200200
* The ID of the span.
@@ -207,7 +207,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
207207
*
208208
* @deprecated Use `spanToJSON(span).parent_span_id` instead.
209209
*/
210-
parentSpanId?: string;
210+
parentSpanId?: string | undefined;
211211

212212
/**
213213
* The ID of the trace.
@@ -219,7 +219,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
219219
* Was this span chosen to be sent as part of the sample?
220220
* @deprecated Use `isRecording()` instead.
221221
*/
222-
sampled?: boolean;
222+
sampled?: boolean | undefined;
223223

224224
/**
225225
* Timestamp in seconds (epoch time) indicating when the span started.
@@ -231,7 +231,7 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
231231
* Timestamp in seconds (epoch time) indicating when the span ended.
232232
* @deprecated Use `spanToJSON()` instead.
233233
*/
234-
endTimestamp?: number;
234+
endTimestamp?: number | undefined;
235235

236236
/**
237237
* Tags for the span.
@@ -271,14 +271,14 @@ export interface Span extends Omit<SpanContext, 'op' | 'status' | 'origin'> {
271271
*
272272
* @deprecated Use `.setStatus` to set or update and `spanToJSON()` to read the status.
273273
*/
274-
status?: string;
274+
status?: string | undefined;
275275

276276
/**
277277
* The origin of the span, giving context about what created the span.
278278
*
279279
* @deprecated Use `startSpan` function to set and `spanToJSON(span).origin` to read the origin instead.
280280
*/
281-
origin?: SpanOrigin;
281+
origin?: SpanOrigin | undefined;
282282

283283
/**
284284
* Get context data for this span.

packages/types/src/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export interface TransactionContext extends SpanContext {
2121
* accounted for in child spans, like what happens in the idle transaction Tracing integration, where we finish the
2222
* transaction after a given "idle time" and we don't want this "idle time" to be part of the transaction.
2323
*/
24-
trimEnd?: boolean;
24+
trimEnd?: boolean | undefined;
2525

2626
/**
2727
* If this transaction has a parent, the parent's sampling decision
2828
*/
29-
parentSampled?: boolean;
29+
parentSampled?: boolean | undefined;
3030

3131
/**
3232
* Metadata associated with the transaction, for internal SDK use.

0 commit comments

Comments
 (0)