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

support for artifact bundles (release-based sourcemap uploading is deprecated) #170

Open
aroman opened this issue Jun 8, 2023 · 7 comments

Comments

@aroman
Copy link

aroman commented Jun 8, 2023

It seems that Sentry has deprecated the release-based sourcemap uploading system used by toucan-js, and instead switched to a new system called "artifact bundles".

Unfortunately, it seems that toucan doesn't support this system yet.

At minimum (but I believe there is more to do as well), it looks like we need to use sentry version 7.47.0 — this library is currently using 7.43.0.

Is this something you plan to support?

CleanShot 2023-06-07 at 17 12 18@2x
@aroman aroman changed the title support for artifact bundles support for artifact bundles (release-based sourcemap uploading is deprecated) Jun 8, 2023
@robertcepa
Copy link
Owner

All dependencies are now at 7.60.0

https://github.com/robertcepa/toucan-js/releases/tag/toucan-js%403.2.0

I'll look at Artifact Bundles sometimes next week, but any feedback/suggestions are welcome!

@huw
Copy link

huw commented Jul 31, 2023

I’ve got it working with artifact bundles on the server:

import { $, argv } from "zx";

// Cut a Sentry release
const version = await $`pnpm sentry-cli releases propose-version`;
await $`sentry-cli releases new ${version}`;

// Inject & upload source maps for the server code
await $`pnpm sentry-cli sourcemaps inject ./dist/server`;
await $`pnpm sentry-cli sourcemaps upload --dist server --release ${version} ./dist/server`;

// Update the commit tracking on production
await $`pnpm sentry-cli releases set-commits ${version} --auto`;

await $`sentry-cli releases finalize ${version}`;

// Deploy to Cloudflare
// We need to add `--no-bundle` to prevent Wrangler from putting the build through ESBuild again, which will mess up the source mappings
await $`pnpm wrangler deploy --no-bundle --var SENTRY_VERSION:${version}`;

// Deploy the project in the current environment
await $`pnpm sentry-cli releases deploys ${version} new`;

Essentially, everything works like it used to, but you have to migrate a few of the commands to the new sentry-cli sourcemaps sub-command and add sentry-cli sourcemaps inject (unless you’re using the ESBuild plugin etc).

The one caveat is the trade-off between passing --no-bundle to Wrangler or not. If you decide to pass --no-bundle, you can inject & upload your source maps after your custom build and before the main worker upload. If you omit it, then you’ll have to set wrangler deploy --outdir ./dist/wrangler and upload your source maps from sentry-cli sourcemaps inject ./dist/wrangler after your deploy. However, in my experience the latter leaves my source maps slightly off (by one or two lines) and I didn’t have the time to figure out why.

@aroman
Copy link
Author

aroman commented Aug 1, 2023

Thanks for sharing, @huw. Here's what I've been doing via GitHub Actions (see YAML snippet below). My trick has been to use --dry-run, then upload those sourcemaps. It's been working fine for us in production. I'm pretty sure this approach is using the deprecated release-based sourcemap uploading... but I do actually see "Artifact Bundles" in the sentry dashboard (see screenshot below) 🤷

In your approach, how are you actually building your worker project?

- name: Generate server source maps
  run: npm run --workspace server deploy-production -- --dry-run --outdir=dist
- name: Create Sentry release for this commit
  run: npx sentry-cli releases new "$SENTRY_RELEASE"
- name: Upload client source maps to Sentry
  run: npx sentry-cli releases files "$SENTRY_RELEASE" upload-sourcemaps --dist client ./client/dist
- name: Upload server source maps to Sentry
  run: npx sentry-cli releases files "$SENTRY_RELEASE" upload-sourcemaps --dist server ./server/dist
- name: Set commits for Sentry release
  run: npx sentry-cli releases set-commits "$SENTRY_RELEASE" --commit "${{ github.repository }}@${{ github.event.before }}..${{ github.sha }}"
- name: Finalize sentry release
  run: npx sentry-cli releases finalize "$SENTRY_RELEASE"
CleanShot 2023-08-01 at 13 45 46@2x

@huw
Copy link

huw commented Aug 1, 2023

You should be able to tell because your output files will have a debugId comment at the very bottom which Sentry uses to track everything. If it doesn’t have that, then it’s probably not an artifact bundle.

Some more colour on my build process—I’m using a Remix site which is bundling the server files as part of its own build process. I can rebundle those with Wrangler and upload the output source maps, but those source maps have been getting my line numbers slightly wrong (usually off by one or two lines). I think it might be to do with the __STATIC_CONTENT_MANIFEST import being moved to the top of the file by Wrangler’s build, but I’m only speculating at this point.

I assume for a normal project, at least one that doesn’t use a custom build, you should be able to upload Wrangler’s source maps after injecting them with debug IDs.

@amiranvarov
Copy link

However, in my experience the latter leaves my source maps slightly off (by one or two lines) and I didn’t have the time to figure out why.

@huw did you manage to figure out why It was off by 1 or 2 lines? I am having the same issue in both cases:
case 1 - when I first bundle with wranger, handle sentry and then deploy with --noBundle
case 2 - when I wrangler --ourdir="dist" deploy first and then handle sentry injection and uploading source maps. Your comment would be really appretiated!

@amiranvarov
Copy link

@huw why 👎 ? can you elaborate please?

@huw
Copy link

huw commented Jul 23, 2024

As I said, never got the time to investigate properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants