Skip to content
6 changes: 5 additions & 1 deletion packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,11 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
// 0.0 === 0% events are sent
// Sampling for transaction happens somewhere else
if (!isTransaction && typeof sampleRate === 'number' && Math.random() > sampleRate) {
return SyncPromise.reject(new SentryError('This event has been sampled, will not send event.'));
return SyncPromise.reject(
new SentryError(
`Discarding event because it's not included in the random sample (sampling rate = ${sampleRate})`,
),
);
}

return this._prepareEvent(event, scope, hint)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('SDK', () => {
expect((DEFAULT_INTEGRATIONS[1].setupOnce as jest.Mock).mock.calls.length).toBe(1);
});

test('not installs default integrations', () => {
test("doesn't install default integrations if told not to", () => {
const DEFAULT_INTEGRATIONS: Integration[] = [
new MockIntegration('MockIntegration 1'),
new MockIntegration('MockIntegration 2'),
Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ function extractExpressTransactionName(
return info;
}

type TransactionTypes = 'path' | 'methodPath' | 'handler';
type TransactionNamingScheme = 'path' | 'methodPath' | 'handler';

/** JSDoc */
function extractTransaction(req: ExpressRequest, type: boolean | TransactionTypes): string {
function extractTransaction(req: ExpressRequest, type: boolean | TransactionNamingScheme): string {
switch (type) {
case 'path': {
return extractExpressTransactionName(req, { path: true });
Expand Down Expand Up @@ -186,7 +186,7 @@ export interface ParseRequestOptions {
ip?: boolean;
request?: boolean | string[];
serverName?: boolean;
transaction?: boolean | TransactionTypes;
transaction?: boolean | TransactionNamingScheme;
user?: boolean | string[];
version?: boolean;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core';
import { Hub } from '@sentry/hub';
import * as sentryHub from '@sentry/hub';
import { SpanStatus, Transaction } from '@sentry/tracing';
import { Runtime, Transaction as TransactionType } from '@sentry/types';
import { Runtime } from '@sentry/types';
import * as http from 'http';
import * as net from 'net';

Expand Down Expand Up @@ -255,7 +255,7 @@ describe('tracingHandler', () => {

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

sentryTracingMiddleware(req, res, next);
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('tracingHandler', () => {

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

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

Expand Down
4 changes: 2 additions & 2 deletions packages/serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"fix": "run-s fix:eslint fix:prettier",
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"fix:eslint": "eslint . --format stylish --fix",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests",
"test": "jest",
"test:watch": "jest --watch",
"pack": "npm pack"
},
"volta": {
Expand Down
8 changes: 4 additions & 4 deletions packages/tracing/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hub } from '@sentry/hub';
import { EventProcessor, Integration, Transaction as TransactionType, TransactionContext } from '@sentry/types';
import { EventProcessor, Integration, Transaction, TransactionContext } from '@sentry/types';
import { logger } from '@sentry/utils';

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

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

return idleTransaction as TransactionType;
return idleTransaction as Transaction;
}
}

Expand Down
14 changes: 7 additions & 7 deletions packages/tracing/src/browser/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export interface ResourceEntry extends Record<string, unknown> {
decodedBodySize?: number;
}

/** Create resource related spans */
/** Create resource-related spans */
export function addResourceSpans(
transaction: Transaction,
entry: ResourceEntry,
Expand Down Expand Up @@ -375,27 +375,27 @@ function addPerformanceNavigationTiming(
return;
}
_startChild(transaction, {
description: event,
endTimestamp: timeOrigin + msToSec(end),
op: 'browser',
description: event,
startTimestamp: timeOrigin + msToSec(start),
endTimestamp: timeOrigin + msToSec(end),
});
}

/** Create request and response related spans */
function addRequest(transaction: Transaction, entry: Record<string, any>, timeOrigin: number): void {
_startChild(transaction, {
description: 'request',
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
op: 'browser',
description: 'request',
startTimestamp: timeOrigin + msToSec(entry.requestStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});

_startChild(transaction, {
description: 'response',
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
op: 'browser',
description: 'response',
startTimestamp: timeOrigin + msToSec(entry.responseStart as number),
endTimestamp: timeOrigin + msToSec(entry.responseEnd as number),
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/tracing/src/browser/router.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Transaction as TransactionType, TransactionContext } from '@sentry/types';
import { Transaction, TransactionContext } from '@sentry/types';
import { addInstrumentationHandler, getGlobalObject, logger } from '@sentry/utils';

const global = getGlobalObject<Window>();

/**
* Default function implementing pageload and navigation transactions
*/
export function defaultRoutingInstrumentation<T extends TransactionType>(
export function defaultRoutingInstrumentation<T extends Transaction>(
startTransaction: (context: TransactionContext) => T | undefined,
startTransactionOnPageLoad: boolean = true,
startTransactionOnLocationChange: boolean = true,
Expand Down
3 changes: 1 addition & 2 deletions packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ describe('Span', () => {
traceId: 'c',
});
const serialized = spanB.toJSON();
expect(serialized).toHaveProperty('start_timestamp');
delete (serialized as { start_timestamp: number }).start_timestamp;
expect(serialized).toStrictEqual({
start_timestamp: expect.any(Number),
parent_span_id: 'b',
span_id: 'd',
trace_id: 'c',
Expand Down
13 changes: 7 additions & 6 deletions packages/utils/src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import { truncate } from './string';
*
* @param source An object that contains a method to be wrapped.
* @param name A name of method to be wrapped.
* @param replacement A function that should be used to wrap a given method.
* @param replacementFactory A function that should be used to wrap a given method, returning the wrapped method which
* will be substituted in for `source[name]`.
* @returns void
*/
export function fill(source: { [key: string]: any }, name: string, replacement: (...args: any[]) => any): void {
export function fill(source: { [key: string]: any }, name: string, replacementFactory: (...args: any[]) => any): void {
if (!(name in source)) {
return;
}

const original = source[name] as () => any;
const wrapped = replacement(original) as WrappedFunction;
const wrapped = replacementFactory(original) as WrappedFunction;

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

/**
* Transforms any object into an object literal with all it's attributes
* Transforms any object into an object literal with all its attributes
* attached to it.
*
* @param value Initial source that we have to transform in order to be usable by the serializer
* @param value Initial source that we have to transform in order for it to be usable by the serializer
*/
function getWalkSource(
value: any,
Expand Down Expand Up @@ -383,7 +384,7 @@ export function dropUndefinedKeys<T>(val: T): T {
}

if (Array.isArray(val)) {
return val.map(dropUndefinedKeys) as any;
return (val as any[]).map(dropUndefinedKeys) as any;
}

return val;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isRegExp, isString } from './is';
* Truncates given string to the maximum characters count
*
* @param str An object that contains serializable values
* @param max Maximum number of characters in truncated string
* @param max Maximum number of characters in truncated string (0 = unlimited)
* @returns string Encoded
*/
export function truncate(str: string, max: number = 0): string {
Expand Down
16 changes: 11 additions & 5 deletions packages/utils/test/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { isMatchingPattern, truncate } from '../src/string';

describe('truncate()', () => {
test('it works as expected', () => {
expect(truncate(null, 3)).toEqual(null);
expect(truncate('lolol', 3)).toEqual('lol...');
expect(truncate('lolol', 10)).toEqual('lolol');
expect(truncate('1'.repeat(1000), 300)).toHaveLength(303);
expect(truncate(new Array(1000).join('f'), 0)).toEqual(new Array(1000).join('f'));
expect(truncate(new Array(1000).join('f'), 0)).toEqual(new Array(1000).join('f'));
});

test('should bail out as an identity function when given non-string value', () => {
expect(truncate(null as any, 3)).toEqual(null);
expect(truncate(undefined as any, 3)).toEqual(undefined);
expect(truncate({} as any, 3)).toEqual({});
expect(truncate([] as any, 3)).toEqual([]);
});
});

describe('isMatchingPattern()', () => {
Expand All @@ -33,9 +39,9 @@ describe('isMatchingPattern()', () => {
});

test('should bail out with false when given non-string value', () => {
expect(isMatchingPattern(null, 'foo')).toEqual(false);
expect(isMatchingPattern(undefined, 'foo')).toEqual(false);
expect(isMatchingPattern({}, 'foo')).toEqual(false);
expect(isMatchingPattern([], 'foo')).toEqual(false);
expect(isMatchingPattern(null as any, 'foo')).toEqual(false);
expect(isMatchingPattern(undefined as any, 'foo')).toEqual(false);
expect(isMatchingPattern({} as any, 'foo')).toEqual(false);
expect(isMatchingPattern([] as any, 'foo')).toEqual(false);
});
});