From 28f714526eba37d6b9482035bc45d0fe92ba0723 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Thu, 11 Jul 2024 13:30:09 +0200 Subject: [PATCH 1/3] fix(nestjs): ensure testSpanDecoratorSync checks that wrapped fn is sync --- .../e2e-tests/test-applications/nestjs/src/app.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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..d6efc38ea60a 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; } /* From c6e89ee3fcfe07165a13671b97fe096730f0fbb5 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Thu, 11 Jul 2024 13:33:39 +0200 Subject: [PATCH 2/3] fix(nestjs): do not make SentryTraced() decorated functions async --- packages/nestjs/src/span-decorator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); }, ); From 5842c518c816d6f682b857a3f9a680c78bb28e55 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Thu, 11 Jul 2024 14:38:57 +0200 Subject: [PATCH 3/3] fix: formatting --- .../e2e-tests/test-applications/nestjs/src/app.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d6efc38ea60a..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 @@ -104,7 +104,7 @@ export class AppService1 { } async testSpanDecoratorSync() { - const returned = this.getString() + const returned = this.getString(); // Will fail if getString() is async, because returned will be a Promise<> return returned.result; }