Skip to content

Commit 50b0294

Browse files
authored
fix(v8/aws-lambda): Avoid overwriting root span name (#15054)
backport of #15000
1 parent 40d9b9f commit 50b0294

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
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

+9-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,15 @@ class ScopeClass implements ScopeInterface {
306306
}
307307

308308
/**
309-
* @inheritDoc
309+
* Sets the transaction name on the scope so that the name of e.g. taken server route or
310+
* the page location is attached to future events.
311+
*
312+
* IMPORTANT: Calling this function does NOT change the name of the currently active
313+
* root span. If you want to change the name of the active root span, use
314+
* `Sentry.updateSpanName(rootSpan, 'new name')` instead.
315+
*
316+
* By default, the SDK updates the scope's transaction name automatically on sensible
317+
* occasions, such as a page navigation or when handling a new request on the server.
310318
*/
311319
public setTransactionName(name?: string): this {
312320
this._transactionName = name;

0 commit comments

Comments
 (0)