Skip to content

Commit d68d71b

Browse files
sshaderConvex, Inc.
authored andcommitted
Hook up sentry reporting for local deployments (#31478)
While we're rolling out dev with local deployments and trying to identify bugs, it'll be helpful to be able to see any errors that the local backend hits (similar to being able to see errors hit by `npx convex dev` and similar from cloud deployments). This change makes it so that `npx convex dev --local` reports errors from the local backend to one of our Sentry projects -- alpha testing instructions will be updated to make this clear. We'll make this reporting opt in or at least configurable before releasing more broadly. This makes it so that local backend can generally be configured to report errors (I think we weren't calling `sentry::init` anywhere before), but only if there's a `SENTRY_DSN` env var provided. GitOrigin-RevId: f08666117de00545e3ef755fb682fdf15964f065
1 parent 849c0eb commit d68d71b

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

src/cli/index.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ import { login } from "./login.js";
1414
import { logout } from "./logout.js";
1515
import chalk from "chalk";
1616
import * as Sentry from "@sentry/node";
17-
import "@sentry/tracing";
18-
import stripAnsi from "strip-ansi";
19-
import { productionProvisionHost, provisionHost } from "./lib/config.js";
20-
import { convexImport } from "./convexImport.js";
17+
import { initSentry } from "./lib/utils/sentry.js";
2118
import { dev } from "./dev.js";
2219
import { deploy } from "./deploy.js";
2320
import { logs } from "./logs.js";
2421
import { networkTest } from "./network_test.js";
2522
import { convexExport } from "./convexExport.js";
23+
import { convexImport } from "./convexImport.js";
2624
import { env } from "./env.js";
2725
import { data } from "./data.js";
2826
import inquirer from "inquirer";
@@ -40,28 +38,10 @@ function logToStderr(...args: unknown[]) {
4038
}
4139

4240
async function main() {
43-
// If you want to use `@sentry/tracing` in your project directly, use a named import instead:
44-
// import * as SentryTracing from "@sentry/tracing"
45-
// Unused named imports are not guaranteed to patch the global hub.
46-
4741
// Use ipv4 first for 127.0.0.1 in tests
4842
dns.setDefaultResultOrder("ipv4first");
4943

50-
if (!process.env.CI && provisionHost === productionProvisionHost) {
51-
Sentry.init({
52-
dsn: "https://f9fa0306e3d540079cf40ce8c2ad9644@o1192621.ingest.sentry.io/6390839",
53-
release: "cli@" + version,
54-
tracesSampleRate: 0.2,
55-
beforeBreadcrumb: (breadcrumb) => {
56-
// Strip ANSI color codes from log lines that are sent as breadcrumbs.
57-
if (breadcrumb.message) {
58-
breadcrumb.message = stripAnsi(breadcrumb.message);
59-
}
60-
return breadcrumb;
61-
},
62-
});
63-
}
64-
44+
initSentry();
6545
inquirer.registerPrompt("search-list", inquirerSearchList);
6646

6747
const nodeVersion = process.versions.node;

src/cli/lib/localDeployment/run.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { promisify } from "util";
1313
import { Readable } from "stream";
1414
import { nodeFs } from "../../../bundler/fs.js";
1515
import detect from "detect-port";
16-
16+
import { SENTRY_DSN } from "../utils/sentry.js";
17+
import { createHash } from "crypto";
1718
const LOCAL_BACKEND_INSTANCE_SECRET =
1819
"4361726e697461732c206c69746572616c6c79206d65616e696e6720226c6974";
1920

@@ -137,11 +138,16 @@ export async function runLocalBackend(
137138
const { ports } = args;
138139
const deploymentDir = deploymentStateDir(args.deploymentName);
139140
ctx.fs.mkdir(deploymentDir, { recursive: true });
141+
const deploymentNameSha = createHash("sha256")
142+
.update(args.deploymentName)
143+
.digest("hex");
140144
const commandArgs = [
141145
"--port",
142146
ports.cloud.toString(),
143147
"--site-proxy-port",
144148
ports.site.toString(),
149+
"--sentry-identifier",
150+
deploymentNameSha,
145151
"--instance-name",
146152
args.deploymentName,
147153
"--instance-secret",
@@ -153,7 +159,13 @@ export async function runLocalBackend(
153159
const commandStr = `${args.binaryPath} ${commandArgs.join(" ")}`;
154160
logVerbose(ctx, `Starting local backend: \`${commandStr}\``);
155161
const p = child_process
156-
.spawn(args.binaryPath, commandArgs, { stdio: "ignore" })
162+
.spawn(args.binaryPath, commandArgs, {
163+
stdio: "ignore",
164+
env: {
165+
...process.env,
166+
SENTRY_DSN: SENTRY_DSN,
167+
},
168+
})
157169
.on("exit", (code) => {
158170
logVerbose(
159171
ctx,

src/cli/lib/utils/sentry.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import "@sentry/tracing";
2+
import { productionProvisionHost, provisionHost } from "../config.js";
3+
import stripAnsi from "strip-ansi";
4+
import * as Sentry from "@sentry/node";
5+
import { version } from "../../../index.js";
6+
7+
export const SENTRY_DSN =
8+
"https://f9fa0306e3d540079cf40ce8c2ad9644@o1192621.ingest.sentry.io/6390839";
9+
10+
export function initSentry() {
11+
if (!process.env.CI && provisionHost === productionProvisionHost) {
12+
Sentry.init({
13+
dsn: SENTRY_DSN,
14+
release: "cli@" + version,
15+
tracesSampleRate: 0.2,
16+
beforeBreadcrumb: (breadcrumb) => {
17+
// Strip ANSI color codes from log lines that are sent as breadcrumbs.
18+
if (breadcrumb.message) {
19+
breadcrumb.message = stripAnsi(breadcrumb.message);
20+
}
21+
return breadcrumb;
22+
},
23+
});
24+
}
25+
}

0 commit comments

Comments
 (0)