Skip to content

Add sourcemap usage with Cloudflare in combination with CF_VERSION_METADATA #16387

@JPeer264

Description

@JPeer264

SDK

JavaScript SDK

Description

When using CF_VERSION_METADATA the release is set automatically. In this case the release is a runtime variable and the sourcemaps cannot be uploaded at build time.

Suggested Solution

However, there is a way to still upload the sourcemaps with the release of CF_VERSION_METADATA. The following bash script could be a manual way to make this happen (not stating that this is the best practice, but a way):

#!/usr/bin/env bash
set -euo pipefail

# Deploy to Cloudflare and capture the start time
start=$(date +%s)
wrangler deploy --env production --outdir dist

# Extract the version from the latest Cloudflare deployment
VERSION=$(wrangler versions list --env production --json | jq -r '.[-1].id')

# Create a Sentry release
sentry-cli releases new "$VERSION"

# Associate commits from the local git repo
sentry-cli releases set-commits "$VERSION" --auto --ignore-missing

# Upload sourcemaps
sentry-cli sourcemaps upload --release="$VERSION" dist

# Create a deploy record and finalize
now=$(date +%s)
sentry-cli deploys new --release "$VERSION" -e production -t $((now - start))
sentry-cli releases finalize "$VERSION"

We need to document the limitations, and maybe come up with a way to automate this (in case there is a user friendly way).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions