Skip to content

Commit 58d2d78

Browse files
authored
chore(various): Small fixes (#3150)
No behavior changes
1 parent 78db3d7 commit 58d2d78

File tree

12 files changed

+48
-38
lines changed

12 files changed

+48
-38
lines changed

packages/core/src/baseclient.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,11 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
490490
// 0.0 === 0% events are sent
491491
// Sampling for transaction happens somewhere else
492492
if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
493-
return SyncPromise.reject(new SentryError('This event has been sampled, will not send event.'));
493+
return SyncPromise.reject(
494+
new SentryError(
495+
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
496+
),
497+
);
494498
}
495499

496500
return this._prepareEvent(event, scope, hint)

packages/core/test/lib/sdk.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('SDK', () => {
5151
expect((DEFAULT_INTEGRATIONS[1].setupOnce as jest.Mock).mock.calls.length).toBe(1);
5252
});
5353

54-
test('not installs default integrations', () => {
54+
test("doesn't install default integrations if told not to", () => {
5555
const DEFAULT_INTEGRATIONS: Integration[] = [
5656
new MockIntegration('MockIntegration 1'),
5757
new MockIntegration('MockIntegration 2'),

packages/node/src/handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ function extractExpressTransactionName(
139139
return info;
140140
}
141141

142-
type TransactionTypes = 'path' | 'methodPath' | 'handler';
142+
type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';
143143

144144
/** JSDoc */
145-
function extractTransaction(req: ExpressRequest, type: boolean | TransactionTypes): string {
145+
function extractTransaction(req: ExpressRequest, type: boolean | TransactionNamingScheme): string {
146146
switch (type) {
147147
case 'path': {
148148
return extractExpressTransactionName(req, { path: true });
@@ -186,7 +186,7 @@ export interface ParseRequestOptions {
186186
ip?: boolean;
187187
request?: boolean | string[];
188188
serverName?: boolean;
189-
transaction?: boolean | TransactionTypes;
189+
transaction?: boolean | TransactionNamingScheme;
190190
user?: boolean | string[];
191191
version?: boolean;
192192
}

packages/node/test/handlers.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core';
22
import { Hub } from '@sentry/hub';
33
import * as sentryHub from '@sentry/hub';
44
import { SpanStatus, Transaction } from '@sentry/tracing';
5-
import { Runtime, Transaction as TransactionType } from '@sentry/types';
5+
import { Runtime } from '@sentry/types';
66
import * as http from 'http';
77
import * as net from 'net';
88

@@ -255,7 +255,7 @@ describe('tracingHandler', () => {
255255

256256
it('pulls status code from the response', done => {
257257
const transaction = new Transaction({ name: 'mockTransaction' });
258-
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as TransactionType);
258+
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as Transaction);
259259
const finishTransaction = jest.spyOn(transaction, 'finish');
260260

261261
sentryTracingMiddleware(req, res, next);
@@ -302,7 +302,7 @@ describe('tracingHandler', () => {
302302

303303
it('closes the transaction when request processing is done', done => {
304304
const transaction = new Transaction({ name: 'mockTransaction' });
305-
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as TransactionType);
305+
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as Transaction);
306306
const finishTransaction = jest.spyOn(transaction, 'finish');
307307

308308
sentryTracingMiddleware(req, res, next);
@@ -321,7 +321,7 @@ describe('tracingHandler', () => {
321321
description: 'reallyCoolHandler',
322322
op: 'middleware',
323323
});
324-
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as TransactionType);
324+
jest.spyOn(sentryCore, 'startTransaction').mockReturnValue(transaction as Transaction);
325325
const finishSpan = jest.spyOn(span, 'finish');
326326
const finishTransaction = jest.spyOn(transaction, 'finish');
327327

packages/serverless/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"fix": "run-s fix:eslint fix:prettier",
6161
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
6262
"fix:eslint": "eslint . --format stylish --fix",
63-
"test": "jest --passWithNoTests",
64-
"test:watch": "jest --watch --passWithNoTests",
63+
"test": "jest",
64+
"test:watch": "jest --watch",
6565
"pack": "npm pack"
6666
},
6767
"volta": {

packages/tracing/src/browser/browsertracing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hub } from '@sentry/hub';
2-
import { EventProcessor, Integration, Transaction as TransactionType, TransactionContext } from '@sentry/types';
2+
import { EventProcessor, Integration, Transaction, TransactionContext } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44

55
import { startIdleTransaction } from '../hubextensions';
@@ -76,7 +76,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7676
* Instrumentation that creates routing change transactions. By default creates
7777
* pageload and navigation transactions.
7878
*/
79-
routingInstrumentation<T extends TransactionType>(
79+
routingInstrumentation<T extends Transaction>(
8080
startTransaction: (context: TransactionContext) => T | undefined,
8181
startTransactionOnPageLoad?: boolean,
8282
startTransactionOnLocationChange?: boolean,
@@ -182,7 +182,7 @@ export class BrowserTracing implements Integration {
182182
}
183183

184184
/** Create routing idle transaction. */
185-
private _createRouteTransaction(context: TransactionContext): TransactionType | undefined {
185+
private _createRouteTransaction(context: TransactionContext): Transaction | undefined {
186186
if (!this._getCurrentHub) {
187187
logger.warn(`[Tracing] Did not create ${context.op} transaction because _getCurrentHub is invalid.`);
188188
return undefined;
@@ -216,7 +216,7 @@ export class BrowserTracing implements Integration {
216216
adjustTransactionDuration(secToMs(maxTransactionDuration), transaction, endTimestamp);
217217
});
218218

219-
return idleTransaction as TransactionType;
219+
return idleTransaction as Transaction;
220220
}
221221
}
222222

packages/tracing/src/browser/metrics.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export interface ResourceEntry extends Record<string, unknown> {
321321
decodedBodySize?: number;
322322
}
323323

324-
/** Create resource related spans */
324+
/** Create resource-related spans */
325325
export function addResourceSpans(
326326
transaction: Transaction,
327327
entry: ResourceEntry,
@@ -375,27 +375,27 @@ function addPerformanceNavigationTiming(
375375
return;
376376
}
377377
_startChild(transaction, {
378-
description: event,
379-
endTimestamp: timeOrigin + msToSec(end),
380378
op: 'browser',
379+
description: event,
381380
startTimestamp: timeOrigin + msToSec(start),
381+
endTimestamp: timeOrigin + msToSec(end),
382382
});
383383
}
384384

385385
/** Create request and response related spans */
386386
function addRequest(transaction: Transaction, entry: Record<string, any>, timeOrigin: number): void {
387387
_startChild(transaction, {
388-
description: 'request',
389-
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
390388
op: 'browser',
389+
description: 'request',
391390
startTimestamp: timeOrigin + msToSec(entry.requestStart as number),
391+
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
392392
});
393393

394394
_startChild(transaction, {
395-
description: 'response',
396-
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
397395
op: 'browser',
396+
description: 'response',
398397
startTimestamp: timeOrigin + msToSec(entry.responseStart as number),
398+
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
399399
});
400400
}
401401

packages/tracing/src/browser/router.ts

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

44
const global = getGlobalObject<Window>();
55

66
/**
77
* Default function implementing pageload and navigation transactions
88
*/
9-
export function defaultRoutingInstrumentation<T extends TransactionType>(
9+
export function defaultRoutingInstrumentation<T extends Transaction>(
1010
startTransaction: (context: TransactionContext) => T | undefined,
1111
startTransactionOnPageLoad: boolean = true,
1212
startTransactionOnLocationChange: boolean = true,

packages/tracing/test/span.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ describe('Span', () => {
127127
traceId: 'c',
128128
});
129129
const serialized = spanB.toJSON();
130-
expect(serialized).toHaveProperty('start_timestamp');
131-
delete (serialized as { start_timestamp: number }).start_timestamp;
132130
expect(serialized).toStrictEqual({
131+
start_timestamp: expect.any(Number),
133132
parent_span_id: 'b',
134133
span_id: 'd',
135134
trace_id: 'c',

packages/utils/src/object.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import { truncate } from './string';
1212
*
1313
* @param source An object that contains a method to be wrapped.
1414
* @param name A name of method to be wrapped.
15-
* @param replacement A function that should be used to wrap a given method.
15+
* @param replacementFactory A function that should be used to wrap a given method, returning the wrapped method which
16+
* will be substituted in for `source[name]`.
1617
* @returns void
1718
*/
18-
export function fill(source: { [key: string]: any }, name: string, replacement: (...args: any[]) => any): void {
19+
export function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {
1920
if (!(name in source)) {
2021
return;
2122
}
2223

2324
const original = source[name] as () => any;
24-
const wrapped = replacement(original) as WrappedFunction;
25+
const wrapped = replacementFactory(original) as WrappedFunction;
2526

2627
// Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
2728
// otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
@@ -56,10 +57,10 @@ export function urlEncode(object: { [key: string]: any }): string {
5657
}
5758

5859
/**
59-
* Transforms any object into an object literal with all it's attributes
60+
* Transforms any object into an object literal with all its attributes
6061
* attached to it.
6162
*
62-
* @param value Initial source that we have to transform in order to be usable by the serializer
63+
* @param value Initial source that we have to transform in order for it to be usable by the serializer
6364
*/
6465
function getWalkSource(
6566
value: any,
@@ -383,7 +384,7 @@ export function dropUndefinedKeys<T>(val: T): T {
383384
}
384385

385386
if (Array.isArray(val)) {
386-
return val.map(dropUndefinedKeys) as any;
387+
return (val as any[]).map(dropUndefinedKeys) as any;
387388
}
388389

389390
return val;

0 commit comments

Comments
 (0)