Skip to content

Commit 3e14f6b

Browse files
authored
fix(aws-lambda): Avoid overwriting root span name (#15000)
Calls `scope.updateTransactionName` which updates the error location "transaction" name on the scope. This is only applied to error events during event processing, so the intention is clearer than adding an event processor.
1 parent 4af179e commit 3e14f6b

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

packages/aws-serverless/src/sdk.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ function enhanceScopeWithEnvironmentData(scope: Scope, context: Context, startTi
220220
* @param context AWS Lambda context that will be used to extract some part of the data
221221
*/
222222
function enhanceScopeWithTransactionData(scope: Scope, context: Context): void {
223-
scope.addEventProcessor(event => {
224-
event.transaction = context.functionName;
225-
return event;
226-
});
223+
scope.setTransactionName(context.functionName);
227224
scope.setTag('server_name', process.env._AWS_XRAY_DAEMON_ADDRESS || process.env.SENTRY_NAME || hostname());
228225
scope.setTag('url', `awslambda:///${context.functionName}`);
229226
}

packages/aws-serverless/test/sdk.test.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const mockScope = {
1818
setTag: jest.fn(),
1919
setContext: jest.fn(),
2020
addEventProcessor: jest.fn(),
21+
setTransactionName: jest.fn(),
2122
};
2223

2324
jest.mock('@sentry/node', () => {
@@ -81,12 +82,8 @@ const fakeCallback: Callback = (err, result) => {
8182
};
8283

8384
function expectScopeSettings() {
84-
expect(mockScope.addEventProcessor).toBeCalledTimes(1);
85-
// Test than an event processor to add `transaction` is registered for the scope
86-
const eventProcessor = mockScope.addEventProcessor.mock.calls[0][0];
87-
const event: Event = {};
88-
eventProcessor(event);
89-
expect(event).toEqual({ transaction: 'functionName' });
85+
expect(mockScope.setTransactionName).toBeCalledTimes(1);
86+
expect(mockScope.setTransactionName).toBeCalledWith('functionName');
9087

9188
expect(mockScope.setTag).toBeCalledWith('server_name', expect.anything());
9289

packages/core/src/scope.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ export class Scope {
342342
}
343343

344344
/**
345-
* Sets the transaction name on the scope so that the name of the transaction
346-
* (e.g. taken server route or page location) is attached to future events.
345+
* Sets the transaction name on the scope so that the name of e.g. taken server route or
346+
* the page location is attached to future events.
347347
*
348348
* IMPORTANT: Calling this function does NOT change the name of the currently active
349-
* span. If you want to change the name of the active span, use `span.updateName()`
350-
* instead.
349+
* root span. If you want to change the name of the active root span, use
350+
* `Sentry.updateSpanName(rootSpan, 'new name')` instead.
351351
*
352352
* By default, the SDK updates the scope's transaction name automatically on sensible
353353
* occasions, such as a page navigation or when handling a new request on the server.

0 commit comments

Comments
 (0)