sentry-javascript: Cannot read property 'finish' of undefined
-
@sentry/serverless": "^5.26.0
Version:
5.26.0
Description
0
Good afternoon,
After new release: The sentry service works, But I’m getting this message in Amazon CloudWatch:
ERROR Invoke Error
{
"errorType": "TypeError",
"errorMessage": "Cannot read property 'finish' of undefined",
"stack": [
"TypeError: Cannot read property 'finish' of undefined",
" at Runtime.eval [as handler] (webpack://rpc-analise-input/./node_modules/@sentry/serverless/esm/awslambda.js?:216:25)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
Sentry common file
import * as sentry from '@sentry/serverless';
sentry.AWSLambda.init({dsn: 'https://somedsn',
});
export default sentry;
Lambda file
import sentry from '../common/sentry';
const handler = async (event) => {}
exports.handler = sentry.AWSLambda.wrapHandler(handler);
Error location
const transaction = startTransaction({
name: context.functionName,
op: 'awslambda.handler',
});
Line 170: transaction.finish();
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 21
- Comments: 23 (3 by maintainers)
After doing some digging, I found that the
AWSLambda’s handler wrapper makes use of thestartTransactionmethod, which is dynamically registered by@sentry/tracingas an “extension” of Sentry’s core functionality. My guess is that either the docs are missing a step to correctly import and enable this extension or webpack’s tree-shaking (in my case at least) is discarding the tracing code since it’s not used directly but only through the extension mechanism.In any case, I was able to get this working without the error by adding the following before the
initcall:This is happening to me without using serverless, just the regular Node.js package using TS.
Try adding
import '@sentry/tracing';where in you callstartTransactionFor
@sentry/serverless": "6.2.3",with Typescript & Webpack, this worked for me:I have the same issue with “5.26.0” of “@sentry/serverless”, I have to use “5.25.0” for now.
I am in the process of switching from our old
@sentry/nodebased AWS Lambda wrapper with custom flushing to the official@sentry/serverlesspackage. I ran into this issue with 5.27.1 and just like everyone else downgrading to 5.25.0 fixed it. So I guess I’ll stick to that version for the foreseeable future.Not really related to this issue, but I noticed that the package does not have all TypeScript dependencies set properly so adding the package caused compilation to break until I manually added
@google-cloud/functions-frameworkand@types/expresspackages.