diff --git a/dev-packages/e2e-tests/test-applications/nestjs/src/app.service.ts b/dev-packages/e2e-tests/test-applications/nestjs/src/app.service.ts index b6fd70769e1f..f5666bffeb46 100644 --- a/dev-packages/e2e-tests/test-applications/nestjs/src/app.service.ts +++ b/dev-packages/e2e-tests/test-applications/nestjs/src/app.service.ts @@ -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; } /* diff --git a/packages/nestjs/src/span-decorator.ts b/packages/nestjs/src/span-decorator.ts index c56056a26621..b9ef861bc3b2 100644 --- a/packages/nestjs/src/span-decorator.ts +++ b/packages/nestjs/src/span-decorator.ts @@ -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; + const originalMethod = descriptor.value as (...args: any[]) => Promise | any; // function can be sync or async // eslint-disable-next-line @typescript-eslint/no-explicit-any descriptor.value = function (...args: any[]) { @@ -15,7 +15,7 @@ export function SentryTraced(op: string = 'function') { op: op, name: propertyKey, }, - async () => { + () => { return originalMethod.apply(this, args); }, );