Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3324a90
Merge pull request #9853 from getsentry/master
github-actions[bot] Dec 14, 2023
383c816
build: Enable codecov AI PR review (#9850)
AbhiPrasad Dec 14, 2023
1e8d2b3
ref: Use `getCurrentScope()`/`hub.getScope()` instead of `configureSc…
mydea Dec 15, 2023
da8c9c3
feat(nextjs): Auto instrument generation functions (#9781)
Dec 15, 2023
30bb8b5
fix(utils): Do not use `Event` type in worldwide (#9864)
mydea Dec 15, 2023
ffc4181
ref: Use `getCurrentScope()` / `getClient` instead of `hub.xxx` (#9862)
mydea Dec 15, 2023
5bc9a38
fix(utils): Update `eventFromUnknownInput` to avoid scope pollution &…
mydea Dec 15, 2023
72c3488
ref(node): Refactor node integrations to use `processEvent` (#9018)
mydea Dec 15, 2023
e128936
fix(utils): Support crypto.getRandomValues in old Chromium versions (…
jghinestrosa Dec 15, 2023
53724c5
meta(feedback): Fix syntax error in README (#9875)
billyvg Dec 15, 2023
12c146b
fix(nextjs): Export `createReduxEnhancer` (#9854)
adam187 Dec 18, 2023
db4bef1
ref: Pass client instead of hub to `isSentryRequestUrl` (#9869)
mydea Dec 18, 2023
f2a4caa
feat(core): Update `withScope` to return callback return value (#9866)
mydea Dec 18, 2023
01a4cc9
feat(core): Add type & utility for function-based integrations (#9818)
mydea Dec 18, 2023
c0c5eca
feat(node): Add Hapi Integration (#9539)
onurtemizkan Dec 18, 2023
35906d0
ref: Use `addBreadcrumb` directly & allow to pass hint (#9867)
mydea Dec 18, 2023
f922414
build: Fix linting (#9888)
mydea Dec 18, 2023
e1d3633
ref(serverless): Avoid using `pushScope` (#9883)
mydea Dec 18, 2023
ada32b2
ref(nextjs): Simplify `wrapServerComponentWithSentry` (#9844)
Dec 18, 2023
0efdb21
feat(core): Deprecate `configureScope` (#9887)
mydea Dec 18, 2023
b27c236
feat(core): Deprecate `pushScope` & `popScope` (#9890)
mydea Dec 18, 2023
f121585
feat(nextjs): Connect server component transactions if there is no in…
Dec 18, 2023
8fb1a2f
feat(deno): Support `Deno.CronSchedule` for cron jobs (#9880)
timfish Dec 18, 2023
84299d0
feat(replay): Add `canvas.type` setting (#9877)
billyvg Dec 18, 2023
605fd50
feat(node-experimental): Update to new Scope APIs (#9799)
mydea Dec 19, 2023
32f4bf0
ref(deno): Refactor deno integration to avoid `setupOnce` (#9900)
mydea Dec 19, 2023
91a6b4e
ref(browser): Refactor browser integrations to avoid `setupOnce` (#9898)
mydea Dec 19, 2023
c9552a4
ref(node): Refactor LocalVariables integration to avoid `setupOnce` (…
mydea Dec 19, 2023
4e0c460
chore(sveltekit): Add SvelteKit 2.0 to peer dependencies (#9861)
Lms24 Dec 19, 2023
6d32228
fix(sveltekit): Add conditional exports (#9872)
Lms24 Dec 19, 2023
a856913
fix(remix): Do not capture thrown redirect responses. (#9909)
onurtemizkan Dec 19, 2023
31c769c
test(sveltekit): Add SvelteKit 2.0 E2E test app (#9873)
Lms24 Dec 19, 2023
cef3621
ref(sveltekit): Improve SvelteKit 2.0 404 server error handling (#9901)
Lms24 Dec 19, 2023
cf773fc
fix(sveltekit): Avoid capturing 404 errors on client side (#9902)
Lms24 Dec 19, 2023
9f173e1
meta(changelog): Update changelog for 7.89.0
Dec 19, 2023
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
Prev Previous commit
Next Next commit
fix(utils): Update eventFromUnknownInput to avoid scope pollution &…
… `getCurrentHub` (#9868)

Instead we can pass a client directly, and I refactored the method to
avoid setting extra on the scope, and just set it on the event directly
- as this is also kind of leaking right now, because the extra may also
be applied to other events using the same scope.
  • Loading branch information
mydea authored Dec 15, 2023
commit 5bc9a38726ac567072cca8aa8537e9292234947d
4 changes: 2 additions & 2 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { eventFromMessage, eventFromUnknownInput, logger, resolvedSyncPromise, u
import { BaseClient } from './baseclient';
import { createCheckInEnvelope } from './checkin';
import { DEBUG_BUILD } from './debug-build';
import { getCurrentHub } from './hub';
import { getClient } from './exports';
import type { Scope } from './scope';
import { SessionFlusher } from './sessionflusher';
import { addTracingExtensions, getDynamicSamplingContextFromClient } from './tracing';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ServerRuntimeClient<
* @inheritDoc
*/
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
return resolvedSyncPromise(eventFromUnknownInput(getCurrentHub, this._options.stackParser, exception, hint));
return resolvedSyncPromise(eventFromUnknownInput(getClient(), this._options.stackParser, exception, hint));
}

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/deno/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ServerRuntimeClient } from '@sentry/core';
import { flush, getCurrentHub } from '@sentry/core';
import { getClient, getCurrentHub, getCurrentScope } from '@sentry/core';
import { flush } from '@sentry/core';
import type { Event, Hub, Integration, Primitive, StackParser } from '@sentry/types';
import { eventFromUnknownInput, isPrimitive } from '@sentry/utils';

Expand Down Expand Up @@ -70,7 +71,7 @@ function installGlobalErrorHandler(): void {
const [hub, stackParser] = getHubAndOptions();
const { message, error } = data;

const event = eventFromUnknownInput(getCurrentHub, stackParser, error || message);
const event = eventFromUnknownInput(getClient(), stackParser, error || message);

event.level = 'fatal';

Expand Down Expand Up @@ -113,7 +114,7 @@ function installGlobalUnhandledRejectionHandler(): void {

const event = isPrimitive(error)
? eventFromRejectionWithPrimitive(error)
: eventFromUnknownInput(getCurrentHub, stackParser, error, undefined);
: eventFromUnknownInput(getClient(), stackParser, error, undefined);

event.level = 'fatal';

Expand Down
85 changes: 53 additions & 32 deletions packages/node/test/eventbuilders.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
import type { Client } from '@sentry/types';
import type { Hub } from '@sentry/types';
import { eventFromUnknownInput } from '@sentry/utils';

import { Scope, defaultStackParser, getCurrentHub } from '../src';
import { defaultStackParser } from '../src';

const testScope = new Scope();

jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
...original,
getCurrentHub(): {
getClient(): Client;
getScope(): Scope;
} {
return {
getClient(): any {
return {
getOptions(): any {
return { normalizeDepth: 6 };
describe('eventFromUnknownInput', () => {
test('uses normalizeDepth from init options', () => {
const deepObject = {
a: {
b: {
c: {
d: {
e: {
f: {
g: 'foo',
},
},
},
};
},
getScope(): Scope {
return testScope;
},
},
};
},
};
});
},
};

afterEach(() => {
jest.resetAllMocks();
});
const client = {
getOptions(): any {
return { normalizeDepth: 6 };
},
} as any;
const event = eventFromUnknownInput(client, defaultStackParser, deepObject);

describe('eventFromUnknownInput', () => {
test('uses normalizeDepth from init options', () => {
const serializedObject = event.extra?.__serialized__;
expect(serializedObject).toBeDefined();
expect(serializedObject).toEqual({
a: {
b: {
c: {
d: {
e: {
f: '[Object]',
},
},
},
},
},
});
});

test('uses normalizeDepth from init options (passing getCurrentHub)', () => {
const deepObject = {
a: {
b: {
Expand All @@ -51,9 +62,19 @@ describe('eventFromUnknownInput', () => {
},
};

eventFromUnknownInput(getCurrentHub, defaultStackParser, deepObject);
const getCurrentHub = jest.fn(() => {
return {
getClient: () => ({
getOptions(): any {
return { normalizeDepth: 6 };
},
}),
} as unknown as Hub;
});

const event = eventFromUnknownInput(getCurrentHub, defaultStackParser, deepObject);

const serializedObject = (testScope as any)._extra.__serialized__;
const serializedObject = event.extra?.__serialized__;
expect(serializedObject).toBeDefined();
expect(serializedObject).toEqual({
a: {
Expand Down
20 changes: 15 additions & 5 deletions packages/utils/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type {
Client,
Event,
EventHint,
Exception,
Extras,
Hub,
Mechanism,
Severity,
Expand Down Expand Up @@ -61,14 +63,18 @@ function getMessageForObject(exception: object): string {

/**
* Builds and Event from a Exception
*
* TODO(v8): Remove getHub fallback
* @hidden
*/
export function eventFromUnknownInput(
getCurrentHub: () => Hub,
getHubOrClient: (() => Hub) | Client | undefined,
stackParser: StackParser,
exception: unknown,
hint?: EventHint,
): Event {
const client = typeof getHubOrClient === 'function' ? getHubOrClient().getClient() : getHubOrClient;

let ex: unknown = exception;
const providedMechanism: Mechanism | undefined =
hint && hint.data && (hint.data as { mechanism: Mechanism }).mechanism;
Expand All @@ -77,12 +83,12 @@ export function eventFromUnknownInput(
type: 'generic',
};

let extras: Extras | undefined;

if (!isError(exception)) {
if (isPlainObject(exception)) {
const hub = getCurrentHub();
const client = hub.getClient();
const normalizeDepth = client && client.getOptions().normalizeDepth;
hub.getScope().setExtra('__serialized__', normalizeToSize(exception, normalizeDepth));
extras = { ['__serialized__']: normalizeToSize(exception as Record<string, unknown>, normalizeDepth) };

const message = getMessageForObject(exception);
ex = (hint && hint.syntheticException) || new Error(message);
Expand All @@ -96,12 +102,16 @@ export function eventFromUnknownInput(
mechanism.synthetic = true;
}

const event = {
const event: Event = {
exception: {
values: [exceptionFromError(stackParser, ex as Error)],
},
};

if (extras) {
event.extra = extras;
}

addExceptionTypeValue(event, undefined, undefined);
addExceptionMechanism(event, mechanism);

Expand Down
5 changes: 5 additions & 0 deletions packages/utils/test/eventbuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ describe('eventFromUnknownInput', () => {
const event = eventFromUnknownInput(getCurrentHub, stackParser, { foo: { bar: 'baz' }, message: 'Some message' });
expect(event.exception?.values?.[0].value).toBe('Some message');
});

test('passing client directly', () => {
const event = eventFromUnknownInput(undefined, stackParser, { foo: { bar: 'baz' }, prop: 1 });
expect(event.exception?.values?.[0].value).toBe('Object captured as exception with keys: foo, prop');
});
});