Skip to content
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 @@ -116,4 +116,9 @@ export class AppController {
testServiceWithCanActivate() {
return this.appService.canActivate();
}

@Get('test-function-name')
testFunctionName() {
return this.appService.getFunctionName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class AppService {
return { result: 'test' };
}

@SentryTraced('return the function name')
getFunctionName(): { result: string } {
return { result: this.getFunctionName.name };
}

async testSpanDecoratorSync() {
const returned = this.getString();
// Will fail if getString() is async, because returned will be a Promise<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ test('Transaction includes span and correct value for decorated sync function',
]),
);
});

test('preserves original function name on decorated functions', async ({ baseURL }) => {
const response = await fetch(`${baseURL}/test-function-name`);
const body = await response.json();

expect(body.result).toEqual('getFunctionName');
});
9 changes: 9 additions & 0 deletions packages/nestjs/src/decorators/sentry-traced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export function SentryTraced(op: string = 'function') {
},
);
};

// preserve the original name on the decorated function
Object.defineProperty(descriptor.value, 'name', {
value: originalMethod.name,
configurable: true,
enumerable: true,
writable: true,
});

return descriptor;
};
}
Loading