Skip to content

Commit d324516

Browse files
authored
fix(serverless): Account when transaction undefined (#7829)
1 parent 95f721f commit d324516

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

packages/serverless/src/awslambda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export function wrapHandler<TEvent, TResult>(
328328
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
329329
source: 'component',
330330
},
331-
});
331+
}) as Sentry.Transaction | undefined;
332332

333333
const scope = hub.pushScope();
334334
let rv: TResult;
@@ -350,7 +350,7 @@ export function wrapHandler<TEvent, TResult>(
350350
throw e;
351351
} finally {
352352
clearTimeout(timeoutWarningTimer);
353-
transaction.finish();
353+
transaction?.finish();
354354
hub.popScope();
355355
await flush(options.flushTimeout).catch(e => {
356356
__DEBUG_BUILD__ && logger.error(e);

packages/serverless/src/gcpfunction/cloud_events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function _wrapCloudEventFunction(
3636
name: context.type || '<unknown>',
3737
op: 'function.gcp.cloud_event',
3838
metadata: { source: 'component' },
39-
});
39+
}) as ReturnType<typeof hub.startTransaction> | undefined;
4040

4141
// getCurrentHub() is expected to use current active domain as a carrier
4242
// since functions-framework creates a domain for each incoming request.
@@ -51,7 +51,7 @@ function _wrapCloudEventFunction(
5151
if (args[0] !== null && args[0] !== undefined) {
5252
captureException(args[0]);
5353
}
54-
transaction.finish();
54+
transaction?.finish();
5555

5656
void flush(options.flushTimeout)
5757
.then(null, e => {

packages/serverless/src/gcpfunction/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
3838
name: context.eventType,
3939
op: 'function.gcp.event',
4040
metadata: { source: 'component' },
41-
});
41+
}) as ReturnType<typeof hub.startTransaction> | undefined;
4242

4343
// getCurrentHub() is expected to use current active domain as a carrier
4444
// since functions-framework creates a domain for each incoming request.
@@ -53,7 +53,7 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
5353
if (args[0] !== null && args[0] !== undefined) {
5454
captureException(args[0]);
5555
}
56-
transaction.finish();
56+
transaction?.finish();
5757

5858
void flush(options.flushTimeout)
5959
.then(null, e => {

packages/serverless/src/gcpfunction/http.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
9292
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
9393
source: 'route',
9494
},
95-
});
95+
}) as ReturnType<typeof hub.startTransaction> | undefined;
9696

9797
// getCurrentHub() is expected to use current active domain as a carrier
9898
// since functions-framework creates a domain for each incoming request.
@@ -115,8 +115,8 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
115115
const _end = res.end;
116116
// eslint-disable-next-line @typescript-eslint/no-explicit-any
117117
res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): any {
118-
transaction.setHttpStatus(res.statusCode);
119-
transaction.finish();
118+
transaction?.setHttpStatus(res.statusCode);
119+
transaction?.finish();
120120

121121
void flush(options.flushTimeout)
122122
.then(null, e => {

0 commit comments

Comments
 (0)