Skip to content

chore(various): Tiny code fixes #4391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function eventFromUnknownInput(
exception: unknown,
syntheticException?: Error,
options: {
rejection?: boolean;
isRejection?: boolean;
attachStacktrace?: boolean;
} = {},
): Event {
Expand Down Expand Up @@ -108,7 +108,7 @@ export function eventFromUnknownInput(
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
const objectException = exception as Record<string, unknown>;
event = eventFromPlainObject(objectException, syntheticException, options.rejection);
event = eventFromPlainObject(objectException, syntheticException, options.isRejection);
addExceptionMechanism(event, {
synthetic: true,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function _installGlobalOnErrorHandler(): void {
: _enhanceEventWithInitialFrame(
eventFromUnknownInput(error || msg, undefined, {
attachStacktrace,
rejection: false,
isRejection: false,
}),
url,
line,
Expand Down Expand Up @@ -145,7 +145,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void {
? _eventFromRejectionWithPrimitive(error)
: eventFromUnknownInput(error, undefined, {
attachStacktrace,
rejection: true,
isRejection: true,
});

event.level = 'error';
Expand Down
112 changes: 56 additions & 56 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,69 +312,69 @@ describe('Scope', () => {
expect(processedEvent!.transaction).toEqual('/abc');
});
});
});

test('applyToEvent trace context', async () => {
expect.assertions(1);
const scope = new Scope();
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
} as any;
scope.setSpan(span);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect((processedEvent!.contexts!.trace as any).a).toEqual('b');
test('adds trace context', async () => {
expect.assertions(1);
const scope = new Scope();
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
} as any;
scope.setSpan(span);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect((processedEvent!.contexts!.trace as any).a).toEqual('b');
});
});
});

test('applyToEvent existing trace context in event should be stronger', async () => {
expect.assertions(1);
const scope = new Scope();
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
} as any;
scope.setSpan(span);
const event: Event = {
contexts: {
trace: { a: 'c' },
},
};
return scope.applyToEvent(event).then(processedEvent => {
expect((processedEvent!.contexts!.trace as any).a).toEqual('c');
test('existing trace context in event should take precedence', async () => {
expect.assertions(1);
const scope = new Scope();
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
} as any;
scope.setSpan(span);
const event: Event = {
contexts: {
trace: { a: 'c' },
},
};
return scope.applyToEvent(event).then(processedEvent => {
expect((processedEvent!.contexts!.trace as any).a).toEqual('c');
});
});
});

test('applyToEvent transaction name tag when transaction on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
name: 'fake transaction',
} as any;
transaction.transaction = transaction; // because this is a transaction, its transaction pointer points to itself
scope.setSpan(transaction);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
test('adds `transaction` tag when transaction on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
name: 'fake transaction',
} as any;
transaction.transaction = transaction; // because this is a transaction, its `transaction` pointer points to itself
scope.setSpan(transaction);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
});
});
});

test('applyToEvent transaction name tag when span on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = { name: 'fake transaction' };
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
transaction,
} as any;
scope.setSpan(span);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
test('adds `transaction` tag when span on scope', async () => {
expect.assertions(1);
const scope = new Scope();
const transaction = { name: 'fake transaction' };
const span = {
fake: 'span',
getTraceContext: () => ({ a: 'b' }),
transaction,
} as any;
scope.setSpan(span);
const event: Event = {};
return scope.applyToEvent(event).then(processedEvent => {
expect(processedEvent!.tags!.transaction).toEqual('fake transaction');
});
});
});

Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
import { RewriteFrames } from '@sentry/integrations';
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
import { hasTracingEnabled } from '@sentry/tracing';
import { Event } from '@sentry/types';
import { escapeStringForRegex, logger } from '@sentry/utils';
import * as domainModule from 'domain';
Expand Down Expand Up @@ -113,7 +114,7 @@ function addServerIntegrations(options: NextjsOptions): void {
options.integrations = [defaultRewriteFramesIntegration];
}

if (options.tracesSampleRate !== undefined || options.tracesSampler !== undefined) {
if (hasTracingEnabled(options)) {
const defaultHttpTracingIntegration = new Integrations.Http({ tracing: true });
options.integrations = addIntegration(defaultHttpTracingIntegration, options.integrations, {
Http: { keyPath: '_tracing', value: true },
Expand Down
18 changes: 9 additions & 9 deletions packages/utils/src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@ export function truncate(str: string, max: number = 0): string {
*/
export function snipLine(line: string, colno: number): string {
let newLine = line;
const ll = newLine.length;
if (ll <= 150) {
const lineLength = newLine.length;
if (lineLength <= 150) {
return newLine;
}
if (colno > ll) {
if (colno > lineLength) {
// eslint-disable-next-line no-param-reassign
colno = ll;
colno = lineLength;
}

let start = Math.max(colno - 60, 0);
if (start < 5) {
start = 0;
}

let end = Math.min(start + 140, ll);
if (end > ll - 5) {
end = ll;
let end = Math.min(start + 140, lineLength);
if (end > lineLength - 5) {
end = lineLength;
}
if (end === ll) {
if (end === lineLength) {
start = Math.max(end - 140, 0);
}

newLine = newLine.slice(start, end);
if (start > 0) {
newLine = `'{snip} ${newLine}`;
}
if (end < ll) {
if (end < lineLength) {
newLine += ' {snip}';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
"pack": "npm pack",
"test": "jest --passWithNoTests",
"test": "jest",
"test:watch": "jest --watch"
},
"volta": {
Expand Down