Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(nestjs): Add support for Symbol as event name #17785

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
chargome merged 1 commit into getsentry:develop from stefanvanderwolf:fix/event-name-symbol
Oct 6, 2025
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
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ export class SentryNestEventInstrumentation extends InstrumentationBase {
return decoratorResult(target, propertyKey, descriptor);
}

function eventNameFromEvent(event: unknown): string {
if (typeof event === 'string') {
return event;
} else if (Array.isArray(event)) {
return event.map(eventNameFromEvent).join(',');
} else return String(event);
}
Copy link

@cursor cursor bot Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Symbol Handling Fails in Event Name Extraction

The eventNameFromEvent function at line 82 uses String(event) in its fallback, which throws a TypeError when the event is a Symbol. This prevents proper Symbol handling, contrary to the PR's intent.

Fix in Cursor Fix in Web

Copy link
Contributor Author

@stefanvanderwolf stefanvanderwolf Sep 25, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const originalHandler = descriptor.value;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const handlerName = originalHandler.name || propertyKey;
let eventName = typeof event === 'string' ? event : String(event);
let eventName = eventNameFromEvent(event);

// Instrument the actual handler
descriptor.value = async function (...args: unknown[]) {
Expand All @@ -93,7 +101,7 @@ export class SentryNestEventInstrumentation extends InstrumentationBase {
eventName = eventData
.map((data: unknown) => {
if (data && typeof data === 'object' && 'event' in data && data.event) {
return data.event;
return eventNameFromEvent(data.event);
}
return '';
})
Expand Down
61 changes: 58 additions & 3 deletions packages/nestjs/test/integrations/nest.test.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,72 @@ describe('Nest', () => {

await descriptor.value();

expect(core.startSpan).toHaveBeenCalled();
expect(core.startSpan).toHaveBeenCalledWith(
expect.objectContaining({
name: 'event test.event',
}),
expect.any(Function),
);
expect(originalHandler).toHaveBeenCalled();
});

it('should wrap array event handlers', async () => {
it('should wrap symbol event handlers', async () => {
const decorated = wrappedOnEvent(Symbol('test.event'));
decorated(mockTarget, 'testMethod', descriptor);

await descriptor.value();

expect(core.startSpan).toHaveBeenCalledWith(
expect.objectContaining({
name: 'event Symbol(test.event)',
}),
expect.any(Function),
);
expect(originalHandler).toHaveBeenCalled();
});

it('should wrap string array event handlers', async () => {
const decorated = wrappedOnEvent(['test.event1', 'test.event2']);
decorated(mockTarget, 'testMethod', descriptor);

await descriptor.value();

expect(core.startSpan).toHaveBeenCalled();
expect(core.startSpan).toHaveBeenCalledWith(
expect.objectContaining({
name: 'event test.event1,test.event2',
}),
expect.any(Function),
);
expect(originalHandler).toHaveBeenCalled();
});

it('should wrap symbol array event handlers', async () => {
const decorated = wrappedOnEvent([Symbol('test.event1'), Symbol('test.event2')]);
decorated(mockTarget, 'testMethod', descriptor);

await descriptor.value();

expect(core.startSpan).toHaveBeenCalledWith(
expect.objectContaining({
name: 'event Symbol(test.event1),Symbol(test.event2)',
}),
expect.any(Function),
);
expect(originalHandler).toHaveBeenCalled();
});

it('should wrap mixed type array event handlers', async () => {
const decorated = wrappedOnEvent([Symbol('test.event1'), 'test.event2', Symbol('test.event3')]);
decorated(mockTarget, 'testMethod', descriptor);

await descriptor.value();

expect(core.startSpan).toHaveBeenCalledWith(
expect.objectContaining({
name: 'event Symbol(test.event1),test.event2,Symbol(test.event3)',
}),
expect.any(Function),
);
expect(originalHandler).toHaveBeenCalled();
});

Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /