Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions apps/example/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { withSentryConfig } from "@sentry/nitro";
import { defineConfig } from "nitro";
import { juniorNitro } from "@sentry/junior/nitro";
import { juniorNitro, withSentryConfig } from "@sentry/junior/nitro";
import {
exampleDashboardAuthRequired,
exampleDashboardComponentGallery,
Expand Down
1 change: 0 additions & 1 deletion apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@sentry/junior-notion": "workspace:*",
"@sentry/junior-sentry": "workspace:*",
"@sentry/junior-vercel": "workspace:*",
"@sentry/nitro": "10.65.0",
"hono": "^4.13.11"
},
"devDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions packages/docs/src/content/docs/start-here/existing-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export const plugins = defineJuniorPlugins([sentryPlugin()]);

```ts title="nitro.config.ts"
import { defineConfig } from "nitro";
import { juniorNitro } from "@sentry/junior/nitro";
import { juniorNitro, withSentryConfig } from "@sentry/junior/nitro";

export default defineConfig({
const config = defineConfig({
modules: [
juniorNitro({
plugins: "./plugins",
Expand All @@ -66,8 +66,20 @@ export default defineConfig({
"/**": { handler: "./server.ts" },
},
});

export default withSentryConfig(config, {
authToken: process.env.SENTRY_AUTH_TOKEN,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
});
```

`withSentryConfig` uploads source maps to Sentry when the build has
`SENTRY_AUTH_TOKEN`, `SENTRY_ORG`, and `SENTRY_PROJECT`. Import it from
`@sentry/junior/nitro`. Do not add `@sentry/nitro` or `@sentry/node` to your
app. Junior pins their versions, and a different version cannot use the Sentry
client that `initSentry()` creates.

If your existing app already owns routes, make sure the Junior Hono app still receives the paths under `/api/webhooks`, `/api/oauth/callback`, `/api/internal/agent-dispatch`, `/api/internal/agent/continue`, `/api/internal/plugin/tasks`, `/api/internal/heartbeat`, and `/health`. Do not split those routes across independent runtime instances. When mounted, `@sentry/junior-dashboard` owns `/`, `/conversations`, `/conversations/*`, `/locations`, `/locations/*`, `/people`, `/people/*`, `/system`, `/system/*`, `/_junior/dashboard/client.js`, `/auth/login`, `/api/auth/*`, and the authenticated product API routes `/api/health`, `/api/runtime`, `/api/plugins`, `/api/plugins/*`, `/api/plugin-reports`, `/api/skills`, `/api/conversations`, `/api/conversations/*`, `/api/locations`, `/api/locations/*`, `/api/people`, `/api/people/*`, `/api/config`, and `/api/me`.

Some packages export runtime hooks instead of `plugin.yaml`. Add those
Expand Down
2 changes: 1 addition & 1 deletion packages/junior/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Install

```bash
pnpm add @sentry/junior hono @sentry/node
pnpm add @sentry/junior hono
```

## Quick usage
Expand Down
1 change: 1 addition & 0 deletions packages/junior/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@opentelemetry/api": "catalog:",
"@opentelemetry/core": "catalog:",
"@sentry/junior-plugin-api": "workspace:*",
"@sentry/nitro": "catalog:",
"@sentry/node": "catalog:",
"@sinclair/typebox": "^0.34.49",
"@slack/types": "^2.21.1",
Expand Down
6 changes: 2 additions & 4 deletions packages/junior/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ export const plugins = defineJuniorPlugins([
function writeNitroConfig(targetDir: string): void {
fs.writeFileSync(
path.join(targetDir, "nitro.config.ts"),
`import { withSentryConfig } from "@sentry/nitro";
import { defineConfig } from "nitro";
import { juniorNitro } from "@sentry/junior/nitro";
`import { defineConfig } from "nitro";
import { juniorNitro, withSentryConfig } from "@sentry/junior/nitro";

const config = defineConfig({
preset: "vercel",
Expand Down Expand Up @@ -185,7 +184,6 @@ export async function runInit(
"@sentry/junior": "latest",
"@sentry/junior-memory": "latest",
"@sentry/junior-maintenance": "latest",
"@sentry/nitro": "10.65.0",
hono: "^4.13.11",
},
devDependencies: {
Expand Down
27 changes: 27 additions & 0 deletions packages/junior/src/nitro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { withSentryConfig as withSentryNitroConfig } from "@sentry/nitro";
import type { Nitro } from "nitro/types";
import { applyRolldownTreeshakeWorkaround } from "@/build/rolldown-workarounds";
import {
Expand All @@ -21,6 +22,7 @@ import {
JUNIOR_RETENTION_CRON_SCHEDULE,
JUNIOR_RETENTION_ROUTE,
JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE,
getDeploymentServiceVersion,
} from "@/deployment";
import {
pluginCatalogConfigFromPluginSet,
Expand All @@ -30,6 +32,31 @@ import {
import { loadPluginSetFromModule, resolvePluginModule } from "./plugin-module";
import type { JuniorDashboardOptions } from "./app";

type SentryNitroConfig = Parameters<typeof withSentryNitroConfig>[0];
type SentryNitroOptions = NonNullable<
Parameters<typeof withSentryNitroConfig>[1]
>;

/**
* Sentry's Nitro config wrapper: source map upload and Nitro request hooks.
* Junior pins `@sentry/nitro` to the same version as its `@sentry/node`. The
* SDK keeps one client for each version, so this lets the Nitro hooks use the
* client that `initSentry()` creates. Apps import it from here, not from
* `@sentry/nitro`.
*
* The build release defaults to the release that `initSentry()` reports, so
* the uploaded source maps and the runtime events use the same release.
*/
export function withSentryConfig(
config: SentryNitroConfig,
options: SentryNitroOptions = {},
): SentryNitroConfig {
return withSentryNitroConfig(config, {
...options,
release: { name: getDeploymentServiceVersion(), ...options.release },
});
}

export type JuniorNitroDashboardOptions = JuniorDashboardOptions;

export interface JuniorPluginModuleReference {
Expand Down
7 changes: 2 additions & 5 deletions packages/junior/tests/unit/cli/init-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ describe("init cli", () => {
"utf8",
);
expect(nitroConfig).toContain(
'import { juniorNitro } from "@sentry/junior/nitro";',
);
expect(nitroConfig).toContain(
'import { withSentryConfig } from "@sentry/nitro";',
'import { juniorNitro, withSentryConfig } from "@sentry/junior/nitro";',
);
expect(nitroConfig).toContain('preset: "vercel"');
expect(nitroConfig).toContain("juniorNitro({");
Expand Down Expand Up @@ -171,7 +168,7 @@ describe("init cli", () => {
expect(pkg.dependencies["@sentry/junior"]).toBe("latest");
expect(pkg.dependencies["@sentry/junior-memory"]).toBe("latest");
expect(pkg.dependencies["@sentry/junior-maintenance"]).toBe("latest");
expect(pkg.dependencies["@sentry/nitro"]).toBe("10.65.0");
expect(pkg.dependencies["@sentry/nitro"]).toBeUndefined();
expect(pkg.devDependencies.nitro).toBeDefined();
expect(pkg.devDependencies.vite).toBeUndefined();
expect(pkg.devDependencies.vercel).toBeUndefined();
Expand Down
Loading
Loading