From 8da73ac6490b44bda28367860e5f1c4df1a795e4 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 14 Jan 2025 10:15:13 +0100 Subject: [PATCH 1/2] fix(aws-lambda): Avoid overwriting root span name --- packages/aws-serverless/src/sdk.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/aws-serverless/src/sdk.ts b/packages/aws-serverless/src/sdk.ts index ea981a420744..79847adb047e 100644 --- a/packages/aws-serverless/src/sdk.ts +++ b/packages/aws-serverless/src/sdk.ts @@ -220,10 +220,7 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi * @param context AWS Lambda context that will be used to extract some part of the data */ function enhanceScopeWithTransactionData(scope: Scope, context: Context): void { - scope.addEventProcessor(event => { - event.transaction = context.functionName; - return event; - }); + scope.setTransactionName(context.functionName); scope.setTag('server_name', process.env._AWS_XRAY_DAEMON_ADDRESS || process.env.SENTRY_NAME || hostname()); scope.setTag('url', `awslambda:///${context.functionName}`); } From b930e032d102dfca93143a2df160dfba5784fe10 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 14 Jan 2025 10:24:58 +0100 Subject: [PATCH 2/2] adjust tests --- packages/aws-serverless/test/sdk.test.ts | 9 +++------ packages/core/src/scope.ts | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/aws-serverless/test/sdk.test.ts b/packages/aws-serverless/test/sdk.test.ts index 7ab59670cdf2..28b58a830e61 100644 --- a/packages/aws-serverless/test/sdk.test.ts +++ b/packages/aws-serverless/test/sdk.test.ts @@ -18,6 +18,7 @@ const mockScope = { setTag: jest.fn(), setContext: jest.fn(), addEventProcessor: jest.fn(), + setTransactionName: jest.fn(), }; jest.mock('@sentry/node', () => { @@ -81,12 +82,8 @@ const fakeCallback: Callback = (err, result) => { }; function expectScopeSettings() { - expect(mockScope.addEventProcessor).toBeCalledTimes(1); - // Test than an event processor to add `transaction` is registered for the scope - const eventProcessor = mockScope.addEventProcessor.mock.calls[0][0]; - const event: Event = {}; - eventProcessor(event); - expect(event).toEqual({ transaction: 'functionName' }); + expect(mockScope.setTransactionName).toBeCalledTimes(1); + expect(mockScope.setTransactionName).toBeCalledWith('functionName'); expect(mockScope.setTag).toBeCalledWith('server_name', expect.anything()); diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index 53593314be57..6b1238342ee9 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -342,12 +342,12 @@ export class Scope { } /** - * Sets the transaction name on the scope so that the name of the transaction - * (e.g. taken server route or page location) is attached to future events. + * Sets the transaction name on the scope so that the name of e.g. taken server route or + * the page location is attached to future events. * * IMPORTANT: Calling this function does NOT change the name of the currently active - * span. If you want to change the name of the active span, use `span.updateName()` - * instead. + * root span. If you want to change the name of the active root span, use + * `Sentry.updateSpanName(rootSpan, 'new name')` instead. * * By default, the SDK updates the scope's transaction name automatically on sensible * occasions, such as a page navigation or when handling a new request on the server.