@sentry/remix
Version:
Official Sentry SDK for Remix
98 lines (94 loc) • 2.61 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const diagnosticsChannel = require('node:diagnostics_channel');
const match = require('remix/route-pattern/match');
const core = require('@sentry/core');
const config = require('@sentry/server-utils/orchestrion/config');
const errorFilter = require('./errorFilter.js');
const middleware = require('./middleware.js');
const NOOP = () => {
};
const INJECTED = /* @__PURE__ */ Symbol.for("SentryRemixV3Injected");
let subscribed = false;
function instrumentRemixV3() {
if (subscribed || !diagnosticsChannel.tracingChannel) {
return;
}
subscribed = true;
subscribeToCreateRouter();
subscribeToCreateRequestListener();
}
function subscribeToCreateRouter() {
diagnosticsChannel.tracingChannel(config.remixV3Channels.REMIX_V3_CREATE_ROUTER).subscribe({
start(data) {
try {
injectRouterMiddleware(ensureOptions(data.arguments));
} catch {
}
},
end: NOOP,
asyncStart: NOOP,
asyncEnd: NOOP,
error: NOOP
});
}
function subscribeToCreateRequestListener() {
diagnosticsChannel.tracingChannel(
config.remixV3Channels.REMIX_V3_CREATE_REQUEST_LISTENER
).subscribe({
start(data) {
try {
injectOnError(ensureOptions(data.arguments, 1));
} catch {
}
},
end: NOOP,
asyncStart: NOOP,
asyncEnd: NOOP,
error: NOOP
});
}
function injectOnError(raw) {
if (!raw || markInjected(raw)) {
return;
}
const options = raw;
const appOnError = options.onError;
options.onError = (error) => {
errorFilter.captureRequestError(error, void 0, "auto.http.remix_v3.on_error");
if (appOnError) {
return appOnError(error);
}
core.consoleSandbox(() => {
console.error(error);
});
return void 0;
};
}
function ensureOptions(args, index = 0) {
const existing = args[index];
if (existing === void 0 || existing === null) {
const created = {};
args[index] = created;
return created;
}
return typeof existing === "object" ? existing : void 0;
}
function markInjected(raw) {
const marker = raw;
if (marker[INJECTED]) {
return true;
}
marker[INJECTED] = true;
return false;
}
function injectRouterMiddleware(raw) {
if (!raw || markInjected(raw)) {
return;
}
const options = raw;
const matcher = options.matcher ?? match.createMultiMatcher();
options.matcher = matcher;
options.middleware = [middleware.sentryRemixMiddleware(matcher), ...options.middleware ?? []];
}
exports.instrumentRemixV3 = instrumentRemixV3;
//# sourceMappingURL=instrument.js.map