Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-lambda): Avoid overwriting root span name #15000

Merged
merged 2 commits into from
Jan 17, 2025
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
5 changes: 1 addition & 4 deletions packages/aws-serverless/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
9 changes: 3 additions & 6 deletions packages/aws-serverless/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const mockScope = {
setTag: jest.fn(),
setContext: jest.fn(),
addEventProcessor: jest.fn(),
setTransactionName: jest.fn(),
};

jest.mock('@sentry/node', () => {
Expand Down Expand Up @@ -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());

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading