Closed drmikecrowe closed 7 months ago
I am assuming you are uploading source maps for 87 lambdas in quick succession and you are running into our rate limits. Can you try somehow adding a sleep in between the individual builds as a workaround? 1-2 seconds between each build should probably be enough.
I am not sure whether we will increase the rate limit on our API for this use case as it is a bit special I'd say. If the esbuild plugin doesn't work for your use-case you can also use Sentry CLI.
Sorry @lforst -- I need you guys to do it. I tried to fork/test, but this project is using an EOL version of node that my OS won't install, and trying to use a local version of node-18 gives errors like this:
sentry-javascript-bundler-plugins main @ 6fd1363 ∽ 30s ❄️ nix-shell-env❯ yarn build
yarn run v1.22.22
$ nx run-many --target=build --all
✖ nx run @sentry/babel-plugin-component-annotate:build
$ rimraf ./out && run-p build:rollup build:types
$ rollup --config rollup.config.js
$ tsc --project types.tsconfig.json
src/index.ts → dist/esm/index.mjs, dist/cjs/index.js...
created dist/esm/index.mjs, dist/cjs/index.js in 1.4s
src/index.ts(136,15): error TS2345: Argument of type 'string | null | undefined' is not assignable to parameter of type 'string | null'.
Type 'undefined' is not assignable to type 'string | null'.
The fix should be simple, but I can't build/test it. Given this is related to your API limits, can I get some help from you guys to test this? This should be pretty close to what we want:
Replace:
await upload(buildArtifacts);
with:
const chunkSize = 35;
const oneMinute = 60 * 1000; // in milliseconds
for (let i = 0; i < buildArtifacts.length; i += chunkSize) {
const currentChunk = buildArtifacts.slice(i, i + chunkSize);
const timeLeft = oneMinute - (Date.now() % oneMinute);
await upload(currentChunk);
const sleepTime = Math.max(0, timeLeft - 50); // add some extra 50ms to account for timing inaccuracies
await new Promise((resolve) => setTimeout(resolve, sleepTime));
}
Full code for that function
function esbuildDebugIdUploadPlugin(
upload: (buildArtifacts: string[]) => Promise<void>
): UnpluginOptions {
return {
name: "sentry-esbuild-debug-id-upload-plugin",
esbuild: {
setup({ initialOptions, onEnd }) {
initialOptions.metafile = true;
onEnd(async (result) => {
const buildArtifacts = result.metafile ? Object.keys(result.metafile.outputs) : [];
// sentry API appears to have a rate limit of 40 requests per minute -- chunk and finish in batches
const chunkSize = 35;
const oneMinute = 60 * 1000; // in milliseconds
for (let i = 0; i < buildArtifacts.length; i += chunkSize) {
const currentChunk = buildArtifacts.slice(i, i + chunkSize);
const timeLeft = oneMinute - (Date.now() % oneMinute);
await upload(currentChunk);
const sleepTime = Math.max(0, timeLeft - 50); // add some extra 50ms to account for timing inaccuracies
await new Promise((resolve) => setTimeout(resolve, sleepTime));
}
});
},
},
};
}
Two things:
You are right, it won't. Turns out, I had another plugin (serverless-sentry
) installed that was duplicating the upload and causing the issue. My bad, sorry for the confusion
Environment
Steps to Reproduce
I'm not sure why this is triggering. I'm simply trigging esbuild and have no special build additions other than documented here
Expected Result
This should not trigger any error.
Actual Result
This randomly generates these errors. I repeated the CICD step and it passed w/o any issues.