From aeac69dbc0ca224b2ce965fa5814c1e99f33d40c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 8 Jul 2022 14:39:22 -0400 Subject: [PATCH] ref(serverless): Add transaction source (#5394) --- packages/serverless/src/awslambda.ts | 2 +- .../src/gcpfunction/cloud_events.ts | 1 + packages/serverless/src/gcpfunction/events.ts | 1 + packages/serverless/src/gcpfunction/http.ts | 2 +- packages/serverless/test/awslambda.test.ts | 15 ++-- packages/serverless/test/gcpfunction.test.ts | 77 +++++++++++++++---- 6 files changed, 75 insertions(+), 23 deletions(-) diff --git a/packages/serverless/src/awslambda.ts b/packages/serverless/src/awslambda.ts index bd5c8ced25af..826bc34ab29c 100644 --- a/packages/serverless/src/awslambda.ts +++ b/packages/serverless/src/awslambda.ts @@ -324,7 +324,7 @@ export function wrapHandler( name: context.functionName, op: 'awslambda.handler', ...traceparentData, - metadata: { baggage }, + metadata: { baggage, source: 'component' }, }); const hub = getCurrentHub(); diff --git a/packages/serverless/src/gcpfunction/cloud_events.ts b/packages/serverless/src/gcpfunction/cloud_events.ts index 8ca0bff5dc16..605a3a486dd4 100644 --- a/packages/serverless/src/gcpfunction/cloud_events.ts +++ b/packages/serverless/src/gcpfunction/cloud_events.ts @@ -33,6 +33,7 @@ function _wrapCloudEventFunction( const transaction = startTransaction({ name: context.type || '', op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, }); // getCurrentHub() is expected to use current active domain as a carrier diff --git a/packages/serverless/src/gcpfunction/events.ts b/packages/serverless/src/gcpfunction/events.ts index 1b4efaf19a11..9d13f18386e0 100644 --- a/packages/serverless/src/gcpfunction/events.ts +++ b/packages/serverless/src/gcpfunction/events.ts @@ -33,6 +33,7 @@ function _wrapEventFunction( const transaction = startTransaction({ name: context.eventType, op: 'gcp.function.event', + metadata: { source: 'component' }, }); // getCurrentHub() is expected to use current active domain as a carrier diff --git a/packages/serverless/src/gcpfunction/http.ts b/packages/serverless/src/gcpfunction/http.ts index 07728f54f0f6..fd3af7b08ac2 100644 --- a/packages/serverless/src/gcpfunction/http.ts +++ b/packages/serverless/src/gcpfunction/http.ts @@ -87,7 +87,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); // @ts-ignore see "Why @ts-ignore" note @@ -213,7 +213,7 @@ describe('AWSLambda', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); expect(Sentry.captureException).toBeCalledWith(error); @@ -259,6 +259,7 @@ describe('AWSLambda', () => { '', false, ], + source: 'component', }, }), ); @@ -289,7 +290,7 @@ describe('AWSLambda', () => { traceId: '12312012123120121231201212312012', parentSpanId: '1121201211212012', parentSampled: false, - metadata: { baggage: [{}, '', false] }, + metadata: { baggage: [{}, '', false], source: 'component' }, }); expectScopeSettings(); expect(Sentry.captureException).toBeCalledWith(e); @@ -313,7 +314,7 @@ describe('AWSLambda', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); // @ts-ignore see "Why @ts-ignore" note @@ -347,7 +348,7 @@ describe('AWSLambda', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); expect(Sentry.captureException).toBeCalledWith(error); @@ -386,7 +387,7 @@ describe('AWSLambda', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); // @ts-ignore see "Why @ts-ignore" note @@ -420,7 +421,7 @@ describe('AWSLambda', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'component' }, }); expectScopeSettings(); expect(Sentry.captureException).toBeCalledWith(error); diff --git a/packages/serverless/test/gcpfunction.test.ts b/packages/serverless/test/gcpfunction.test.ts index d6229394990b..4e54be9d21ca 100644 --- a/packages/serverless/test/gcpfunction.test.ts +++ b/packages/serverless/test/gcpfunction.test.ts @@ -113,7 +113,7 @@ describe('GCPFunction', () => { expect(Sentry.startTransaction).toBeCalledWith({ name: 'POST /path', op: 'gcp.function.http', - metadata: { baggage: [{}, '', true] }, + metadata: { baggage: [{}, '', true], source: 'route' }, }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); @@ -153,6 +153,7 @@ describe('GCPFunction', () => { '', false, ], + source: 'route', }, }), ); @@ -178,7 +179,7 @@ describe('GCPFunction', () => { traceId: '12312012123120121231201212312012', parentSpanId: '1121201211212012', parentSampled: false, - metadata: { baggage: [{}, '', false] }, + metadata: { baggage: [{}, '', false], source: 'route' }, }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); @@ -245,7 +246,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapEventFunction(func); await expect(handleEvent(wrappedHandler)).resolves.toBe(42); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); // @ts-ignore see "Why @ts-ignore" note @@ -262,7 +267,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapEventFunction(handler); await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -284,7 +293,11 @@ describe('GCPFunction', () => { }); const wrappedHandler = wrapEventFunction(func); await expect(handleEvent(wrappedHandler)).resolves.toBe(42); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); // @ts-ignore see "Why @ts-ignore" note @@ -305,7 +318,11 @@ describe('GCPFunction', () => { const wrappedHandler = wrapEventFunction(handler); await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -324,7 +341,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapEventFunction(func); await expect(handleEvent(wrappedHandler)).resolves.toBe(42); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); // @ts-ignore see "Why @ts-ignore" note @@ -341,7 +362,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapEventFunction(handler); await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -359,7 +384,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapEventFunction(handler); await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -388,7 +417,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapCloudEventFunction(func); await expect(handleCloudEvent(wrappedHandler)).resolves.toBe(42); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); // @ts-ignore see "Why @ts-ignore" note @@ -405,7 +438,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapCloudEventFunction(handler); await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -424,7 +461,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapCloudEventFunction(func); await expect(handleCloudEvent(wrappedHandler)).resolves.toBe(42); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); // @ts-ignore see "Why @ts-ignore" note @@ -441,7 +482,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapCloudEventFunction(handler); await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error); @@ -459,7 +504,11 @@ describe('GCPFunction', () => { }; const wrappedHandler = wrapCloudEventFunction(handler); await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error); - expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' }); + expect(Sentry.startTransaction).toBeCalledWith({ + name: 'event.type', + op: 'gcp.function.cloud_event', + metadata: { source: 'component' }, + }); // @ts-ignore see "Why @ts-ignore" note expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction); expect(Sentry.captureException).toBeCalledWith(error);