Skip to content

Commit

Permalink
fix(serverless): Account when transaction undefined (#7829)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Apr 13, 2023
1 parent 95f721f commit d324516
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/serverless/src/awslambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export function wrapHandler<TEvent, TResult>(
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'component',
},
});
}) as Sentry.Transaction | undefined;

const scope = hub.pushScope();
let rv: TResult;
Expand All @@ -350,7 +350,7 @@ export function wrapHandler<TEvent, TResult>(
throw e;
} finally {
clearTimeout(timeoutWarningTimer);
transaction.finish();
transaction?.finish();
hub.popScope();
await flush(options.flushTimeout).catch(e => {
__DEBUG_BUILD__ && logger.error(e);
Expand Down
4 changes: 2 additions & 2 deletions packages/serverless/src/gcpfunction/cloud_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _wrapCloudEventFunction(
name: context.type || '<unknown>',
op: 'function.gcp.cloud_event',
metadata: { source: 'component' },
});
}) as ReturnType<typeof hub.startTransaction> | undefined;

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

void flush(options.flushTimeout)
.then(null, e => {
Expand Down
4 changes: 2 additions & 2 deletions packages/serverless/src/gcpfunction/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
name: context.eventType,
op: 'function.gcp.event',
metadata: { source: 'component' },
});
}) as ReturnType<typeof hub.startTransaction> | undefined;

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

void flush(options.flushTimeout)
.then(null, e => {
Expand Down
6 changes: 3 additions & 3 deletions packages/serverless/src/gcpfunction/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function _wrapHttpFunction(fn: HttpFunction, wrapOptions: Partial<HttpFunctionWr
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
source: 'route',
},
});
}) as ReturnType<typeof hub.startTransaction> | undefined;

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

void flush(options.flushTimeout)
.then(null, e => {
Expand Down

0 comments on commit d324516

Please sign in to comment.