@rootcat/node 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/LICENSE +202 -0
- package/README.md +294 -2
- package/dist/attach.d.ts +1 -0
- package/dist/attach.js +24 -0
- package/dist/attach.js.map +1 -0
- package/dist/callsite.d.ts +109 -0
- package/dist/callsite.js +565 -0
- package/dist/callsite.js.map +1 -0
- package/dist/coexist.d.ts +183 -0
- package/dist/coexist.js +587 -0
- package/dist/coexist.js.map +1 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +182 -0
- package/dist/config.js.map +1 -0
- package/dist/drizzle.d.ts +21 -0
- package/dist/drizzle.js +127 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/esm.mjs +57 -0
- package/dist/esmhook.d.ts +52 -0
- package/dist/esmhook.js +158 -0
- package/dist/esmhook.js.map +1 -0
- package/dist/iitm-hook.mjs +83 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/intake.d.ts +40 -0
- package/dist/intake.js +164 -0
- package/dist/intake.js.map +1 -0
- package/dist/keys.d.ts +20 -0
- package/dist/keys.js +33 -0
- package/dist/keys.js.map +1 -0
- package/dist/notices.d.ts +2 -0
- package/dist/notices.js +21 -0
- package/dist/notices.js.map +1 -0
- package/dist/otlp.d.ts +75 -0
- package/dist/otlp.js +449 -0
- package/dist/otlp.js.map +1 -0
- package/dist/pg.d.ts +16 -0
- package/dist/pg.js +170 -0
- package/dist/pg.js.map +1 -0
- package/dist/pgpool.d.ts +20 -0
- package/dist/pgpool.js +99 -0
- package/dist/pgpool.js.map +1 -0
- package/dist/postgresjs.d.ts +60 -0
- package/dist/postgresjs.js +400 -0
- package/dist/postgresjs.js.map +1 -0
- package/dist/privacy.d.ts +38 -0
- package/dist/privacy.js +161 -0
- package/dist/privacy.js.map +1 -0
- package/dist/processor.d.ts +197 -0
- package/dist/processor.js +494 -0
- package/dist/processor.js.map +1 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +12 -0
- package/dist/register.js.map +1 -0
- package/dist/sampler.d.ts +30 -0
- package/dist/sampler.js +101 -0
- package/dist/sampler.js.map +1 -0
- package/dist/sdk.d.ts +129 -0
- package/dist/sdk.js +606 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +72 -4
package/dist/esmhook.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.drizzleModules = exports.ownedModules = exports.noInstanceLine = exports.hookedPackages = exports.esmHookMarker = void 0;
|
|
37
|
+
exports.ownInstancePossible = ownInstancePossible;
|
|
38
|
+
exports.quietESMHook = quietESMHook;
|
|
39
|
+
exports.registerESMHook = registerESMHook;
|
|
40
|
+
// The ES module loader hook from the CommonJS entry. A CommonJS
|
|
41
|
+
// application still loads ES module packages through the ESM loader
|
|
42
|
+
// (postgres.js is ESM first; Next.js imports its external packages as
|
|
43
|
+
// ES modules), and only a loader hook can patch those. The hook watches
|
|
44
|
+
// a fixed list of modules, so nothing else pays for it.
|
|
45
|
+
//
|
|
46
|
+
// It runs on the loader's hooks thread (module.register), which costs
|
|
47
|
+
// about 0.2 s of startup (every module load waits on the thread; see the
|
|
48
|
+
// benchmark). The in-thread synchronous hooks (module.registerHooks) save
|
|
49
|
+
// most of that, but in a Next.js standalone server they left postgres.js
|
|
50
|
+
// and Drizzle unpatched.
|
|
51
|
+
const fs = __importStar(require("node:fs"));
|
|
52
|
+
const nodeModule = __importStar(require("node:module"));
|
|
53
|
+
const node_url_1 = require("node:url");
|
|
54
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
55
|
+
/** esmHookMarker is set on globalThis once a hook is registered. */
|
|
56
|
+
exports.esmHookMarker = Symbol.for('rootcat.node.esmHook');
|
|
57
|
+
/**
|
|
58
|
+
* hookedPackages are the modules the loader wraps for the
|
|
59
|
+
* instrumentations. The CommonJS packages are matched whole (their
|
|
60
|
+
* internal files load through require, never through the loader). Of
|
|
61
|
+
* the ES module packages only the files the instrumentations patch are
|
|
62
|
+
* wrapped: postgres.js's entry, and Drizzle's two query classes. Wrapping
|
|
63
|
+
* every file of postgres.js would also hand its internal query.js to any
|
|
64
|
+
* other SDK's hook for it: Sentry patches that file to trace the
|
|
65
|
+
* driver's own connection queries, which it otherwise does only in
|
|
66
|
+
* CommonJS.
|
|
67
|
+
*/
|
|
68
|
+
exports.hookedPackages = /[\\/]node_modules[\\/](?:(?:pg|pg-pool|mysql2|mongodb|ioredis|redis|@redis|undici|@prisma)[\\/]|postgres[\\/](?:cjs[\\/])?src[\\/]index\.js(?:[?#].*)?$|drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs)(?:[?#].*)?$)/;
|
|
69
|
+
/**
|
|
70
|
+
* noInstanceLine is said when the installed import-in-the-middle has no
|
|
71
|
+
* create-hook.mjs: the package cannot make a hook instance of its own,
|
|
72
|
+
* and a second registration of the shared hook.mjs would replace the
|
|
73
|
+
* options of another SDK that registered it (Sentry's, behind its request
|
|
74
|
+
* isolation), so it registers none: CommonJS modules are still traced.
|
|
75
|
+
*/
|
|
76
|
+
exports.noInstanceLine = 'rootcat: the installed import-in-the-middle has no create-hook.mjs; the ES module hook is not registered (ES modules are not traced; CommonJS modules are)\n';
|
|
77
|
+
/**
|
|
78
|
+
* ownInstancePossible reports whether the import-in-the-middle copy
|
|
79
|
+
* @opentelemetry/instrumentation uses has create-hook.mjs (see
|
|
80
|
+
* iitm-hook.mjs).
|
|
81
|
+
*/
|
|
82
|
+
function ownInstancePossible() {
|
|
83
|
+
try {
|
|
84
|
+
const fromInstrumentation = nodeModule.createRequire(require.resolve('@opentelemetry/instrumentation/package.json'));
|
|
85
|
+
const hookPath = fromInstrumentation.resolve('import-in-the-middle/hook.mjs');
|
|
86
|
+
return fs.statSync(hookPath.replace(/hook\.mjs$/, 'create-hook.mjs')).isFile();
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* ownedModules are the ES module files only the package patches:
|
|
94
|
+
* postgres.js's entry and Drizzle's two query classes. Beside a tracer
|
|
95
|
+
* that records nothing, the package's hook takes them over from another
|
|
96
|
+
* import-in-the-middle hook that marked them (see iitm-hook.mjs); inside
|
|
97
|
+
* a tracer that records spans, Drizzle's only (that tracer may
|
|
98
|
+
* instrument postgres.js itself).
|
|
99
|
+
*/
|
|
100
|
+
exports.ownedModules = /[\\/]node_modules[\\/](?:postgres[\\/](?:cjs[\\/])?src[\\/]index\.js|drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs))(?:[?#].*)?$/;
|
|
101
|
+
exports.drizzleModules = /[\\/]node_modules[\\/]drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs)(?:[?#].*)?$/;
|
|
102
|
+
/** control is the port the package's hook listens on (see quietESMHook). */
|
|
103
|
+
let control;
|
|
104
|
+
/**
|
|
105
|
+
* quietESMHook makes the package's loader hook pass every module through
|
|
106
|
+
* from now on: a loader hook cannot be removed once registered, so a
|
|
107
|
+
* stopped package leaves it in place, idle.
|
|
108
|
+
*/
|
|
109
|
+
function quietESMHook() {
|
|
110
|
+
try {
|
|
111
|
+
control?.postMessage('off');
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// the hook stays as it was
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* registerESMHook registers the instrumentation loader hook once and
|
|
119
|
+
* reports whether it is in place. A failure to register never reaches the
|
|
120
|
+
* application.
|
|
121
|
+
*/
|
|
122
|
+
function registerESMHook(report = () => undefined, takeOver, include = exports.hookedPackages) {
|
|
123
|
+
const global = globalThis;
|
|
124
|
+
if (global[exports.esmHookMarker]) {
|
|
125
|
+
return 'on';
|
|
126
|
+
}
|
|
127
|
+
const registrar = nodeModule;
|
|
128
|
+
if (typeof registrar.register !== 'function') {
|
|
129
|
+
report('module.register is not available in this Node version');
|
|
130
|
+
return 'off';
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
// The package's own instance of import-in-the-middle (see
|
|
134
|
+
// iitm-hook.mjs). Both files are resolved here, by path: a file tracer
|
|
135
|
+
// (Next.js standalone output) follows require.resolve and ships them,
|
|
136
|
+
// and import-in-the-middle's hook.mjs with them.
|
|
137
|
+
require.resolve('@opentelemetry/instrumentation/hook.mjs');
|
|
138
|
+
if (!ownInstancePossible()) {
|
|
139
|
+
process.stderr.write(exports.noInstanceLine);
|
|
140
|
+
return 'off';
|
|
141
|
+
}
|
|
142
|
+
const hook = require.resolve('./iitm-hook.mjs');
|
|
143
|
+
const channel = new node_worker_threads_1.MessageChannel();
|
|
144
|
+
channel.port1.unref();
|
|
145
|
+
control = channel.port1;
|
|
146
|
+
registrar.register((0, node_url_1.pathToFileURL)(hook).href, (0, node_url_1.pathToFileURL)(__filename).href, {
|
|
147
|
+
data: { include: [include], control: channel.port2, ...(takeOver ? { takeOver } : {}) },
|
|
148
|
+
transferList: [channel.port2],
|
|
149
|
+
});
|
|
150
|
+
global[exports.esmHookMarker] = true;
|
|
151
|
+
return 'on';
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
report(error instanceof Error ? error.message : String(error));
|
|
155
|
+
return 'off';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=esmhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esmhook.js","sourceRoot":"","sources":["../src/esmhook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,kDAQC;AA2BD,oCAMC;AAOD,0CAkCC;AAlID,gEAAgE;AAChE,oEAAoE;AACpE,sEAAsE;AACtE,wEAAwE;AACxE,wDAAwD;AACxD,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,0EAA0E;AAC1E,yEAAyE;AACzE,yBAAyB;AACzB,4CAA8B;AAC9B,wDAA0C;AAC1C,uCAAyC;AACzC,6DAAuE;AAEvE,oEAAoE;AACvD,Q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@ -0,0 +1,83 @@
|
|
|
1
|
+
// The package's ES module loader hook: import-in-the-middle, as an
|
|
2
|
+
// instance of its own. import-in-the-middle's hook.mjs creates one hook
|
|
3
|
+
// at module level, so two registrations of the same file (Sentry's and
|
|
4
|
+
// the package's, when the package manager installed one copy for both)
|
|
5
|
+
// are one instance, and the second initialize() replaces the first one's
|
|
6
|
+
// options: Sentry's list of modules to wrap was lost, and with it Sentry's
|
|
7
|
+
// instrumentation of node:http. This module builds a separate instance
|
|
8
|
+
// with createHook, pointed at the same copy (so the wrapped modules call
|
|
9
|
+
// the register.js the package's instrumentations listen on). It also
|
|
10
|
+
// clears the flag import-in-the-middle sets on the hooks thread around
|
|
11
|
+
// its own initialize, so neither hook warns about the other.
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const require = createRequire(import.meta.url);
|
|
16
|
+
// The copy @opentelemetry/instrumentation depends on.
|
|
17
|
+
const fromInstrumentation = createRequire(require.resolve('@opentelemetry/instrumentation/package.json'));
|
|
18
|
+
const hookPath = fromInstrumentation.resolve('import-in-the-middle/hook.mjs');
|
|
19
|
+
|
|
20
|
+
// No fallback to the shared hook.mjs: registering it a second time
|
|
21
|
+
// replaces the options of whoever registered it first (Sentry's list of
|
|
22
|
+
// modules, and with it the instrumentation behind its request
|
|
23
|
+
// isolation). Without create-hook.mjs this module fails to load, and the
|
|
24
|
+
// package's main thread, which checks first, says so and goes on without
|
|
25
|
+
// the hook.
|
|
26
|
+
const { createHook } = await import(pathToFileURL(createHookPath(hookPath)).href);
|
|
27
|
+
const hook = createHook({ url: pathToFileURL(hookPath).href });
|
|
28
|
+
|
|
29
|
+
function createHookPath(path) {
|
|
30
|
+
return path.replace(/hook\.mjs$/, 'create-hook.mjs');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* takeOver names the modules this hook wraps even when another
|
|
35
|
+
* import-in-the-middle hook registered before it marked them for itself:
|
|
36
|
+
* Sentry 8's hook (import-in-the-middle 1.x, a copy of its own) marks
|
|
37
|
+
* every ES module, and the wrapper its copy generates never calls this
|
|
38
|
+
* copy's hooks, so postgres.js and Drizzle went unpatched. Set by the
|
|
39
|
+
* package only for modules the other SDK does not instrument (see
|
|
40
|
+
* esmhook.ts).
|
|
41
|
+
*/
|
|
42
|
+
let takeOver;
|
|
43
|
+
|
|
44
|
+
/** off is set when the package stopped (quietESMHook): every module passes through. */
|
|
45
|
+
let off = false;
|
|
46
|
+
|
|
47
|
+
export async function initialize(data) {
|
|
48
|
+
takeOver = data?.takeOver instanceof RegExp ? data.takeOver : undefined;
|
|
49
|
+
const control = data?.control;
|
|
50
|
+
if (control && typeof control.on === 'function') {
|
|
51
|
+
control.on('message', (message) => {
|
|
52
|
+
if (message === 'off') {
|
|
53
|
+
off = true;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
control.unref?.();
|
|
57
|
+
}
|
|
58
|
+
globalThis.__import_in_the_middle_initialized__ = false;
|
|
59
|
+
try {
|
|
60
|
+
await hook.initialize?.(data);
|
|
61
|
+
} finally {
|
|
62
|
+
globalThis.__import_in_the_middle_initialized__ = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function resolve(specifier, context, nextResolve) {
|
|
67
|
+
if (off) {
|
|
68
|
+
return nextResolve(specifier, context);
|
|
69
|
+
}
|
|
70
|
+
if (!takeOver) {
|
|
71
|
+
return hook.resolve(specifier, context, nextResolve);
|
|
72
|
+
}
|
|
73
|
+
return hook.resolve(specifier, context, async (next, nextContext) => {
|
|
74
|
+
const result = await nextResolve(next, nextContext);
|
|
75
|
+
if (result && typeof result.url === 'string' && result.url.includes('iitm') && takeOver.test(result.url)) {
|
|
76
|
+
const url = new URL(result.url);
|
|
77
|
+
url.searchParams.delete('iitm');
|
|
78
|
+
return { ...result, url: url.href };
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export const load = hook.load;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { start, startAlongside, rootcatSpanProcessors, current, curatedInstrumentations, instrumentationNames, otlpExporter, redisStatement, type Mode, type Started, type StartOptions } from './sdk.js';
|
|
2
|
+
export { rootcatSampler } from './sampler.js';
|
|
3
|
+
export { readConfig, serviceIdentity, tracesURL, type Config } from './config.js';
|
|
4
|
+
export { discoverIntake, defaultGateway, inContainer, type Files } from './intake.js';
|
|
5
|
+
export { captureCallSite, captureFrames, firstAppFrame, parseStack, resolveLocation, isAppFile, type CallSiteLocation } from './callsite.js';
|
|
6
|
+
export { CallSiteProcessor, CallSiteSampling, callSiteContextKey, eligible, type CallSiteProcessorOptions } from './processor.js';
|
|
7
|
+
export { PgInstrumentation } from './pg.js';
|
|
8
|
+
export { PostgresJsInstrumentation } from './postgresjs.js';
|
|
9
|
+
export { PgPoolEntryInstrumentation } from './pgpool.js';
|
|
10
|
+
export { DrizzleEntryInstrumentation } from './drizzle.js';
|
|
11
|
+
export { registerESMHook, hookedPackages, type ESMHook } from './esmhook.js';
|
|
12
|
+
export { scrubbed, stripQuery, statementKeyword } from './privacy.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statementKeyword = exports.stripQuery = exports.scrubbed = exports.hookedPackages = exports.registerESMHook = exports.DrizzleEntryInstrumentation = exports.PgPoolEntryInstrumentation = exports.PostgresJsInstrumentation = exports.PgInstrumentation = exports.eligible = exports.callSiteContextKey = exports.CallSiteSampling = exports.CallSiteProcessor = exports.isAppFile = exports.resolveLocation = exports.parseStack = exports.firstAppFrame = exports.captureFrames = exports.captureCallSite = exports.inContainer = exports.defaultGateway = exports.discoverIntake = exports.tracesURL = exports.serviceIdentity = exports.readConfig = exports.rootcatSampler = exports.redisStatement = exports.otlpExporter = exports.instrumentationNames = exports.curatedInstrumentations = exports.current = exports.rootcatSpanProcessors = exports.startAlongside = exports.start = void 0;
|
|
4
|
+
// Programmatic surface (@rootcat/node/sdk): the same start the entries
|
|
5
|
+
// call, and the pieces an application or a test may want on their own.
|
|
6
|
+
var sdk_js_1 = require("./sdk.js");
|
|
7
|
+
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return sdk_js_1.start; } });
|
|
8
|
+
Object.defineProperty(exports, "startAlongside", { enumerable: true, get: function () { return sdk_js_1.startAlongside; } });
|
|
9
|
+
Object.defineProperty(exports, "rootcatSpanProcessors", { enumerable: true, get: function () { return sdk_js_1.rootcatSpanProcessors; } });
|
|
10
|
+
Object.defineProperty(exports, "current", { enumerable: true, get: function () { return sdk_js_1.current; } });
|
|
11
|
+
Object.defineProperty(exports, "curatedInstrumentations", { enumerable: true, get: function () { return sdk_js_1.curatedInstrumentations; } });
|
|
12
|
+
Object.defineProperty(exports, "instrumentationNames", { enumerable: true, get: function () { return sdk_js_1.instrumentationNames; } });
|
|
13
|
+
Object.defineProperty(exports, "otlpExporter", { enumerable: true, get: function () { return sdk_js_1.otlpExporter; } });
|
|
14
|
+
Object.defineProperty(exports, "redisStatement", { enumerable: true, get: function () { return sdk_js_1.redisStatement; } });
|
|
15
|
+
var sampler_js_1 = require("./sampler.js");
|
|
16
|
+
Object.defineProperty(exports, "rootcatSampler", { enumerable: true, get: function () { return sampler_js_1.rootcatSampler; } });
|
|
17
|
+
var config_js_1 = require("./config.js");
|
|
18
|
+
Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return config_js_1.readConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "serviceIdentity", { enumerable: true, get: function () { return config_js_1.serviceIdentity; } });
|
|
20
|
+
Object.defineProperty(exports, "tracesURL", { enumerable: true, get: function () { return config_js_1.tracesURL; } });
|
|
21
|
+
var intake_js_1 = require("./intake.js");
|
|
22
|
+
Object.defineProperty(exports, "discoverIntake", { enumerable: true, get: function () { return intake_js_1.discoverIntake; } });
|
|
23
|
+
Object.defineProperty(exports, "defaultGateway", { enumerable: true, get: function () { return intake_js_1.defaultGateway; } });
|
|
24
|
+
Object.defineProperty(exports, "inContainer", { enumerable: true, get: function () { return intake_js_1.inContainer; } });
|
|
25
|
+
var callsite_js_1 = require("./callsite.js");
|
|
26
|
+
Object.defineProperty(exports, "captureCallSite", { enumerable: true, get: function () { return callsite_js_1.captureCallSite; } });
|
|
27
|
+
Object.defineProperty(exports, "captureFrames", { enumerable: true, get: function () { return callsite_js_1.captureFrames; } });
|
|
28
|
+
Object.defineProperty(exports, "firstAppFrame", { enumerable: true, get: function () { return callsite_js_1.firstAppFrame; } });
|
|
29
|
+
Object.defineProperty(exports, "parseStack", { enumerable: true, get: function () { return callsite_js_1.parseStack; } });
|
|
30
|
+
Object.defineProperty(exports, "resolveLocation", { enumerable: true, get: function () { return callsite_js_1.resolveLocation; } });
|
|
31
|
+
Object.defineProperty(exports, "isAppFile", { enumerable: true, get: function () { return callsite_js_1.isAppFile; } });
|
|
32
|
+
var processor_js_1 = require("./processor.js");
|
|
33
|
+
Object.defineProperty(exports, "CallSiteProcessor", { enumerable: true, get: function () { return processor_js_1.CallSiteProcessor; } });
|
|
34
|
+
Object.defineProperty(exports, "CallSiteSampling", { enumerable: true, get: function () { return processor_js_1.CallSiteSampling; } });
|
|
35
|
+
Object.defineProperty(exports, "callSiteContextKey", { enumerable: true, get: function () { return processor_js_1.callSiteContextKey; } });
|
|
36
|
+
Object.defineProperty(exports, "eligible", { enumerable: true, get: function () { return processor_js_1.eligible; } });
|
|
37
|
+
var pg_js_1 = require("./pg.js");
|
|
38
|
+
Object.defineProperty(exports, "PgInstrumentation", { enumerable: true, get: function () { return pg_js_1.PgInstrumentation; } });
|
|
39
|
+
var postgresjs_js_1 = require("./postgresjs.js");
|
|
40
|
+
Object.defineProperty(exports, "PostgresJsInstrumentation", { enumerable: true, get: function () { return postgresjs_js_1.PostgresJsInstrumentation; } });
|
|
41
|
+
var pgpool_js_1 = require("./pgpool.js");
|
|
42
|
+
Object.defineProperty(exports, "PgPoolEntryInstrumentation", { enumerable: true, get: function () { return pgpool_js_1.PgPoolEntryInstrumentation; } });
|
|
43
|
+
var drizzle_js_1 = require("./drizzle.js");
|
|
44
|
+
Object.defineProperty(exports, "DrizzleEntryInstrumentation", { enumerable: true, get: function () { return drizzle_js_1.DrizzleEntryInstrumentation; } });
|
|
45
|
+
var esmhook_js_1 = require("./esmhook.js");
|
|
46
|
+
Object.defineProperty(exports, "registerESMHook", { enumerable: true, get: function () { return esmhook_js_1.registerESMHook; } });
|
|
47
|
+
Object.defineProperty(exports, "hookedPackages", { enumerable: true, get: function () { return esmhook_js_1.hookedPackages; } });
|
|
48
|
+
var privacy_js_1 = require("./privacy.js");
|
|
49
|
+
Object.defineProperty(exports, "scrubbed", { enumerable: true, get: function () { return privacy_js_1.scrubbed; } });
|
|
50
|
+
Object.defineProperty(exports, "stripQuery", { enumerable: true, get: function () { return privacy_js_1.stripQuery; } });
|
|
51
|
+
Object.defineProperty(exports, "statementKeyword", { enumerable: true, get: function () { return privacy_js_1.statementKeyword; } });
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,uEAAuE;AACvE,mCAA0M;AAAjM,+FAAA,KAAK,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,+GAAA,qBAAqB,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,iHAAA,uBAAuB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA;AAC3I,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AACvB,yCAAkF;AAAzE,uGAAA,UAAU,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC/C,yCAAsF;AAA7E,2GAAA,cAAc,OAAA;AAAE,2GAAA,cAAc,OAAA;AAAE,wGAAA,WAAW,OAAA;AACpD,6CAA6I;AAApI,8GAAA,eAAe,OAAA;AAAE,4GAAA,aAAa,OAAA;AAAE,4GAAA,aAAa,OAAA;AAAE,yGAAA,UAAU,OAAA;AAAE,8GAAA,eAAe,OAAA;AAAE,wGAAA,SAAS,OAAA;AAC9F,+CAAkI;AAAzH,iHAAA,iBAAiB,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAAE,wGAAA,QAAQ,OAAA;AAC1E,iCAA4C;AAAnC,0GAAA,iBAAiB,OAAA;AAC1B,iDAA4D;AAAnD,0HAAA,yBAAyB,OAAA;AAClC,yCAAyD;AAAhD,uHAAA,0BAA0B,OAAA;AACnC,2CAA2D;AAAlD,yHAAA,2BAA2B,OAAA;AACpC,2CAA6E;AAApE,6GAAA,eAAe,OAAA;AAAE,4GAAA,cAAc,OAAA;AACxC,2CAAsE;AAA7D,sGAAA,QAAQ,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,8GAAA,gBAAgB,OAAA"}
|
package/dist/intake.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Files is the small file-system surface discovery needs; tests fake it. */
|
|
2
|
+
export interface Files {
|
|
3
|
+
exists(file: string): boolean;
|
|
4
|
+
read(file: string, maxBytes: number): string | undefined;
|
|
5
|
+
/** list names a directory's entries, [] when it cannot be read. */
|
|
6
|
+
list(dir: string): string[];
|
|
7
|
+
}
|
|
8
|
+
/** procFiles reads the real /proc, /sys and root. */
|
|
9
|
+
export declare const procFiles: Files;
|
|
10
|
+
/**
|
|
11
|
+
* defaultGateway parses /proc/net/route and returns the IPv4 gateway of
|
|
12
|
+
* the default route (destination 0.0.0.0 with the gateway flag set), or
|
|
13
|
+
* undefined when there is none.
|
|
14
|
+
*/
|
|
15
|
+
export declare function defaultGateway(routeTable: string): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* inContainer reports whether the process runs in a container: Docker's
|
|
18
|
+
* /.dockerenv, podman's /run/.containerenv, or a cgroup path naming a
|
|
19
|
+
* container runtime.
|
|
20
|
+
*/
|
|
21
|
+
export declare function inContainer(files: Files): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* hostNetwork reports whether the process sees the host's own network:
|
|
24
|
+
* a Docker bridge (docker0, docker_gwbridge, br-*) among the interfaces
|
|
25
|
+
* in /sys/class/net, which in a container's own network namespace lists
|
|
26
|
+
* only that namespace's interfaces. A container started with
|
|
27
|
+
* network_mode: host has /.dockerenv and the host's routing table, whose
|
|
28
|
+
* default gateway is the LAN's or the provider's router.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hostNetwork(files: Files): boolean;
|
|
31
|
+
/** privateAddress reports whether an IPv4 address is in a private or shared range. */
|
|
32
|
+
export declare function privateAddress(address: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* discoverIntake returns the agent intake's origin: the default gateway
|
|
35
|
+
* inside a container on a bridge (the bridge address the agent listens
|
|
36
|
+
* on), else loopback. A container on the host's network, or a gateway
|
|
37
|
+
* outside the private ranges, gets loopback: spans are never sent off
|
|
38
|
+
* the host by discovery.
|
|
39
|
+
*/
|
|
40
|
+
export declare function discoverIntake(files?: Files): string;
|
package/dist/intake.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.procFiles = void 0;
|
|
37
|
+
exports.defaultGateway = defaultGateway;
|
|
38
|
+
exports.inContainer = inContainer;
|
|
39
|
+
exports.hostNetwork = hostNetwork;
|
|
40
|
+
exports.privateAddress = privateAddress;
|
|
41
|
+
exports.discoverIntake = discoverIntake;
|
|
42
|
+
// Intake discovery: where the host agent's OTLP listener is from where the
|
|
43
|
+
// process runs. Inside a container the agent listens on the IPv4 address
|
|
44
|
+
// of the container's bridge, which is the container's default gateway; on
|
|
45
|
+
// the host it listens on loopback. Both come from /proc, read once,
|
|
46
|
+
// bounded.
|
|
47
|
+
const fs = __importStar(require("node:fs"));
|
|
48
|
+
const config_js_1 = require("./config.js");
|
|
49
|
+
/** Bounds on the /proc reads. */
|
|
50
|
+
const maxRouteBytes = 64 * 1024;
|
|
51
|
+
const maxCgroupBytes = 16 * 1024;
|
|
52
|
+
/** procFiles reads the real /proc, /sys and root. */
|
|
53
|
+
exports.procFiles = {
|
|
54
|
+
exists(file) {
|
|
55
|
+
try {
|
|
56
|
+
return fs.existsSync(file);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
list(dir) {
|
|
63
|
+
try {
|
|
64
|
+
return fs.readdirSync(dir).slice(0, 4096);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
read(file, maxBytes) {
|
|
71
|
+
let fd;
|
|
72
|
+
try {
|
|
73
|
+
fd = fs.openSync(file, 'r');
|
|
74
|
+
const buffer = Buffer.alloc(maxBytes);
|
|
75
|
+
const n = fs.readSync(fd, buffer, 0, maxBytes, 0);
|
|
76
|
+
return buffer.toString('utf8', 0, n);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
if (fd !== undefined) {
|
|
83
|
+
fs.closeSync(fd);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* defaultGateway parses /proc/net/route and returns the IPv4 gateway of
|
|
90
|
+
* the default route (destination 0.0.0.0 with the gateway flag set), or
|
|
91
|
+
* undefined when there is none.
|
|
92
|
+
*/
|
|
93
|
+
function defaultGateway(routeTable) {
|
|
94
|
+
const lines = routeTable.split('\n');
|
|
95
|
+
for (const line of lines.slice(1)) {
|
|
96
|
+
const fields = line.trim().split(/\s+/);
|
|
97
|
+
if (fields.length < 4) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const [, destination, gateway, flags] = fields;
|
|
101
|
+
if (destination !== '00000000' || !/^[0-9a-fA-F]{8}$/.test(gateway)) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const flagBits = Number.parseInt(flags, 16);
|
|
105
|
+
if (Number.isNaN(flagBits) || (flagBits & 0x2) === 0) {
|
|
106
|
+
continue; // RTF_GATEWAY not set
|
|
107
|
+
}
|
|
108
|
+
const value = Number.parseInt(gateway, 16);
|
|
109
|
+
if (value === 0) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
// The kernel writes the address in host byte order, little-endian on
|
|
113
|
+
// every platform Rootcat runs on.
|
|
114
|
+
const address = [value & 0xff, (value >>> 8) & 0xff, (value >>> 16) & 0xff, (value >>> 24) & 0xff].join('.');
|
|
115
|
+
return address;
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* inContainer reports whether the process runs in a container: Docker's
|
|
121
|
+
* /.dockerenv, podman's /run/.containerenv, or a cgroup path naming a
|
|
122
|
+
* container runtime.
|
|
123
|
+
*/
|
|
124
|
+
function inContainer(files) {
|
|
125
|
+
if (files.exists('/.dockerenv') || files.exists('/run/.containerenv')) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
const cgroup = files.read('/proc/1/cgroup', maxCgroupBytes) ?? '';
|
|
129
|
+
return /\/(docker|containerd|kubepods|libpod|lxc|podman)[/-]/.test(cgroup) || /:\/docker\//.test(cgroup);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* hostNetwork reports whether the process sees the host's own network:
|
|
133
|
+
* a Docker bridge (docker0, docker_gwbridge, br-*) among the interfaces
|
|
134
|
+
* in /sys/class/net, which in a container's own network namespace lists
|
|
135
|
+
* only that namespace's interfaces. A container started with
|
|
136
|
+
* network_mode: host has /.dockerenv and the host's routing table, whose
|
|
137
|
+
* default gateway is the LAN's or the provider's router.
|
|
138
|
+
*/
|
|
139
|
+
function hostNetwork(files) {
|
|
140
|
+
return files.list('/sys/class/net').some((name) => name === 'docker0' || name === 'docker_gwbridge' || name.startsWith('br-'));
|
|
141
|
+
}
|
|
142
|
+
/** privateAddress reports whether an IPv4 address is in a private or shared range. */
|
|
143
|
+
function privateAddress(address) {
|
|
144
|
+
const [a, b] = address.split('.').map(Number);
|
|
145
|
+
return a === 10 || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* discoverIntake returns the agent intake's origin: the default gateway
|
|
149
|
+
* inside a container on a bridge (the bridge address the agent listens
|
|
150
|
+
* on), else loopback. A container on the host's network, or a gateway
|
|
151
|
+
* outside the private ranges, gets loopback: spans are never sent off
|
|
152
|
+
* the host by discovery.
|
|
153
|
+
*/
|
|
154
|
+
function discoverIntake(files = exports.procFiles) {
|
|
155
|
+
if (inContainer(files) && !hostNetwork(files)) {
|
|
156
|
+
const route = files.read('/proc/net/route', maxRouteBytes);
|
|
157
|
+
const gateway = route ? defaultGateway(route) : undefined;
|
|
158
|
+
if (gateway && privateAddress(gateway)) {
|
|
159
|
+
return `http://${gateway}:${config_js_1.otlpPort}`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return `http://127.0.0.1:${config_js_1.otlpPort}`;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=intake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intake.js","sourceRoot":"","sources":["../src/intake.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,wCAyBC;AAOD,kCAMC;AAUD,kCAEC;AAGD,wCAGC;AASD,wCASC;AApID,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,oEAAoE;AACpE,WAAW;AACX,4CAA8B;AAC9B,2CAAuC;AAEvC,iCAAiC;AACjC,MAAM,aAAa,GAAG,EAAE,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC;AAUjC,qDAAqD;AACxC,QA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;QAC1D,IAAI,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,UAAU,OAAO,IAAI,oBAAQ,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;IACD,OAAO,oBAAoB,oBAAQ,EAAE,CAAC;AACxC,CAAC"}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** callSiteContextKey carries a call site through the active context. */
|
|
2
|
+
export declare const callSiteContextKey: symbol;
|
|
3
|
+
/**
|
|
4
|
+
* rootDecisionKey carries a trace decision an entry wrapper made for an
|
|
5
|
+
* operation outside any span, so the span the driver starts later is
|
|
6
|
+
* sampled as the wrapper decided (and the wrapper captured, or not, to
|
|
7
|
+
* match).
|
|
8
|
+
*/
|
|
9
|
+
export declare const rootDecisionKey: symbol;
|
|
10
|
+
/**
|
|
11
|
+
* ownWrapper marks the functions the package's instrumentations wrap a
|
|
12
|
+
* module's methods with. A wrapper found on a method is unwrapped only
|
|
13
|
+
* when it is the package's own (a second enable): another SDK's (Sentry's
|
|
14
|
+
* pg instrumentation) stays, and the package's goes around it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ownWrapper: unique symbol;
|
|
17
|
+
/** mine reports whether a method is one of the package's own wrappers. */
|
|
18
|
+
export declare function mine(method: unknown): boolean;
|
|
19
|
+
/** marked marks a wrapper as the package's own and returns it. */
|
|
20
|
+
export declare function marked<T extends Function>(wrapper: T): T;
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ownWrapper = exports.rootDecisionKey = exports.callSiteContextKey = void 0;
|
|
4
|
+
exports.mine = mine;
|
|
5
|
+
exports.marked = marked;
|
|
6
|
+
// Context keys shared by the processor, the sampler and the entry wrappers.
|
|
7
|
+
const api_1 = require("@opentelemetry/api");
|
|
8
|
+
/** callSiteContextKey carries a call site through the active context. */
|
|
9
|
+
exports.callSiteContextKey = (0, api_1.createContextKey)('rootcat.callsite');
|
|
10
|
+
/**
|
|
11
|
+
* rootDecisionKey carries a trace decision an entry wrapper made for an
|
|
12
|
+
* operation outside any span, so the span the driver starts later is
|
|
13
|
+
* sampled as the wrapper decided (and the wrapper captured, or not, to
|
|
14
|
+
* match).
|
|
15
|
+
*/
|
|
16
|
+
exports.rootDecisionKey = (0, api_1.createContextKey)('rootcat.root-decision');
|
|
17
|
+
/**
|
|
18
|
+
* ownWrapper marks the functions the package's instrumentations wrap a
|
|
19
|
+
* module's methods with. A wrapper found on a method is unwrapped only
|
|
20
|
+
* when it is the package's own (a second enable): another SDK's (Sentry's
|
|
21
|
+
* pg instrumentation) stays, and the package's goes around it.
|
|
22
|
+
*/
|
|
23
|
+
exports.ownWrapper = Symbol.for('rootcat.node.wrapper');
|
|
24
|
+
/** mine reports whether a method is one of the package's own wrappers. */
|
|
25
|
+
function mine(method) {
|
|
26
|
+
return typeof method === 'function' && method[exports.ownWrapper] === true;
|
|
27
|
+
}
|
|
28
|
+
/** marked marks a wrapper as the package's own and returns it. */
|
|
29
|
+
function marked(wrapper) {
|
|
30
|
+
wrapper[exports.ownWrapper] = true;
|
|
31
|
+
return wrapper;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAuBA,oBAEC;AAGD,wBAGC;AA/BD,4EAA4E;AAC5E,4CAAsD;AAEtD,yEAAyE;AAC5D,QAAA,kBAAkB,GAAG,IAAA,sBAAgB,EAAC,kBAAkB,CAAC,CAAC;AAEvE;;;;;GAKG;AACU,QAAA,eAAe,GAAG,IAAA,sBAAgB,EAAC,uBAAuB,CAAC,CAAC;AAEzE;;;;;GAKG;AACU,QAAA,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAE7D,0EAA0E;AAC1E,SAAgB,IAAI,CAAC,MAAe;IAClC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAK,MAA6C,CAAC,kBAAU,CAAC,KAAK,IAAI,CAAC;AAC7G,CAAC;AAED,kEAAkE;AAClE,SAAgB,MAAM,CAAqB,OAAU;IAClD,OAA8C,CAAC,kBAAU,CAAC,GAAG,IAAI,CAAC;IACnE,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/notices.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sayOnce = sayOnce;
|
|
4
|
+
// Notices the package prints on stderr, each at most once per process:
|
|
5
|
+
// the exporter's and the SDK's failures never reach the application, but
|
|
6
|
+
// an operator should learn once that spans are being lost, and why.
|
|
7
|
+
const said = new Set();
|
|
8
|
+
/** sayOnce writes a line to stderr the first time key is seen. */
|
|
9
|
+
function sayOnce(key, message) {
|
|
10
|
+
if (said.has(key)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
said.add(key);
|
|
14
|
+
try {
|
|
15
|
+
process.stderr.write(`rootcat: ${message}; this is said once\n`);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// stderr closed: nothing to do
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=notices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notices.js","sourceRoot":"","sources":["../src/notices.ts"],"names":[],"mappings":";;AAMA,0BAUC;AAhBD,uEAAuE;AACvE,yEAAyE;AACzE,oEAAoE;AACpE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;AAE/B,kEAAkE;AAClE,SAAgB,OAAO,CAAC,GAAW,EAAE,OAAe;IAClD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,uBAAuB,CAAC,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;IACjC,CAAC;AACH,CAAC"}
|