@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
64 lines (63 loc) • 2.01 kB
JavaScript
import { getGlobalSingleton } from "../carrier.js";
// src/utils/tunnelStore.ts
/**
* Only this module touches the store, through the functions below.
*/
function getTunnelStore() {
return getGlobalSingleton("tunnelStore", () => ({ clients: /* @__PURE__ */ new WeakMap() }));
}
/**
* What the tunnel keeps for a client.
*/
function getClientTunnel(client) {
return getTunnelStore().clients.get(client);
}
/**
* Sets what the tunnel keeps for a client. Merges into what is already there, like `scope.setTags`.
*/
function setClientTunnel(client, state) {
const { clients } = getTunnelStore();
clients.set(client, {
...clients.get(client),
...state
});
}
/**
* The framework-known tunnel settings, see `setTunnelDefaults`.
*/
function getStoredTunnelDefaults() {
return getTunnelStore().defaults;
}
/**
* Replaces the framework-known tunnel settings.
*/
function setStoredTunnelDefaults(defaults) {
getTunnelStore().defaults = defaults;
}
/**
* Records that core's HTTP server instrumentation is set up. Its `emit` wrapper handles tunnel requests, so `node:http`
* servers need no second one for the tunnel.
*/
function setHttpServerHandlesTunnel() {
getTunnelStore().httpServerHandlesTunnel = true;
}
/**
* Whether core's HTTP server instrumentation handles tunnel requests, see {@link setHttpServerHandlesTunnel}.
*/
function httpServerHandlesTunnel() {
return !!getTunnelStore().httpServerHandlesTunnel;
}
/**
* Sets what answers tunnel requests on Node servers, like the forwarder `serveTunnelIntegration` brings in.
*/
function setNodeTunnelHandler(handler) {
getTunnelStore().nodeHandler = handler;
}
/**
* What answers tunnel requests on Node servers, see {@link setNodeTunnelHandler}.
*/
function getNodeTunnelHandler() {
return getTunnelStore().nodeHandler;
}
export { getClientTunnel, getNodeTunnelHandler, getStoredTunnelDefaults, httpServerHandlesTunnel, setClientTunnel, setHttpServerHandlesTunnel, setNodeTunnelHandler, setStoredTunnelDefaults };
//# sourceMappingURL=tunnelStore.js.map