Skip to content

Commit 06c1c9c

Browse files
committed
refactor: use SENTRY_CLI_NO_TELEMETRY env var instead of disableDbTracing
Replace the in-process tracingDisabled flag and disableDbTracing() export with the existing SENTRY_CLI_NO_TELEMETRY=1 env var. The __complete fast-path sets it before any imports, and db/index.ts checks it when deciding whether to lazy-require the tracing wrapper. Removes one export, one module-level variable, and one static import.
1 parent b71cd4f commit 06c1c9c

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

src/bin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* the full CLI with telemetry, middleware, and error recovery.
77
*/
88

9-
import { disableDbTracing } from "./lib/db/index.js";
10-
119
// Exit cleanly when downstream pipe consumer closes (e.g., `sentry issue list | head`).
1210
// EPIPE (errno -32) is normal Unix behavior — not an error. Node.js/Bun ignore SIGPIPE
1311
// at the process level, so pipe write failures surface as async 'error' events on the
@@ -30,7 +28,8 @@ process.stderr.on("error", handleStreamError);
3028
* completion engine and SQLite cache modules.
3129
*/
3230
async function runCompletion(completionArgs: string[]): Promise<void> {
33-
disableDbTracing();
31+
// Disable telemetry so db/index.ts skips the @sentry/bun lazy-require (~280ms)
32+
process.env.SENTRY_CLI_NO_TELEMETRY = "1";
3433
const { handleComplete } = await import("./lib/complete.js");
3534
await handleComplete(completionArgs);
3635
}

src/lib/db/index.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ const CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
2121
/** Probability of running cleanup on write operations */
2222
const CLEANUP_PROBABILITY = 0.1;
2323

24-
/** When true, skip the Sentry tracing wrapper on the database connection. */
25-
let tracingDisabled = false;
26-
27-
/**
28-
* Disable database query tracing for this process.
29-
*
30-
* Call before the first `getDatabase()` invocation to avoid loading
31-
* `@sentry/bun` (~280ms). Used by the `__complete` fast-path where
32-
* only cached reads are needed and telemetry adds unacceptable latency.
33-
*
34-
* Follows the same pattern as {@link disableResponseCache} and
35-
* {@link disableOrgCache}.
36-
*/
37-
export function disableDbTracing(): void {
38-
tracingDisabled = true;
39-
}
40-
4124
/** Traced database wrapper (returned by getDatabase) */
4225
let db: Database | null = null;
4326
/** Raw database without tracing (used for repair operations) */
@@ -118,8 +101,8 @@ export function getDatabase(): Database {
118101

119102
// Wrap with tracing proxy for automatic query instrumentation.
120103
// Lazy-require telemetry to avoid top-level import of @sentry/bun (~280ms).
121-
// Shell completions disable tracing entirely via disableDbTracing().
122-
if (tracingDisabled) {
104+
// Shell completions set SENTRY_CLI_NO_TELEMETRY=1 to skip this entirely.
105+
if (process.env.SENTRY_CLI_NO_TELEMETRY === "1") {
123106
db = rawDb;
124107
} else {
125108
const { createTracedDatabase } = require("../telemetry.js") as {

0 commit comments

Comments
 (0)