Skip to content

Commit 6abb463

Browse files
authored
chore(various): Tiny code fixes (#4391)
A few small changes I stashed away while working on other stuff.
1 parent e32a6e5 commit 6abb463

File tree

6 files changed

+72
-71
lines changed

6 files changed

+72
-71
lines changed

packages/browser/src/eventbuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function eventFromUnknownInput(
5959
exception: unknown,
6060
syntheticException?: Error,
6161
options: {
62-
rejection?: boolean;
62+
isRejection?: boolean;
6363
attachStacktrace?: boolean;
6464
} = {},
6565
): Event {
@@ -108,7 +108,7 @@ export function eventFromUnknownInput(
108108
// it manually. This will allow us to group events based on top-level keys which is much better than creating a new
109109
// group on any key/value change.
110110
const objectException = exception as Record<string, unknown>;
111-
event = eventFromPlainObject(objectException, syntheticException, options.rejection);
111+
event = eventFromPlainObject(objectException, syntheticException, options.isRejection);
112112
addExceptionMechanism(event, {
113113
synthetic: true,
114114
});

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function _installGlobalOnErrorHandler(): void {
9494
: _enhanceEventWithInitialFrame(
9595
eventFromUnknownInput(error || msg, undefined, {
9696
attachStacktrace,
97-
rejection: false,
97+
isRejection: false,
9898
}),
9999
url,
100100
line,
@@ -145,7 +145,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void {
145145
? _eventFromRejectionWithPrimitive(error)
146146
: eventFromUnknownInput(error, undefined, {
147147
attachStacktrace,
148-
rejection: true,
148+
isRejection: true,
149149
});
150150

151151
event.level = 'error';

packages/hub/test/scope.test.ts

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -312,69 +312,69 @@ describe('Scope', () => {
312312
expect(processedEvent!.transaction).toEqual('/abc');
313313
});
314314
});
315-
});
316315

317-
test('applyToEvent trace context', async () => {
318-
expect.assertions(1);
319-
const scope = new Scope();
320-
const span = {
321-
fake: 'span',
322-
getTraceContext: () => ({ a: 'b' }),
323-
} as any;
324-
scope.setSpan(span);
325-
const event: Event = {};
326-
return scope.applyToEvent(event).then(processedEvent => {
327-
expect((processedEvent!.contexts!.trace as any).a).toEqual('b');
316+
test('adds trace context', async () => {
317+
expect.assertions(1);
318+
const scope = new Scope();
319+
const span = {
320+
fake: 'span',
321+
getTraceContext: () => ({ a: 'b' }),
322+
} as any;
323+
scope.setSpan(span);
324+
const event: Event = {};
325+
return scope.applyToEvent(event).then(processedEvent => {
326+
expect((processedEvent!.contexts!.trace as any).a).toEqual('b');
327+
});
328328
});
329-
});
330329

331-
test('applyToEvent existing trace context in event should be stronger', async () => {
332-
expect.assertions(1);
333-
const scope = new Scope();
334-
const span = {
335-
fake: 'span',
336-
getTraceContext: () => ({ a: 'b' }),
337-
} as any;
338-
scope.setSpan(span);
339-
const event: Event = {
340-
contexts: {
341-
trace: { a: 'c' },
342-
},
343-
};
344-
return scope.applyToEvent(event).then(processedEvent => {
345-
expect((processedEvent!.contexts!.trace as any).a).toEqual('c');
330+
test('existing trace context in event should take precedence', async () => {
331+
expect.assertions(1);
332+
const scope = new Scope();
333+
const span = {
334+
fake: 'span',
335+
getTraceContext: () => ({ a: 'b' }),
336+
} as any;
337+
scope.setSpan(span);
338+
const event: Event = {
339+
contexts: {
340+
trace: { a: 'c' },
341+
},
342+
};
343+
return scope.applyToEvent(event).then(processedEvent => {
344+
expect((processedEvent!.contexts!.trace as any).a).toEqual('c');
345+
});
346346
});
347-
});
348347

349-
test('applyToEvent transaction name tag when transaction on scope', async () => {
350-
expect.assertions(1);
351-
const scope = new Scope();
352-
const transaction = {
353-
fake: 'span',
354-
getTraceContext: () => ({ a: 'b' }),
355-
name: 'fake transaction',
356-
} as any;
357-
transaction.transaction = transaction; // because this is a transaction, its transaction pointer points to itself
358-
scope.setSpan(transaction);
359-
const event: Event = {};
360-
return scope.applyToEvent(event).then(processedEvent => {
361-
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
348+
test('adds `transaction` tag when transaction on scope', async () => {
349+
expect.assertions(1);
350+
const scope = new Scope();
351+
const transaction = {
352+
fake: 'span',
353+
getTraceContext: () => ({ a: 'b' }),
354+
name: 'fake transaction',
355+
} as any;
356+
transaction.transaction = transaction; // because this is a transaction, its `transaction` pointer points to itself
357+
scope.setSpan(transaction);
358+
const event: Event = {};
359+
return scope.applyToEvent(event).then(processedEvent => {
360+
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
361+
});
362362
});
363-
});
364363

365-
test('applyToEvent transaction name tag when span on scope', async () => {
366-
expect.assertions(1);
367-
const scope = new Scope();
368-
const transaction = { name: 'fake transaction' };
369-
const span = {
370-
fake: 'span',
371-
getTraceContext: () => ({ a: 'b' }),
372-
transaction,
373-
} as any;
374-
scope.setSpan(span);
375-
const event: Event = {};
376-
return scope.applyToEvent(event).then(processedEvent => {
377-
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
364+
test('adds `transaction` tag when span on scope', async () => {
365+
expect.assertions(1);
366+
const scope = new Scope();
367+
const transaction = { name: 'fake transaction' };
368+
const span = {
369+
fake: 'span',
370+
getTraceContext: () => ({ a: 'b' }),
371+
transaction,
372+
} as any;
373+
scope.setSpan(span);
374+
const event: Event = {};
375+
return scope.applyToEvent(event).then(processedEvent => {
376+
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
377+
});
378378
});
379379
});
380380

packages/nextjs/src/index.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
22
import { RewriteFrames } from '@sentry/integrations';
33
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
4+
import { hasTracingEnabled } from '@sentry/tracing';
45
import { Event } from '@sentry/types';
56
import { escapeStringForRegex, logger } from '@sentry/utils';
67
import * as domainModule from 'domain';
@@ -113,7 +114,7 @@ function addServerIntegrations(options: NextjsOptions): void {
113114
options.integrations = [defaultRewriteFramesIntegration];
114115
}
115116

116-
if (options.tracesSampleRate !== undefined || options.tracesSampler !== undefined) {
117+
if (hasTracingEnabled(options)) {
117118
const defaultHttpTracingIntegration = new Integrations.Http({ tracing: true });
118119
options.integrations = addIntegration(defaultHttpTracingIntegration, options.integrations, {
119120
Http: { keyPath: '_tracing', value: true },

packages/utils/src/string.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@ export function truncate(str: string, max: number = 0): string {
2424
*/
2525
export function snipLine(line: string, colno: number): string {
2626
let newLine = line;
27-
const ll = newLine.length;
28-
if (ll <= 150) {
27+
const lineLength = newLine.length;
28+
if (lineLength <= 150) {
2929
return newLine;
3030
}
31-
if (colno > ll) {
31+
if (colno > lineLength) {
3232
// eslint-disable-next-line no-param-reassign
33-
colno = ll;
33+
colno = lineLength;
3434
}
3535

3636
let start = Math.max(colno - 60, 0);
3737
if (start < 5) {
3838
start = 0;
3939
}
4040

41-
let end = Math.min(start + 140, ll);
42-
if (end > ll - 5) {
43-
end = ll;
41+
let end = Math.min(start + 140, lineLength);
42+
if (end > lineLength - 5) {
43+
end = lineLength;
4444
}
45-
if (end === ll) {
45+
if (end === lineLength) {
4646
start = Math.max(end - 140, 0);
4747
}
4848

4949
newLine = newLine.slice(start, end);
5050
if (start > 0) {
5151
newLine = `'{snip} ${newLine}`;
5252
}
53-
if (end < ll) {
53+
if (end < lineLength) {
5454
newLine += ' {snip}';
5555
}
5656

packages/vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6060
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
6161
"pack": "npm pack",
62-
"test": "jest --passWithNoTests",
62+
"test": "jest",
6363
"test:watch": "jest --watch"
6464
},
6565
"volta": {

0 commit comments

Comments
 (0)