Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] Nov 26, 2026
76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] Nov 26, 2026
0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] Nov 26, 2026
7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
c327e56
feat(cli): add SvelteKit, Remix and React Router to sentry wizard
sentry-junior[bot] Nov 26, 2026
8aa12bc
Merge remote-tracking branch 'origin/feat/cli-wizard-shared-ast-helpe…
sentry-junior[bot] Nov 26, 2026
07f26e0
fix(cli): fix wizard CI after the scaffold merge, upload Remix maps w…
sentry-junior[bot] Nov 26, 2026
39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] Nov 26, 2026
c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
52b0642
fix(cli): keep the Remix SDK source map upload script
sentry-junior[bot] Nov 26, 2026
2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] Nov 26, 2026
ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] Nov 26, 2026
4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] Nov 26, 2026
2f2f91a
fix(mcp): regenerate the chart app after the for…of conversion
sentry-junior[bot] Nov 26, 2026
f0a48de
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] Nov 26, 2026
64a272b
fix(cli): update the SvelteKit, Remix and React Router wizards for th…
sentry-junior[bot] Nov 27, 2026
e525c83
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-svelt…
sentry-junior[bot] Nov 27, 2026
f0ece5c
fix(cli): fix review findings in the SvelteKit, Remix and React Route…
sentry-junior[bot] Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"packages/mcp-server-mocks/src/fixtures/**",
"packages/mcp-core/src/ui/chart-app.generated.ts",
"packages/codemod-cli3to4/tests/**",
"packages/cli/test/lib/wizard/**/fixtures/**",
"**/worker-configuration.d.ts",
"**/tsconfig*.json"
]
Expand Down
3 changes: 2 additions & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"**/tsconfig*.json",
"packages/mcp-server-mocks/src/fixtures/**",
"packages/mcp-core/src/ui/chart-app.generated.ts",
"packages/codemod-cli3to4/tests/**"
"packages/codemod-cli3to4/tests/**",
"packages/cli/test/lib/wizard/**/fixtures/**"
],
"rules": {
"no-unused-vars": [
Expand Down
214 changes: 214 additions & 0 deletions packages/cli/src/lib/wizard/react-router/codemods/client.entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/**
* Adds `Sentry.init` and the HydratedRouter error handler to a React Router
* app's `entry.client` file.
*/

import recast from "recast";
import type { namedTypes as t } from "ast-types";
import type { ExpressionKind } from "ast-types/lib/gen/kinds";

import { clack } from "../../utils/clack/prompts.js";
import chalk from "chalk";

import { loadFile, writeFile } from "magicast";
import { hasSentryContent } from "../../utils/ast-utils.js";
import { getDataCollectionBlock } from "../templates.js";
import { getAfterImportsInsertionIndex } from "./utils.js";

// oxlint-disable-next-line max-params -- positional like the sentry-wizard original and its tests
export async function instrumentClientEntry(
clientEntryPath: string,
dsn: string,
enableTracing: boolean,
enableReplay: boolean,
reduceDataCollection: boolean,
useInstrumentationAPI = false,
useOnError = false,
): Promise<void> {
const clientEntryAst = await loadFile(clientEntryPath);

const alreadyHasSentry = hasSentryContent(clientEntryAst.$ast as t.Program);

if (!alreadyHasSentry) {
clientEntryAst.imports.$add({
from: "@sentry/react-router",
imported: "*",
local: "Sentry",
});

let initContent: string;

if (useInstrumentationAPI && enableTracing) {
const integrations = ["tracing"];
if (enableReplay) {
integrations.push("Sentry.replayIntegration()");
}

initContent = `
const tracing = Sentry.reactRouterTracingIntegration();

Sentry.init({
dsn: "${dsn}",
${getDataCollectionBlock(reduceDataCollection)}
integrations: [${integrations.join(", ")}],
tracesSampleRate: 1.0,
tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],${
enableReplay
? "\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,"
: ""
}
});`;
} else {
const integrations = [];
if (enableTracing) {
integrations.push("Sentry.reactRouterTracingIntegration()");
}
if (enableReplay) {
integrations.push("Sentry.replayIntegration()");
}

initContent = `
Sentry.init({
dsn: "${dsn}",
${getDataCollectionBlock(reduceDataCollection)}
integrations: [${integrations.join(", ")}],
tracesSampleRate: ${enableTracing ? "1.0" : "0"},${
enableTracing
? "\n tracePropagationTargets: [/^\\//, /^https:\\/\\/yourserver\\.io\\/api/],"
: ""
}${
enableReplay
? "\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,"
: ""
}
});`;
}

(clientEntryAst.$ast as t.Program).body.splice(
getAfterImportsInsertionIndex(clientEntryAst.$ast as t.Program),
0,
...recast.parse(initContent).program.body,
);
}

const useInstrAPI = useInstrumentationAPI && enableTracing;
const addInstrProp = useInstrAPI && !alreadyHasSentry;

if (addInstrProp) {
addInstrumentationPropsToHydratedRouter(clientEntryAst.$ast as t.Program);
}

if (useOnError) {
addOnErrorToHydratedRouter(clientEntryAst.$ast as t.Program);
}

// Emit a single warning if HydratedRouter wasn't found for any prop we tried to add
if (
(addInstrProp || useOnError) &&
!hasHydratedRouter(clientEntryAst.$ast as t.Program)
) {
const props: string[] = [];
if (useOnError) {
props.push("onError={Sentry.sentryOnError}");
}
if (addInstrProp) {
props.push("instrumentations={[tracing.clientInstrumentation]}");
}
clack.log.warn(
`Could not find ${chalk.cyan(
"HydratedRouter",
)} component in your client entry file.\n` +
`Manually add the following props:\n` +
` ${chalk.green(`<HydratedRouter ${props.join(" ")} />`)}`,
);
}

await writeFile(clientEntryAst.$ast, clientEntryPath);
}

function hasHydratedRouter(ast: t.Program): boolean {
let found = false;
recast.visit(ast, {
visitJSXElement(path) {
const name = path.node.openingElement.name;
if (name.type === "JSXIdentifier" && name.name === "HydratedRouter") {
found = true;
return false;
}
this.traverse(path);
return undefined;
},
});
return found;
}

function addPropToHydratedRouter(
ast: t.Program,
propName: string,
propValue: ExpressionKind,
): boolean {
let found = false;

recast.visit(ast, {
visitJSXElement(path) {
const openingElement = path.node.openingElement;

if (
openingElement.name.type === "JSXIdentifier" &&
openingElement.name.name === "HydratedRouter"
) {
found = true;

const hasProp = openingElement.attributes?.some(
(attr) =>
attr.type === "JSXAttribute" &&
attr.name.type === "JSXIdentifier" &&
attr.name.name === propName,
);

if (!hasProp) {
const prop = recast.types.builders.jsxAttribute(
recast.types.builders.jsxIdentifier(propName),
recast.types.builders.jsxExpressionContainer(propValue),
);

if (!openingElement.attributes) {
openingElement.attributes = [];
}
openingElement.attributes.push(prop);
}

return false;
}

this.traverse(path);
return undefined;
},
});

return found;
}

function addOnErrorToHydratedRouter(ast: t.Program): boolean {
return addPropToHydratedRouter(
ast,
"onError",
recast.types.builders.memberExpression(
recast.types.builders.identifier("Sentry"),
recast.types.builders.identifier("sentryOnError"),
),
);
}

function addInstrumentationPropsToHydratedRouter(ast: t.Program): boolean {
return addPropToHydratedRouter(
ast,
"instrumentations",
recast.types.builders.arrayExpression([
recast.types.builders.memberExpression(
recast.types.builders.identifier("tracing"),
recast.types.builders.identifier("clientInstrumentation"),
),
]),
);
}
Loading
Loading