Skip to content

Commit a9b564d

Browse files
committed
fix(webapp): reach SentryContextManager through the default export
The webapp server bundle is ESM and @sentry/remix is CommonJS. Node's loader derives named exports by static analysis, and it does not see SentryContextManager because that name is re-exported transitively from @sentry/node-core. A named import type-checks and bundles, then throws SyntaxError when the server boots. The property is reachable on the default export, which for a CommonJS module is module.exports. Vitest resolves the named import fine, so this only shows up when the built server actually starts.
1 parent 57b6caf commit a9b564d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

apps/webapp/app/v3/tracer.server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
metrics,
1616
type Meter,
1717
} from "@opentelemetry/api";
18-
import { SentryContextManager } from "@sentry/remix";
18+
import sentryRemix from "@sentry/remix";
1919
import { logs, SeverityNumber } from "@opentelemetry/api-logs";
2020
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
2121
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
@@ -220,9 +220,13 @@ function getResource() {
220220
* the request attributed to each Sentry event) from leaking between concurrent
221221
* requests. It extends `AsyncLocalStorageContextManager`, so OTel behaviour is
222222
* unchanged.
223+
*
224+
* Reached through the default export because `@sentry/remix` is CommonJS and
225+
* Node's ESM loader does not detect this transitively re-exported name, so a
226+
* named import resolves at build time and then fails when the server boots.
223227
*/
224228
function createContextManager() {
225-
return new SentryContextManager();
229+
return new sentryRemix.SentryContextManager();
226230
}
227231

228232
function setupTelemetry() {

apps/webapp/test/sentryRequestIsolation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { context } from "@opentelemetry/api";
22
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
33
import * as Sentry from "@sentry/remix";
4-
import { SentryContextManager } from "@sentry/remix";
4+
import sentryRemix from "@sentry/remix";
55
import { afterEach, beforeAll, describe, expect, it } from "vitest";
66

77
/**
@@ -42,7 +42,7 @@ describe("Sentry request isolation", () => {
4242
});
4343

4444
it("keeps each request's isolation scope separate with SentryContextManager", async () => {
45-
new NodeTracerProvider().register({ contextManager: new SentryContextManager() });
45+
new NodeTracerProvider().register({ contextManager: new sentryRemix.SentryContextManager() });
4646

4747
const observed = await raceTwoRequests();
4848

0 commit comments

Comments
 (0)