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

fix(serverless): Account when transaction undefined #7829

Merged
merged 1 commit into from
Apr 13, 2023
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
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