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

ref(serverless): Add transaction source #5394

Merged
merged 2 commits into from
Jul 8, 2022
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
2 changes: 1 addition & 1 deletion packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export function wrapHandler<TEvent, TResult>(
name: context.functionName,
op: 'awslambda.handler',
...traceparentData,
metadata: { baggage },
metadata: { baggage, source: 'component' },
});

const hub = getCurrentHub();
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/gcpfunction/cloud_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function _wrapCloudEventFunction(
const transaction = startTransaction({
name: context.type || '<unknown>',
op: 'gcp.function.cloud_event',
metadata: { source: 'component' },
});

// getCurrentHub() is expected to use current active domain as a carrier
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/gcpfunction/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/serverless/src/gcpfunction/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
name: `${reqMethod} ${reqUrl}`,
op: 'gcp.function.http',
...traceparentData,
metadata: { baggage },
metadata: { baggage, source: 'route' },
});

// getCurrentHub() is expected to use current active domain as a carrier
Expand Down
15 changes: 8 additions & 7 deletions packages/serverless/test/awslambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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
Expand All @@ -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);
Expand Down Expand Up @@ -259,6 +259,7 @@ describe('AWSLambda', () => {
'',
false,
],
source: 'component',
},
}),
);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
77 changes: 63 additions & 14 deletions packages/serverless/test/gcpfunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -153,6 +153,7 @@ describe('GCPFunction', () => {
'',
false,
],
source: 'route',
},
}),
);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down