UNPKG

@sentry/remix

Version:
51 lines • 2.35 kB
/** * A browser stand-in for `node:diagnostics_channel`. * * Orchestrion's transform injects `import dc from '<dcModule>'` into every instrumented module and * drives it through Node's `tracingChannel` API. The browser has no `node:diagnostics_channel`, so * without this shim the transform cannot run on browser code. * * This implements exactly what the injected code calls, which is not the `traceSync` helpers but the * per-event channels under them: * * ```js * // The gate is true when ANY of the five event channels has a subscriber, so subscribing to `end` * // alone is enough to get the call wrapped. * if (!(ch.start.hasSubscribers || ch.end.hasSubscribers || ch.asyncStart.hasSubscribers * || ch.asyncEnd.hasSubscribers || ch.error.hasSubscribers)) return traced(); * return ch.start.runStores(ctx, () => { * try { ctx.result = traced(); } * catch (err) { ctx.error = err; ch.error.publish(ctx); throw err; } * finally { ch.end.publish(ctx); } * }); * ``` * * The browser has no `AsyncLocalStorage`, so `runStores` publishes and then calls the callback directly * instead of entering a store. The injected code does not need a store: it passes state along on the * `context` object. */ type Handler = (context: unknown) => void; interface Channel { readonly hasSubscribers: boolean; publish(context: unknown): void; runStores<T>(context: unknown, fn: (...args: unknown[]) => T, thisArg?: unknown, ...args: unknown[]): T; subscribe(handler: Handler): void; unsubscribe(handler: Handler): void; } declare const EVENTS: readonly ['start', 'end', 'asyncStart', 'asyncEnd', 'error']; type EventName = (typeof EVENTS)[number]; export type TracingChannelSubscribers = Partial<Record<EventName, Handler>>; export interface BrowserTracingChannel extends Record<EventName, Channel> { subscribe(subscribers: TracingChannelSubscribers): void; unsubscribe(subscribers: TracingChannelSubscribers): void; } declare global { var __SENTRY_REMIX_DC_REGISTRY__: Map<string, BrowserTracingChannel> | undefined; } /** Create (or look up) a tracing channel by name. */ export declare function tracingChannel(name: string): BrowserTracingChannel; declare const _default: { tracingChannel: typeof tracingChannel; }; export default _default; //# sourceMappingURL=diagnosticsChannelShim.d.ts.map