Skip to content

Commit 430e5f4

Browse files
committed
fix tests (and bug) in serverless package
1 parent edf84ef commit 430e5f4

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

packages/serverless/src/awslambda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export function wrapHandler<TEvent, TResult>(
290290
}
291291

292292
const rawBaggageString =
293-
eventWithHeaders.headers && isString(eventWithHeaders.headers.baggage) && eventWithHeaders.headers.baggege;
293+
eventWithHeaders.headers && isString(eventWithHeaders.headers.baggage) && eventWithHeaders.headers.baggage;
294294
const baggage = parseAndFreezeBaggageIfNecessary(rawBaggageString, traceparentData);
295295

296296
const transaction = startTransaction({

packages/serverless/test/awslambda.test.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ describe('AWSLambda', () => {
189189
const wrappedHandler = wrapHandler(handler);
190190
const rv = await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
191191
expect(rv).toStrictEqual(42);
192-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
192+
expect(Sentry.startTransaction).toBeCalledWith({
193+
name: 'functionName',
194+
op: 'awslambda.handler',
195+
metadata: { baggage: [{}, '', false] },
196+
});
193197
expectScopeSettings();
194198
// @ts-ignore see "Why @ts-ignore" note
195199
expect(Sentry.fakeTransaction.finish).toBeCalled();
@@ -208,7 +212,11 @@ describe('AWSLambda', () => {
208212
try {
209213
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
210214
} catch (e) {
211-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
215+
expect(Sentry.startTransaction).toBeCalledWith({
216+
name: 'functionName',
217+
op: 'awslambda.handler',
218+
metadata: { baggage: [{}, '', false] },
219+
});
212220
expectScopeSettings();
213221
expect(Sentry.captureException).toBeCalledWith(error);
214222
// @ts-ignore see "Why @ts-ignore" note
@@ -251,6 +259,7 @@ describe('AWSLambda', () => {
251259
release: '2.12.1',
252260
},
253261
'maisey=silly,charlie=goofy',
262+
true,
254263
],
255264
},
256265
}),
@@ -282,6 +291,7 @@ describe('AWSLambda', () => {
282291
traceId: '12312012123120121231201212312012',
283292
parentSpanId: '1121201211212012',
284293
parentSampled: false,
294+
metadata: { baggage: [{}, '', true] },
285295
});
286296
expectScopeSettings();
287297
expect(Sentry.captureException).toBeCalledWith(e);
@@ -302,7 +312,11 @@ describe('AWSLambda', () => {
302312
const wrappedHandler = wrapHandler(handler);
303313
const rv = await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
304314
expect(rv).toStrictEqual(42);
305-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
315+
expect(Sentry.startTransaction).toBeCalledWith({
316+
name: 'functionName',
317+
op: 'awslambda.handler',
318+
metadata: { baggage: [{}, '', false] },
319+
});
306320
expectScopeSettings();
307321
// @ts-ignore see "Why @ts-ignore" note
308322
expect(Sentry.fakeTransaction.finish).toBeCalled();
@@ -332,7 +346,11 @@ describe('AWSLambda', () => {
332346
try {
333347
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
334348
} catch (e) {
335-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
349+
expect(Sentry.startTransaction).toBeCalledWith({
350+
name: 'functionName',
351+
op: 'awslambda.handler',
352+
metadata: { baggage: [{}, '', false] },
353+
});
336354
expectScopeSettings();
337355
expect(Sentry.captureException).toBeCalledWith(error);
338356
// @ts-ignore see "Why @ts-ignore" note
@@ -367,7 +385,11 @@ describe('AWSLambda', () => {
367385
const wrappedHandler = wrapHandler(handler);
368386
const rv = await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
369387
expect(rv).toStrictEqual(42);
370-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
388+
expect(Sentry.startTransaction).toBeCalledWith({
389+
name: 'functionName',
390+
op: 'awslambda.handler',
391+
metadata: { baggage: [{}, '', false] },
392+
});
371393
expectScopeSettings();
372394
// @ts-ignore see "Why @ts-ignore" note
373395
expect(Sentry.fakeTransaction.finish).toBeCalled();
@@ -397,7 +419,11 @@ describe('AWSLambda', () => {
397419
try {
398420
await wrappedHandler(fakeEvent, fakeContext, fakeCallback);
399421
} catch (e) {
400-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'functionName', op: 'awslambda.handler' });
422+
expect(Sentry.startTransaction).toBeCalledWith({
423+
name: 'functionName',
424+
op: 'awslambda.handler',
425+
metadata: { baggage: [{}, '', false] },
426+
});
401427
expectScopeSettings();
402428
expect(Sentry.captureException).toBeCalledWith(error);
403429
// @ts-ignore see "Why @ts-ignore" note

packages/serverless/test/gcpfunction.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ describe('GCPFunction', () => {
110110
};
111111
const wrappedHandler = wrapHttpFunction(handler);
112112
await handleHttp(wrappedHandler);
113-
expect(Sentry.startTransaction).toBeCalledWith({ name: 'POST /path', op: 'gcp.function.http' });
113+
expect(Sentry.startTransaction).toBeCalledWith({
114+
name: 'POST /path',
115+
op: 'gcp.function.http',
116+
metadata: { baggage: [{}, '', false] },
117+
});
114118
// @ts-ignore see "Why @ts-ignore" note
115119
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);
116120
// @ts-ignore see "Why @ts-ignore" note
@@ -147,6 +151,7 @@ describe('GCPFunction', () => {
147151
release: '2.12.1',
148152
},
149153
'maisey=silly,charlie=goofy',
154+
true,
150155
],
151156
},
152157
}),
@@ -173,6 +178,7 @@ describe('GCPFunction', () => {
173178
traceId: '12312012123120121231201212312012',
174179
parentSpanId: '1121201211212012',
175180
parentSampled: false,
181+
metadata: { baggage: [{}, '', true] },
176182
});
177183
// @ts-ignore see "Why @ts-ignore" note
178184
expect(Sentry.fakeScope.setSpan).toBeCalledWith(Sentry.fakeTransaction);

packages/serverless/test/google-cloud-grpc.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe('GoogleCloudGrpc tracing', () => {
130130
expect(Sentry.fakeTransaction.startChild).toBeCalledWith({
131131
op: 'gcloud.grpc.pubsub',
132132
description: 'unary call publish',
133+
metadata: { baggage: [{}, '', true] },
133134
});
134135
await pubsub.close();
135136
});

0 commit comments

Comments
 (0)