Skip to content

Commit 718a42a

Browse files
committed
ref(serverless): Add transaction source
1 parent 439b9d3 commit 718a42a

File tree

6 files changed

+75
-23
lines changed

6 files changed

+75
-23
lines changed

packages/serverless/src/awslambda.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export function wrapHandler<TEvent, TResult>(
324324
name: context.functionName,
325325
op: 'awslambda.handler',
326326
...traceparentData,
327-
metadata: { baggage },
327+
metadata: { baggage, source: 'component' },
328328
});
329329

330330
const hub = getCurrentHub();

packages/serverless/src/gcpfunction/cloud_events.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function _wrapCloudEventFunction(
3333
const transaction = startTransaction({
3434
name: context.type || '<unknown>',
3535
op: 'gcp.function.cloud_event',
36+
metadata: { source: 'component' },
3637
});
3738

3839
// getCurrentHub() is expected to use current active domain as a carrier

packages/serverless/src/gcpfunction/events.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function _wrapEventFunction(
3333
const transaction = startTransaction({
3434
name: context.eventType,
3535
op: 'gcp.function.event',
36+
metadata: { source: 'component' },
3637
});
3738

3839
// getCurrentHub() is expected to use current active domain as a carrier

packages/serverless/src/gcpfunction/http.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
8787
name: `${reqMethod} ${reqUrl}`,
8888
op: 'gcp.function.http',
8989
...traceparentData,
90-
metadata: { baggage },
90+
metadata: { baggage, source: 'url' },
9191
});
9292

9393
// getCurrentHub() is expected to use current active domain as a carrier

packages/serverless/test/awslambda.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('AWSLambda', () => {
190190
expect(Sentry.startTransaction).toBeCalledWith({
191191
name: 'functionName',
192192
op: 'awslambda.handler',
193-
metadata: { baggage: [{}, '', true] },
193+
metadata: { baggage: [{}, '', true], source: 'component' },
194194
});
195195
expectScopeSettings();
196196
// @ts-ignore see "Why @ts-ignore" note
@@ -213,7 +213,7 @@ describe('AWSLambda', () => {
213213
expect(Sentry.startTransaction).toBeCalledWith({
214214
name: 'functionName',
215215
op: 'awslambda.handler',
216-
metadata: { baggage: [{}, '', true] },
216+
metadata: { baggage: [{}, '', true], source: 'component' },
217217
});
218218
expectScopeSettings();
219219
expect(Sentry.captureException).toBeCalledWith(error);
@@ -259,6 +259,7 @@ describe('AWSLambda', () => {
259259
'',
260260
false,
261261
],
262+
source: 'component',
262263
},
263264
}),
264265
);
@@ -289,7 +290,7 @@ describe('AWSLambda', () => {
289290
traceId: '12312012123120121231201212312012',
290291
parentSpanId: '1121201211212012',
291292
parentSampled: false,
292-
metadata: { baggage: [{}, '', false] },
293+
metadata: { baggage: [{}, '', false], source: 'component' },
293294
});
294295
expectScopeSettings();
295296
expect(Sentry.captureException).toBeCalledWith(e);
@@ -313,7 +314,7 @@ describe('AWSLambda', () => {
313314
expect(Sentry.startTransaction).toBeCalledWith({
314315
name: 'functionName',
315316
op: 'awslambda.handler',
316-
metadata: { baggage: [{}, '', true] },
317+
metadata: { baggage: [{}, '', true], source: 'component' },
317318
});
318319
expectScopeSettings();
319320
// @ts-ignore see "Why @ts-ignore" note
@@ -347,7 +348,7 @@ describe('AWSLambda', () => {
347348
expect(Sentry.startTransaction).toBeCalledWith({
348349
name: 'functionName',
349350
op: 'awslambda.handler',
350-
metadata: { baggage: [{}, '', true] },
351+
metadata: { baggage: [{}, '', true], source: 'component' },
351352
});
352353
expectScopeSettings();
353354
expect(Sentry.captureException).toBeCalledWith(error);
@@ -386,7 +387,7 @@ describe('AWSLambda', () => {
386387
expect(Sentry.startTransaction).toBeCalledWith({
387388
name: 'functionName',
388389
op: 'awslambda.handler',
389-
metadata: { baggage: [{}, '', true] },
390+
metadata: { baggage: [{}, '', true], source: 'component' },
390391
});
391392
expectScopeSettings();
392393
// @ts-ignore see "Why @ts-ignore" note
@@ -420,7 +421,7 @@ describe('AWSLambda', () => {
420421
expect(Sentry.startTransaction).toBeCalledWith({
421422
name: 'functionName',
422423
op: 'awslambda.handler',
423-
metadata: { baggage: [{}, '', true] },
424+
metadata: { baggage: [{}, '', true], source: 'component' },
424425
});
425426
expectScopeSettings();
426427
expect(Sentry.captureException).toBeCalledWith(error);

packages/serverless/test/gcpfunction.test.ts

+63-14
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('GCPFunction', () => {
113113
expect(Sentry.startTransaction).toBeCalledWith({
114114
name: 'POST /path',
115115
op: 'gcp.function.http',
116-
metadata: { baggage: [{}, '', true] },
116+
metadata: { baggage: [{}, '', true], source: 'url' },
117117
});
118118
// @ts-ignore see "Why @ts-ignore" note
119119
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
@@ -153,6 +153,7 @@ describe('GCPFunction', () => {
153153
'',
154154
false,
155155
],
156+
source: 'url',
156157
},
157158
}),
158159
);
@@ -178,7 +179,7 @@ describe('GCPFunction', () => {
178179
traceId: '12312012123120121231201212312012',
179180
parentSpanId: '1121201211212012',
180181
parentSampled: false,
181-
metadata: { baggage: [{}, '', false] },
182+
metadata: { baggage: [{}, '', false], source: 'url' },
182183
});
183184
// @ts-ignore see "Why @ts-ignore" note
184185
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
@@ -245,7 +246,11 @@ describe('GCPFunction', () => {
245246
};
246247
const wrappedHandler = wrapEventFunction(func);
247248
await expect(handleEvent(wrappedHandler)).resolves.toBe(42);
248-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
249+
expect(Sentry.startTransaction).toBeCalledWith({
250+
name: 'event.type',
251+
op: 'gcp.function.event',
252+
metadata: { source: 'component' },
253+
});
249254
// @ts-ignore see "Why @ts-ignore" note
250255
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
251256
// @ts-ignore see "Why @ts-ignore" note
@@ -262,7 +267,11 @@ describe('GCPFunction', () => {
262267
};
263268
const wrappedHandler = wrapEventFunction(handler);
264269
await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error);
265-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
270+
expect(Sentry.startTransaction).toBeCalledWith({
271+
name: 'event.type',
272+
op: 'gcp.function.event',
273+
metadata: { source: 'component' },
274+
});
266275
// @ts-ignore see "Why @ts-ignore" note
267276
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
268277
expect(Sentry.captureException).toBeCalledWith(error);
@@ -284,7 +293,11 @@ describe('GCPFunction', () => {
284293
});
285294
const wrappedHandler = wrapEventFunction(func);
286295
await expect(handleEvent(wrappedHandler)).resolves.toBe(42);
287-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
296+
expect(Sentry.startTransaction).toBeCalledWith({
297+
name: 'event.type',
298+
op: 'gcp.function.event',
299+
metadata: { source: 'component' },
300+
});
288301
// @ts-ignore see "Why @ts-ignore" note
289302
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
290303
// @ts-ignore see "Why @ts-ignore" note
@@ -305,7 +318,11 @@ describe('GCPFunction', () => {
305318

306319
const wrappedHandler = wrapEventFunction(handler);
307320
await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error);
308-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
321+
expect(Sentry.startTransaction).toBeCalledWith({
322+
name: 'event.type',
323+
op: 'gcp.function.event',
324+
metadata: { source: 'component' },
325+
});
309326
// @ts-ignore see "Why @ts-ignore" note
310327
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
311328
expect(Sentry.captureException).toBeCalledWith(error);
@@ -324,7 +341,11 @@ describe('GCPFunction', () => {
324341
};
325342
const wrappedHandler = wrapEventFunction(func);
326343
await expect(handleEvent(wrappedHandler)).resolves.toBe(42);
327-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
344+
expect(Sentry.startTransaction).toBeCalledWith({
345+
name: 'event.type',
346+
op: 'gcp.function.event',
347+
metadata: { source: 'component' },
348+
});
328349
// @ts-ignore see "Why @ts-ignore" note
329350
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
330351
// @ts-ignore see "Why @ts-ignore" note
@@ -341,7 +362,11 @@ describe('GCPFunction', () => {
341362
};
342363
const wrappedHandler = wrapEventFunction(handler);
343364
await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error);
344-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
365+
expect(Sentry.startTransaction).toBeCalledWith({
366+
name: 'event.type',
367+
op: 'gcp.function.event',
368+
metadata: { source: 'component' },
369+
});
345370
// @ts-ignore see "Why @ts-ignore" note
346371
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
347372
expect(Sentry.captureException).toBeCalledWith(error);
@@ -359,7 +384,11 @@ describe('GCPFunction', () => {
359384
};
360385
const wrappedHandler = wrapEventFunction(handler);
361386
await expect(handleEvent(wrappedHandler)).rejects.toThrowError(error);
362-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.event' });
387+
expect(Sentry.startTransaction).toBeCalledWith({
388+
name: 'event.type',
389+
op: 'gcp.function.event',
390+
metadata: { source: 'component' },
391+
});
363392
// @ts-ignore see "Why @ts-ignore" note
364393
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
365394
expect(Sentry.captureException).toBeCalledWith(error);
@@ -388,7 +417,11 @@ describe('GCPFunction', () => {
388417
};
389418
const wrappedHandler = wrapCloudEventFunction(func);
390419
await expect(handleCloudEvent(wrappedHandler)).resolves.toBe(42);
391-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' });
420+
expect(Sentry.startTransaction).toBeCalledWith({
421+
name: 'event.type',
422+
op: 'gcp.function.cloud_event',
423+
metadata: { source: 'component' },
424+
});
392425
// @ts-ignore see "Why @ts-ignore" note
393426
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
394427
// @ts-ignore see "Why @ts-ignore" note
@@ -405,7 +438,11 @@ describe('GCPFunction', () => {
405438
};
406439
const wrappedHandler = wrapCloudEventFunction(handler);
407440
await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error);
408-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' });
441+
expect(Sentry.startTransaction).toBeCalledWith({
442+
name: 'event.type',
443+
op: 'gcp.function.cloud_event',
444+
metadata: { source: 'component' },
445+
});
409446
// @ts-ignore see "Why @ts-ignore" note
410447
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
411448
expect(Sentry.captureException).toBeCalledWith(error);
@@ -424,7 +461,11 @@ describe('GCPFunction', () => {
424461
};
425462
const wrappedHandler = wrapCloudEventFunction(func);
426463
await expect(handleCloudEvent(wrappedHandler)).resolves.toBe(42);
427-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' });
464+
expect(Sentry.startTransaction).toBeCalledWith({
465+
name: 'event.type',
466+
op: 'gcp.function.cloud_event',
467+
metadata: { source: 'component' },
468+
});
428469
// @ts-ignore see "Why @ts-ignore" note
429470
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
430471
// @ts-ignore see "Why @ts-ignore" note
@@ -441,7 +482,11 @@ describe('GCPFunction', () => {
441482
};
442483
const wrappedHandler = wrapCloudEventFunction(handler);
443484
await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error);
444-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' });
485+
expect(Sentry.startTransaction).toBeCalledWith({
486+
name: 'event.type',
487+
op: 'gcp.function.cloud_event',
488+
metadata: { source: 'component' },
489+
});
445490
// @ts-ignore see "Why @ts-ignore" note
446491
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
447492
expect(Sentry.captureException).toBeCalledWith(error);
@@ -459,7 +504,11 @@ describe('GCPFunction', () => {
459504
};
460505
const wrappedHandler = wrapCloudEventFunction(handler);
461506
await expect(handleCloudEvent(wrappedHandler)).rejects.toThrowError(error);
462-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'event.type', op: 'gcp.function.cloud_event' });
507+
expect(Sentry.startTransaction).toBeCalledWith({
508+
name: 'event.type',
509+
op: 'gcp.function.cloud_event',
510+
metadata: { source: 'component' },
511+
});
463512
// @ts-ignore see "Why @ts-ignore" note
464513
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
465514
expect(Sentry.captureException).toBeCalledWith(error);

0 commit comments

Comments
 (0)