Skip to content

Commit 3fc76dd

Browse files
authored
ref(general): Small language fixes (#2920)
1 parent a3eed12 commit 3fc76dd

File tree

8 files changed

+40
-41
lines changed

8 files changed

+40
-41
lines changed

packages/node/test/handlers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ describe('tracingHandler', () => {
214214

215215
const transaction = (res as any).__sentry_transaction;
216216

217+
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
217218
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
218219
expect(transaction.parentSpanId).toEqual('1121201211212012');
219220
expect(transaction.sampled).toEqual(false);

packages/tracing/src/browser/browsertracing.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7979
): void;
8080
}
8181

82+
const DEFAULT_BROWSER_TRACING_OPTIONS = {
83+
beforeNavigate: defaultBeforeNavigate,
84+
idleTimeout: DEFAULT_IDLE_TIMEOUT,
85+
markBackgroundTransactions: true,
86+
maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,
87+
routingInstrumentation: defaultRoutingInstrumentation,
88+
startTransactionOnLocationChange: true,
89+
startTransactionOnPageLoad: true,
90+
...defaultRequestInstrumentionOptions,
91+
};
92+
8293
/**
8394
* The Browser Tracing integration automatically instruments browser pageload/navigation
8495
* actions as transactions, and captures requests, metrics and errors as spans.
@@ -93,16 +104,7 @@ export class BrowserTracing implements Integration {
93104
public static id: string = 'BrowserTracing';
94105

95106
/** Browser Tracing integration options */
96-
public options: BrowserTracingOptions = {
97-
beforeNavigate: defaultBeforeNavigate,
98-
idleTimeout: DEFAULT_IDLE_TIMEOUT,
99-
markBackgroundTransactions: true,
100-
maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS,
101-
routingInstrumentation: defaultRoutingInstrumentation,
102-
startTransactionOnLocationChange: true,
103-
startTransactionOnPageLoad: true,
104-
...defaultRequestInstrumentionOptions,
105-
};
107+
public options: BrowserTracingOptions;
106108

107109
/**
108110
* @inheritDoc
@@ -130,7 +132,7 @@ export class BrowserTracing implements Integration {
130132
}
131133

132134
this.options = {
133-
...this.options,
135+
...DEFAULT_BROWSER_TRACING_OPTIONS,
134136
..._options,
135137
tracingOrigins,
136138
};
@@ -179,7 +181,7 @@ export class BrowserTracing implements Integration {
179181
/** Create routing idle transaction. */
180182
private _createRouteTransaction(context: TransactionContext): TransactionType | undefined {
181183
if (!this._getCurrentHub) {
182-
logger.warn(`[Tracing] Did not create ${context.op} idleTransaction due to invalid _getCurrentHub`);
184+
logger.warn(`[Tracing] Did not create ${context.op} transaction because _getCurrentHub is invalid.`);
183185
return undefined;
184186
}
185187

packages/tracing/src/browser/router.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Transaction as TransactionType, TransactionContext } from '@sentry/types';
22
import { addInstrumentationHandler, getGlobalObject, logger } from '@sentry/utils';
33

4-
// type StartTransaction
54
const global = getGlobalObject<Window>();
65

76
/**
8-
* Creates a default router based on
7+
* Default function implementing pageload and navigation transactions
98
*/
109
export function defaultRoutingInstrumentation<T extends TransactionType>(
1110
startTransaction: (context: TransactionContext) => T | undefined,
@@ -28,24 +27,24 @@ export function defaultRoutingInstrumentation<T extends TransactionType>(
2827
addInstrumentationHandler({
2928
callback: ({ to, from }: { to: string; from?: string }) => {
3029
/**
31-
* This early return is there to account for some cases where navigation transaction
32-
* starts right after long running pageload. We make sure that if `from` is undefined
33-
* and that a valid `startingURL` exists, we don't unnecessarily create a navigation transaction.
30+
* This early return is there to account for some cases where a navigation transaction starts right after
31+
* long-running pageload. We make sure that if `from` is undefined and a valid `startingURL` exists, we don't
32+
* create an uneccessary navigation transaction.
3433
*
35-
* This was hard to duplicate, but this behavior stopped as soon as this fix
36-
* was applied. This issue might also only be caused in certain development environments
37-
* where the usage of a hot module reloader is causing errors.
34+
* This was hard to duplicate, but this behavior stopped as soon as this fix was applied. This issue might also
35+
* only be caused in certain development environments where the usage of a hot module reloader is causing
36+
* errors.
3837
*/
3938
if (from === undefined && startingUrl && startingUrl.indexOf(to) !== -1) {
4039
startingUrl = undefined;
4140
return;
4241
}
42+
4343
if (from !== to) {
4444
startingUrl = undefined;
4545
if (activeTransaction) {
46-
logger.log(`[Tracing] finishing current idleTransaction with op: ${activeTransaction.op}`);
47-
// We want to finish all current ongoing idle transactions as we
48-
// are navigating to a new page.
46+
logger.log(`[Tracing] Finishing current transaction with op: ${activeTransaction.op}`);
47+
// If there's an open transaction on the scope, we need to finish it before creating an new one.
4948
activeTransaction.finish();
5049
}
5150
activeTransaction = startTransaction({ name: global.location.pathname, op: 'navigation' });

packages/tracing/src/hubextensions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ function sample<T extends Transaction>(hub: Hub, transaction: T, samplingContext
106106

107107
// at this point we know we're keeping the transaction, whether because of an inherited decision or because it got
108108
// lucky with the dice roll
109-
const experimentsOptions = options._experiments || {};
110-
transaction.initSpanRecorder(experimentsOptions.maxSpans as number);
109+
transaction.initSpanRecorder(options._experiments?.maxSpans as number);
111110

111+
logger.log(`[Tracing] starting ${transaction.op} transaction - ${transaction.name}`);
112112
return transaction;
113113
}
114114
/**
@@ -187,6 +187,10 @@ function isValidSampleRate(rate: unknown): boolean {
187187
* The Hub.startTransaction method delegates to this method to do its work, passing the Hub instance in as `this`.
188188
* Exists as a separate function so that it can be injected into the class as an "extension method."
189189
*
190+
* @param this: The Hub starting the transaction
191+
* @param transactionContext: Data used to configure the transaction
192+
* @param CustomSamplingContext: Optional data to be provided to the `tracesSampler` function (if any)
193+
*
190194
* @returns The new transaction
191195
*
192196
* @see {@link Hub.startTransaction}

packages/tracing/src/utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,9 @@ export function extractTraceparentData(traceparent: string): TraceparentData | u
4343
return undefined;
4444
}
4545

46-
/** Grabs active transaction off scope */
46+
/** Grabs active transaction off scope, if any */
4747
export function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {
48-
if (hub) {
49-
const scope = hub.getScope();
50-
if (scope) {
51-
return scope.getTransaction() as T | undefined;
52-
}
53-
}
54-
55-
return undefined;
48+
return hub?.getScope()?.getTransaction() as T | undefined;
5649
}
5750

5851
/**

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('BrowserTracing', () => {
133133
expect(inst.options.tracingOrigins).toEqual(defaultRequestInstrumentionOptions.tracingOrigins);
134134
});
135135

136-
it('warns and uses default tracing origins if array not given', () => {
136+
it('warns and uses default tracing origins if empty array given', () => {
137137
const inst = createBrowserTracing(true, {
138138
routingInstrumentation: customRoutingInstrumentation,
139139
tracingOrigins: [],
@@ -189,18 +189,18 @@ describe('BrowserTracing', () => {
189189
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1);
190190
});
191191

192-
it('can be a custom value', () => {
192+
it('can override default context values', () => {
193193
const mockBeforeNavigation = jest.fn(ctx => ({
194194
...ctx,
195-
op: 'something-else',
195+
op: 'not-pageload',
196196
}));
197197
createBrowserTracing(true, {
198198
beforeNavigate: mockBeforeNavigation,
199199
routingInstrumentation: customRoutingInstrumentation,
200200
});
201201
const transaction = getActiveTransaction(hub) as IdleTransaction;
202202
expect(transaction).toBeDefined();
203-
expect(transaction.op).toBe('something-else');
203+
expect(transaction.op).toBe('not-pageload');
204204

205205
expect(mockBeforeNavigation).toHaveBeenCalledTimes(1);
206206
});
@@ -308,7 +308,7 @@ describe('BrowserTracing', () => {
308308
mockChangeHistory = () => undefined;
309309
});
310310

311-
it('it is not created automatically', () => {
311+
it('it is not created automatically at startup', () => {
312312
createBrowserTracing(true);
313313
jest.runAllTimers();
314314

packages/tracing/test/hub.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe('Hub', () => {
283283
it('should propagate sampling decision to child spans', () => {
284284
const hub = new Hub(new BrowserClient({ tracesSampleRate: Math.random() }));
285285
const transaction = hub.startTransaction({ name: 'dogpark' });
286-
const child = transaction.startChild({ op: 'test' });
286+
const child = transaction.startChild({ op: 'ball.chase' });
287287

288288
expect(child.sampled).toBe(transaction.sampled);
289289
});

packages/types/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface Scope {
9696
getSpan(): Span | undefined;
9797

9898
/**
99-
* Returns the `Transaction` if there is one
99+
* Returns the `Transaction` attached to the scope (if there is one)
100100
*/
101101
getTransaction(): Transaction | undefined;
102102

0 commit comments

Comments
 (0)