Skip to content

docs(react-native): Use Sentry CLI v4 for manual source map uploads - #21120

Open
sentry-junior[bot] wants to merge 1 commit into
masterfrom
byk/docs/rn-sourcemaps-cli-v4
Open

sentry-junior[bot] wants to merge 1 commit into
masterfrom
byk/docs/rn-sourcemaps-cli-v4

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

DESCRIBE YOUR PR

Follow-up to #21100, which kept the React Native manual upload pages on npx @sentry/cli@3 until v4 was tested. This PR moves the Hermes, JavaScript Core, Expo (Advanced), and CodePush manual upload steps to npx sentry@4 sourcemap upload:

  • --ext .bundle / --ext .jsbundle: v4 only picks up .js, .cjs, and .mjs files by default, so without it no React Native bundle is found.
  • Root-only pattern ('index.android.bundle*', 'main.jsbundle*'): v4 takes one directory, and . from the project root also uploads stale bundles under build folders such as android/app/build, because v4 doesn't respect .gitignore. The pattern keeps the upload to the bundle and its source map.
  • No --debug-id-reference: v4 does this by default. For Hermes, it takes the debug ID that copy-debugid.js writes into the source map, and leaves the bundle on disk unchanged.
  • The "bundle will have a size of 0 bytes" alert is removed: v4 uploads the full Hermes bytecode bundle as the minified source.
  • export lines instead of .env blocks: v4 doesn't load .env files, so SENTRY_ORG, SENTRY_PROJECT, and SENTRY_AUTH_TOKEN have to be in the environment.
  • CodePush: v4 reads one directory and dropped --bundle-sourcemap, and it only pairs a bundle with a map in the same directory, so the steps now copy the map from ./sourcemaps next to the bundle before uploading "${BUNDLE_DIR}".

Pages that stay on v3

  • RAM bundles (manual-setup/ram-bundles) now pin npx @sentry/cli@3 sourcemaps upload, with a line explaining that v4 dropped --bundle and --bundle-sourcemap and can't extract RAM bundles.
  • Pages about the CLI that the SDK runs (Xcode and Gradle scripts, troubleshooting), the legacy uploading methods for older SDKs, and the before-v5 migration guide aren't changed.

Open question

Does Sentry symbolicate Hermes frames when v4 uploads the full Hermes bytecode bundle as the minified source? v3 uploaded an empty file there. The artifact bundle contents match the debug IDs, but no real upload to a Sentry project has been run yet. A repro script for the RN SDK team is in the comments. Please don't merge until a maintainer reports the result for Hermes and JSC.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.
Select exactly one option. For deadlines, replace YYYY-MM-DD with the due date. You can update this information later by editing the PR description.

  • Urgent deadline (GA date, etc.): YYYY-MM-DD
  • Other deadline: YYYY-MM-DD
  • No deadline: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've supplied a deadline.

Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

EXTRA RESOURCES

via @BYK.

--

View Session [Sentry]

Move the Hermes, JSC, Expo (Advanced), and CodePush manual upload steps
to `npx sentry@4 sourcemap upload`:

- Pass `--ext .bundle` / `--ext .jsbundle`, because v4 only picks up
  .js, .cjs, and .mjs files by default.
- Upload with a root-only pattern (`'index.android.bundle*'`) instead
  of `.`, which also uploads stale bundles under android/app/build.
- Drop `--debug-id-reference`. v4 takes the debug ID from the source
  map that copy-debugid.js writes, and uploads the Hermes bundle in full,
  so the "0 bytes" note no longer applies.
- Export SENTRY_ORG, SENTRY_PROJECT, and SENTRY_AUTH_TOKEN instead of a
  .env file. v4 doesn't load .env files.
- CodePush: copy the source map next to the bundle, since v4 reads one
  directory and dropped --bundle-sourcemap.

RAM bundles stay on `npx @sentry/cli@3`: v4 dropped --bundle and
--bundle-sourcemap and can't extract RAM bundles.

Follow-up to #21100.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentry-docs Ready Ready Preview Dec 4, 2026 7:05pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
develop-docs Ignored Ignored Dec 4, 2026 7:05pm UTC

Request Review

@github-actions github-actions Bot added the Priority: Normal Docs review has no urgent deadline label Dec 4, 2026
@codeowner-assignment
codeowner-assignment Bot requested review from a team, antonis and buenaflor and removed request for a team December 4, 2026 19:06
@sentry-junior

sentry-junior Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@antonis, could the RN SDK team run one real upload for this PR? It answers the open question in the description: does Sentry symbolicate Hermes frames when sentry@4 uploads the full Hermes bytecode bundle as the minified source? v3 uploaded an empty file there.

The script below builds a fresh RN 0.88.1 app with @sentry/react-native 8.38.0. It follows the Hermes and JSC pages of this PR step by step, and uploads with the documented npx sentry@4 sourcemap upload command plus --wait. Then it sends one test event per bundle and checks where the frame resolves.

Save the three files in one folder, then run:

export SENTRY_ORG=... SENTRY_PROJECT=...   # a test project
export SENTRY_AUTH_TOKEN=...               # org auth token, used for the upload
export SENTRY_DSN=...                      # that project's DSN, for the test events
sh repro.sh
  • The upload uses the org auth token.
  • The event check reads each event back from the API, which may need event:read. If your token can't read events, run with SKIP_EVENT_CHECK=1. Then open the two printed event IDs in the Sentry UI and check that the frame shows App.js:5.
  • Bundles, maps, event JSON and API responses end up in <workdir>/out.

Expected result

Bundle Debug ID Frame sent Should resolve to
Hermes 4931510c-bb48-4773-b031-5440e0b9b94e app:///index.android.bundle:1:900063 App.js:5, throw new Error('CLI v4 React Native source map test')
JSC 5de3c2cc-3188-4d27-85ea-90085d3e9c2c app:///index.android.bundle:990:277 App.js:5, same line

The debug IDs and offsets come out the same on every rebuild with these pinned versions. For both bundles, the artifact bundle should hold ~/index.android.bundle and ~/index.android.bundle.map with that debug ID. The script prints RESOLVED: App.js:5 for each bundle on success. If Hermes stays on index.android.bundle:1:900063, or the event shows a processing error such as js_invalid_source, the full bytecode upload is the problem, and the docs need another approach before this leaves draft.

Please post the output, or a screenshot of both frames, here.

repro.sh
#!/bin/sh
# Real end-to-end check of the React Native manual source map docs with
# Sentry CLI v4: build Hermes and JSC Android bundles the way the docs say,
# upload them with the documented `npx sentry@4 sourcemap upload` command,
# send one test event per bundle, and check that Sentry resolves the frame
# to App.js line 5.
#
# Needs: Node.js 20+, npm, Linux x64 or macOS.
# Env:   SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKEN (an org auth token
#        uploads fine), SENTRY_DSN (the project's DSN, for the test events),
#        optional SENTRY_URL. Reading the events back may need event:read,
#        which org auth tokens don't have: set SKIP_EVENT_CHECK=1 to skip
#        that and check the printed event IDs in the Sentry UI instead.
# Usage: sh repro.sh [workdir]   (keep make-event.mjs and check-event.mjs
#        next to this script)
set -eu

: "${SENTRY_ORG:?set SENTRY_ORG}"
: "${SENTRY_PROJECT:?set SENTRY_PROJECT}"
: "${SENTRY_AUTH_TOKEN:?set SENTRY_AUTH_TOKEN}"
export SENTRY_ORG SENTRY_PROJECT SENTRY_AUTH_TOKEN

here=$(cd "$(dirname "$0")" && pwd)
app=${1:-$(mktemp -d "${TMPDIR:-/tmp}/rn-cli-v4.XXXXXX")}
mkdir -p "$app"
app=$(cd "$app" && pwd)
cd "$app"
echo "== test app: $app"

os=$(uname -s)
case $os in
  Linux) hermesc=node_modules/hermes-compiler/hermesc/linux64-bin/hermesc ;;
  Darwin) hermesc=node_modules/hermes-compiler/hermesc/osx-bin/hermesc ;;
  *) echo "unsupported OS: $os" >&2; exit 2 ;;
esac

cat > package.json <<'JSON'
{ "name": "rnsmtest", "version": "1.0.0", "private": true }
JSON
cat > app.json <<'JSON'
{ "name": "rnsmtest", "displayName": "rnsmtest" }
JSON
cat > babel.config.js <<'JS'
module.exports = { presets: ['module:@react-native/babel-preset'] };
JS
cat > metro.config.js <<'JS'
const { getDefaultConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require('@sentry/react-native/metro');

const config = getDefaultConfig(__dirname);
module.exports = withSentryConfig(config);
JS
cat > index.js <<'JS'
import { AppRegistry } from 'react-native';
import * as Sentry from '@sentry/react-native';
import App from './App';

Sentry.init({ dsn: 'https://public@example.invalid/1' });
AppRegistry.registerComponent('rnsmtest', () => Sentry.wrap(App));
JS
# Line 5 is the throw that every test event points at.
cat > App.js <<'JS'
import React from 'react';
import { Button, View } from 'react-native';

export function throwSourceMapTestError() {
  throw new Error('CLI v4 React Native source map test');
}

export default function App() {
  return (
    <View>
      <Button title="Throw" onPress={() => throwSourceMapTestError()} />
    </View>
  );
}
JS

echo "== npm install"
npm install --no-audit --no-fund --loglevel=error \
  react-native@0.88.1 react@19.3.0 \
  @react-native/metro-config@0.88.1 @react-native/babel-preset@0.88.1 \
  @react-native-community/cli@21.1.1 @sentry/react-native@8.38.0
npx sentry@4 --version

bundle() {
  npx react-native bundle \
    --dev false \
    --minify "$1" \
    --platform android \
    --entry-file index.js \
    --reset-cache \
    --bundle-output index.android.bundle \
    --sourcemap-output index.android.bundle.map
}

# Same command as the docs, plus --wait so processing errors fail the run.
upload() {
  npx sentry@4 sourcemap upload \
    --wait \
    --ext .bundle \
    --strip-prefix "$app" \
    'index.android.bundle*'
}

# Uploads the event, then polls the event API until Sentry has processed it.
# Called from `||`, so `set -e` is off in here: every step returns on failure.
send_and_check() {
  kind=$1
  node "$here/make-event.mjs" "$kind" index.android.bundle index.android.bundle.map \
    app:///index.android.bundle "out/$kind/event.json" > "out/$kind/event.txt" || return 1
  cat "out/$kind/event.txt"
  debug_id=$(sed -n 's/.*debug_id=\([0-9a-f-]*\).*/\1/p' "out/$kind/event.txt")
  event_id=$(sed -n 's/.*event_id=\([0-9a-f]*\).*/\1/p' "out/$kind/event.txt")
  if [ -z "$debug_id" ] || [ -z "$event_id" ]; then
    echo "could not read debug_id or event_id" >&2
    return 1
  fi

  echo "-- artifact lookup for $debug_id"
  if npx sentry@4 api "projects/$SENTRY_ORG/$SENTRY_PROJECT/artifact-lookup/?debug_id=$debug_id" \
    > "out/$kind/artifact-lookup.json"; then
    cat "out/$kind/artifact-lookup.json"
  else
    echo "artifact lookup failed; check the artifact bundles in the Sentry UI"
  fi

  npx sentry@4 event send "${SENTRY_DSN:-$SENTRY_ORG/$SENTRY_PROJECT}" "out/$kind/event.json" ||
    return 1
  if [ "${SKIP_EVENT_CHECK:-}" = 1 ]; then
    echo "-- check event $event_id in the Sentry UI: the frame should show App.js line 5"
    return 0
  fi
  tries=0
  until npx sentry@4 api "projects/$SENTRY_ORG/$SENTRY_PROJECT/events/$event_id/" \
    > "out/$kind/event-api.json" 2>/dev/null; do
    tries=$((tries + 1))
    if [ "$tries" -ge 30 ]; then
      echo "event $event_id not found after 5 minutes" >&2
      return 1
    fi
    sleep 10
  done
  node "$here/check-event.mjs" "out/$kind/event-api.json"
}

status=0

echo "== Hermes (docs: sourcemaps/uploading/hermes)"
mkdir -p out/hermes
bundle false
"$hermesc" -O -emit-binary -output-source-map -out=index.android.bundle.hbc index.android.bundle
rm -f index.android.bundle
mv index.android.bundle.hbc index.android.bundle
mv index.android.bundle.map index.android.bundle.packager.map
node node_modules/react-native/scripts/compose-source-maps.js \
  index.android.bundle.packager.map index.android.bundle.hbc.map -o index.android.bundle.map
node node_modules/@sentry/react-native/scripts/copy-debugid.js \
  index.android.bundle.packager.map index.android.bundle.map
rm -f index.android.bundle.packager.map
upload
send_and_check hermes || status=1
mv index.android.bundle index.android.bundle.map index.android.bundle.hbc.map out/hermes/

echo "== JSC (docs: sourcemaps/uploading/jsc)"
mkdir -p out/jsc
bundle true
upload
send_and_check jsc || status=1
mv index.android.bundle index.android.bundle.map out/jsc/

echo "== done; artifacts and API responses are in $app/out"
exit "$status"
make-event.mjs
// Build a Sentry event whose only frame points at the `throw` on App.js line 5,
// in the generated coordinates of a Hermes or JSC bundle.
//
// Usage: node make-event.mjs <hermes|jsc> <bundle> <map> <code_file> <out.json>
// Run it from the test app so `source-map` resolves from its node_modules.
import { randomUUID } from 'node:crypto';
import { readFileSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';

const [kind, bundlePath, mapPath, codeFile, outPath] = process.argv.slice(2);
if (!outPath || !['hermes', 'jsc'].includes(kind)) {
  console.error('usage: node make-event.mjs <hermes|jsc> <bundle> <map> <code_file> <out.json>');
  process.exit(2);
}

const { SourceMapConsumer } = createRequire(`${process.cwd()}/`)('source-map');
const map = JSON.parse(readFileSync(mapPath, 'utf8'));
const consumer = new SourceMapConsumer(map);
const appSource = consumer.sources.find((s) => s === 'App.js' || s.endsWith('/App.js'));
const isThrowLine = (line, column) => {
  const pos = consumer.originalPositionFor({ line, column });
  return pos.source === appSource && pos.line === 5;
};

let lineno;
let colno;
if (kind === 'hermes') {
  // Hermes frames are `1:<bytecode offset>`. Pick an offset where both the
  // 0-based and 1-based reading land on line 5, so the column base can't matter.
  const hit = consumer
    .allGeneratedPositionsFor({ source: appSource, line: 5, column: 2 })
    .find((p) => isThrowLine(p.line, p.column) && isThrowLine(p.line, p.column + 1));
  if (!hit) throw new Error('no Hermes offset maps to App.js:5');
  lineno = hit.line;
  colno = hit.column + 1;
} else {
  // JSC bundles are text: find the `throw` before the test message.
  const lines = readFileSync(bundlePath, 'utf8').split('\n');
  const index = lines.findIndex((l) => l.includes('CLI v4 React Native source map test'));
  if (index < 0) throw new Error('test message not found in bundle');
  const column = lines[index].lastIndexOf('throw', lines[index].indexOf('CLI v4 React Native'));
  if (!isThrowLine(index + 1, column)) throw new Error('throw does not map to App.js:5');
  lineno = index + 1;
  colno = column + 1;
}

const debugId = map.debug_id ?? map.debugId;
if (!debugId) throw new Error(`${mapPath} has no debug_id`);

const event = {
  event_id: randomUUID().replaceAll('-', ''),
  platform: 'javascript',
  level: 'error',
  tags: { cli_v4_rn_test: kind },
  exception: {
    values: [
      {
        type: 'Error',
        value: `CLI v4 React Native source map test (${kind})`,
        stacktrace: {
          frames: [{ filename: codeFile, abs_path: codeFile, lineno, colno, in_app: true }],
        },
      },
    ],
  },
  debug_meta: { images: [{ type: 'sourcemap', code_file: codeFile, debug_id: debugId }] },
};
writeFileSync(outPath, `${JSON.stringify(event, null, 2)}\n`);
console.log(`${kind}: debug_id=${debugId} frame=${codeFile}:${lineno}:${colno} event_id=${event.event_id}`);
check-event.mjs
// Print the processed frame of a test event and fail unless it resolved to
// App.js line 5.
//
// Usage: node check-event.mjs <event-api-response.json>
import { readFileSync } from 'node:fs';

const event = JSON.parse(readFileSync(process.argv[2], 'utf8'));
const exception = event.entries?.find((e) => e.type === 'exception');
const frame = exception?.data?.values?.[0]?.stacktrace?.frames?.at(-1);
if (!frame) {
  console.error('event has no exception frame yet');
  process.exit(1);
}
const { filename, absPath, lineNo, colNo, function: fn, context } = frame;
console.log(JSON.stringify({ filename, absPath, lineNo, colNo, function: fn }));
const contextLine = context?.find(([line]) => line === lineNo)?.[1];
if (contextLine) console.log(`context: ${contextLine.trim()}`);
const errors = event.errors ?? [];
if (errors.length) console.log(`processing errors: ${JSON.stringify(errors)}`);
const resolved = /(^|\/)App\.js$/.test(absPath ?? filename ?? '') && lineNo === 5;
console.log(resolved ? 'RESOLVED: App.js:5' : 'NOT RESOLVED');
process.exit(resolved ? 0 : 1);

via @BYK.

@sentry-junior
sentry-junior Bot requested a review from BYK December 4, 2026 19:08
@BYK
BYK marked this pull request as ready for review December 4, 2026 19:14
@cursor

cursor Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Rollout plan could not be created · Rollout details

Status Service Environment
❌ Planning failed

Rollout plan could not be created because the team reached its usage limit.

Mention @rollout in a comment to try again.

@codeowner-assignment
codeowner-assignment Bot requested a review from a team December 4, 2026 19:15

This branch was successfully deployed

1 active deployment
Preview – sentry-docs — 1615370f Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Normal Docs review has no urgent deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant