Skip to content
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

fix(nestjs): do not make SentryTraced() decorated functions async #12879

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ export class AppService1 {
}

@SentryTraced('return a string')
getString(): string {
return 'test';
getString(): { result: string } {
return { result: 'test' };
}

async testSpanDecoratorSync() {
return this.getString();
const returned = this.getString();
// Will fail if getString() is async, because returned will be a Promise<>
return returned.result;
}

/*
Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs/src/span-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { startSpan } from '@sentry/node';
export function SentryTraced(op: string = 'function') {
return function (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const originalMethod = descriptor.value as (...args: any[]) => Promise<any>;
const originalMethod = descriptor.value as (...args: any[]) => Promise<any> | any; // function can be sync or async

// eslint-disable-next-line @typescript-eslint/no-explicit-any
descriptor.value = function (...args: any[]) {
Expand All @@ -15,7 +15,7 @@ export function SentryTraced(op: string = 'function') {
op: op,
name: propertyKey,
},
async () => {
() => {
return originalMethod.apply(this, args);
},
);
Expand Down
Loading