Description
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
Package + Version
@sentry/serverless
Version:
6.2.2
Description
It looks like Sentry.GCPFunction.wrapEventFunction
does not correctly signal function termination in async background cloud functions. The function exits prematurely while the async code continues running in the background. You can see this behavior in the logs:
This is a follow up to an issue in the nodejs-pubsub
client, where multiple users reported that pub/sub event functions operate with an unexpectedly high latency. In my case, removing the sentry wrapper solved the issue.
The access to the CPU is limited once the function terminates, and any code that keeps running in background takes minutes to execute or eventually times out.
It looks like only the pub/sub triggered functions are affected. The HTTP triggered functions wrapped in Sentry.GCPFunction.wrapHttpFunction
work as expected.
package.json
{
"name": "sentry-gcf-repro",
"version": "1.0.0",
"main": "function.js",
"license": "MIT",
"dependencies": {
"@sentry/serverless": "^6.2.2"
},
"engines": {
"node": ">= 14.15 <15"
}
}
function.js
const Sentry = require("@sentry/serverless");
Sentry.GCPFunction.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
});
const sleep = (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
const sayHello = async () => {
await sleep(5000);
console.log("Hello")
}
exports.sayHelloHandler = Sentry.GCPFunction.wrapEventFunction(
sayHello
);
Steps to reproduce
You would need to create a topic, deploy the function and send a message to the topic:
gcloud pubsub topics create hello
gcloud functions deploy sayHello --trigger-topic hello --runtime nodejs14 --entry-point sayHelloHandler --region europe-west3
gcloud pubsub topics publish hello --message="{}"