@tracepanel/js 0.3.4 → 0.4.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.
Files changed (59) hide show
  1. package/README.md +50 -4
  2. package/dist/agent.d.ts +23 -1
  3. package/dist/agent.js +72 -22
  4. package/dist/agent.js.map +1 -1
  5. package/dist/body.d.ts +32 -0
  6. package/dist/body.js +314 -0
  7. package/dist/body.js.map +1 -0
  8. package/dist/bullmq.d.ts +76 -1
  9. package/dist/bullmq.js +215 -6
  10. package/dist/bullmq.js.map +1 -1
  11. package/dist/bun.js +81 -11
  12. package/dist/bun.js.map +1 -1
  13. package/dist/config.d.ts +20 -0
  14. package/dist/config.js +13 -0
  15. package/dist/config.js.map +1 -1
  16. package/dist/console.d.ts +5 -0
  17. package/dist/console.js +16 -0
  18. package/dist/console.js.map +1 -1
  19. package/dist/express.js +94 -23
  20. package/dist/express.js.map +1 -1
  21. package/dist/headers.js +54 -8
  22. package/dist/headers.js.map +1 -1
  23. package/dist/inspector.d.ts +9 -0
  24. package/dist/inspector.js +47 -0
  25. package/dist/inspector.js.map +1 -0
  26. package/dist/locals.d.ts +51 -0
  27. package/dist/locals.js +269 -0
  28. package/dist/locals.js.map +1 -0
  29. package/dist/loggers.d.ts +50 -0
  30. package/dist/loggers.js +201 -0
  31. package/dist/loggers.js.map +1 -0
  32. package/dist/model.d.ts +23 -2
  33. package/dist/model.js.map +1 -1
  34. package/dist/next.js +6 -0
  35. package/dist/next.js.map +1 -1
  36. package/dist/nuxt-plugin.d.ts +1 -0
  37. package/dist/nuxt-plugin.js +6 -0
  38. package/dist/nuxt-plugin.js.map +1 -1
  39. package/dist/processor.d.ts +23 -2
  40. package/dist/processor.js +61 -14
  41. package/dist/processor.js.map +1 -1
  42. package/dist/profile.d.ts +63 -0
  43. package/dist/profile.js +300 -0
  44. package/dist/profile.js.map +1 -0
  45. package/dist/request.d.ts +61 -0
  46. package/dist/request.js +244 -0
  47. package/dist/request.js.map +1 -0
  48. package/dist/session.d.ts +10 -0
  49. package/dist/session.js +45 -0
  50. package/dist/session.js.map +1 -0
  51. package/dist/setup.js +10 -1
  52. package/dist/setup.js.map +1 -1
  53. package/dist/stack.d.ts +27 -3
  54. package/dist/stack.js +106 -9
  55. package/dist/stack.js.map +1 -1
  56. package/dist/widget.d.ts +24 -0
  57. package/dist/widget.js +62 -1
  58. package/dist/widget.js.map +1 -1
  59. package/package.json +16 -4
package/dist/locals.js ADDED
@@ -0,0 +1,269 @@
1
+ // The local variables of an error's frames, as the Python SDK keeps them: the app's own frames only, each value as
2
+ // text, cut short, the ones under a sensitive name masked. They never leave this machine.
3
+ //
4
+ // JavaScript can't look into a frame once an error left it, so the inspector stops the app as the error is thrown,
5
+ // while its frames are still there, and reads them: Debugger.setPauseOnExceptions, in a session of the app's own
6
+ // thread, which handles the pause before the throw goes on. Only while a trace runs (no pause outside one: the
7
+ // startup's module loading throws by the hundred), only an Error thrown inside a trace, at most MAX_PAUSES a second;
8
+ // a pause costs about a millisecond. An error is read where it is first thrown: its frames that run then, not
9
+ // the callers that were waiting on an `await` (those have no locals here). A process run under a debugger
10
+ // (--inspect) is left alone: its pauses would stop the debugger too.
11
+ import { inspect } from "node:util";
12
+ import { call, connect, inspector } from "./inspector.js";
13
+ import { MASK, sensitive } from "./request.js";
14
+ import { asyncFrames, inApp, parseStack } from "./stack.js";
15
+ // At most this many local variables of a frame, and the app's frames of an error, have their values kept.
16
+ const MAX_LOCALS = 40;
17
+ const MAX_FRAMES = 50;
18
+ // Pauses on errors in a second; past it, errors are thrown without one until the second is over.
19
+ const MAX_PAUSES = 50;
20
+ // Errors whose locals are kept until their trace records them, by their stack.
21
+ const MAX_ERRORS = 100;
22
+ // A value as text: a container's items cut as Python's reprlib cuts them, and the whole as long as this at most; any
23
+ // other object this long at most.
24
+ const MAX_REPR = 1000;
25
+ const MAX_OTHER = 160;
26
+ const INSPECT = { depth: 2, maxArrayLength: 10, maxStringLength: 160, breakLength: Number.POSITIVE_INFINITY };
27
+ // The scopes that are the frame's own, innermost first: its blocks and catch clauses, then its body.
28
+ const OWN_SCOPES = new Set(["block", "local", "catch", "with"]);
29
+ // The hook the paused app calls with what the debugger hands over, one for each reader.
30
+ let readers = 0;
31
+ /**
32
+ * A value as the console shows it, as Python's reprlib cuts one: a plain object, an array, a Map or a Set by its
33
+ * items, nested two deep, ten of each at most; anything else (a class's instance: a request, a connection) and a
34
+ * string at most 160 characters. Masked under a sensitive name.
35
+ */
36
+ export function repr(name, value) {
37
+ if (sensitive(name))
38
+ return MASK;
39
+ try {
40
+ // On one line: inspect() lays a long array out in rows.
41
+ const text = inspect(value, INSPECT).replace(/\s*\n\s*/g, " ");
42
+ const limit = container(value) ? MAX_REPR : MAX_OTHER;
43
+ return text.length > limit ? `${text.slice(0, limit - 3)}...` : text;
44
+ }
45
+ catch {
46
+ return `<unrepresentable ${typeof value}>`;
47
+ }
48
+ }
49
+ function container(value) {
50
+ if (typeof value === "string")
51
+ return true;
52
+ if (value === null || typeof value !== "object")
53
+ return false;
54
+ const prototype = Object.getPrototypeOf(value);
55
+ return (Array.isArray(value) ||
56
+ prototype === Object.prototype ||
57
+ prototype === null ||
58
+ value instanceof Map ||
59
+ value instanceof Set);
60
+ }
61
+ /** A frame's variables as text, from its scope objects, innermost first: an inner name hides an outer one. */
62
+ export function variables(scopes) {
63
+ const found = {};
64
+ let count = 0;
65
+ for (const scope of scopes) {
66
+ for (const name of Object.keys(scope)) {
67
+ if (count >= MAX_LOCALS)
68
+ return found;
69
+ // V8's own (.generator_object), and Python's rule for dunder names.
70
+ if (name in found || name.startsWith(".") || name.startsWith("__"))
71
+ continue;
72
+ found[name] = repr(name, scope[name]);
73
+ count += 1;
74
+ }
75
+ }
76
+ return found;
77
+ }
78
+ /**
79
+ * Whether a frame of the stack is the one the debugger has: on the same line, or of the same name. A stack mapped
80
+ * through source maps (--enable-source-maps, a TypeScript loader) has the source's lines, the debugger the code's.
81
+ */
82
+ function same(frame, callFrame) {
83
+ if (callFrame.location.lineNumber + 1 === frame.line)
84
+ return true;
85
+ const name = frame.function.replace(/^new /, "").split(".").at(-1);
86
+ return callFrame.functionName !== "" && name === callFrame.functionName;
87
+ }
88
+ /**
89
+ * Errors Next.js throws to steer a render rather than to fail it: redirect(), notFound() and the other HTTP
90
+ * fallbacks, a dynamic or client-side bail-out, a prerender's hanging promise. Each starts its stack with its message,
91
+ * the code Next.js checks for. They are thrown on ordinary requests, so they are not read and spend no pause budget.
92
+ */
93
+ const STEERING = /^(?:\w*Error: )?(?:NEXT_REDIRECT|NEXT_HTTP_ERROR_FALLBACK;|Dynamic server usage: |Bail out to client-side rendering: |During prerendering, )|^StaticGenBailoutError\b/;
94
+ /** Whether an error, by its stack, is one Next.js throws to steer a render. */
95
+ export function steers(stack) {
96
+ return STEERING.test(stack);
97
+ }
98
+ /** Reads the locals of errors thrown in a trace, for its errors to carry. */
99
+ export class Locals {
100
+ session;
101
+ root;
102
+ traceId;
103
+ tracing = false;
104
+ limited = false;
105
+ second = 0;
106
+ pauses = 0;
107
+ state = "none";
108
+ /** The objects the hook was passed. */
109
+ received;
110
+ /**
111
+ * What was read, by the error's stack (its trace records that), and the trace it was thrown in. Thrown again in the
112
+ * same trace, an error keeps its first throw's.
113
+ */
114
+ errors = new Map();
115
+ hookName = `tracepanel.locals.${++readers}`;
116
+ constructor(session, root, traceId) {
117
+ this.session = session;
118
+ this.root = root;
119
+ this.traceId = traceId;
120
+ }
121
+ /** The reader, with the inspector's debugger on; undefined where there is none, or a debugger is attached. */
122
+ static start(root, traceId) {
123
+ if (inspector()?.url())
124
+ return undefined;
125
+ const session = connect();
126
+ if (!session)
127
+ return undefined;
128
+ const locals = new Locals(session, root, traceId);
129
+ try {
130
+ call(session, "Debugger.enable");
131
+ }
132
+ catch {
133
+ session.disconnect();
134
+ return undefined;
135
+ }
136
+ globalThis[Symbol.for(locals.hookName)] = (args) => {
137
+ locals.received = args;
138
+ };
139
+ session.on("Debugger.paused", (message) => {
140
+ try {
141
+ locals.paused(message.params);
142
+ }
143
+ catch {
144
+ // Whatever went wrong, the app goes on as if nothing paused it.
145
+ }
146
+ });
147
+ return locals;
148
+ }
149
+ /** Whether a trace runs: errors pause only then. */
150
+ traces(running) {
151
+ this.tracing = running;
152
+ this.pauseOn(running && !this.limited ? "all" : "none");
153
+ }
154
+ /** The locals read for the error with this stack, taken: each error's are given once. */
155
+ take(stack) {
156
+ if (!stack)
157
+ return undefined;
158
+ const found = this.errors.get(stack);
159
+ this.errors.delete(stack);
160
+ return found?.locals;
161
+ }
162
+ pauseOn(state) {
163
+ if (state === this.state)
164
+ return;
165
+ this.state = state;
166
+ try {
167
+ call(this.session, "Debugger.setPauseOnExceptions", { state });
168
+ }
169
+ catch {
170
+ // The debugger went away: nothing pauses.
171
+ }
172
+ }
173
+ /** At most MAX_PAUSES a second: past them, no pause until the second is over. */
174
+ budget() {
175
+ const now = performance.now();
176
+ if (now - this.second >= 1000) {
177
+ this.second = now;
178
+ this.pauses = 0;
179
+ }
180
+ this.pauses += 1;
181
+ if (this.pauses <= MAX_PAUSES)
182
+ return true;
183
+ this.limited = true;
184
+ this.pauseOn("none");
185
+ setTimeout(() => {
186
+ this.limited = false;
187
+ this.pauseOn(this.tracing ? "all" : "none");
188
+ }, Math.max(1000 - (now - this.second), 1)).unref();
189
+ return false;
190
+ }
191
+ /** The objects of these ids, handed over by the paused app: called on `objectId`, the hook is passed them. */
192
+ objects(objectId, ids) {
193
+ this.received = undefined;
194
+ call(this.session, "Runtime.callFunctionOn", {
195
+ objectId,
196
+ functionDeclaration: `function (...args) { globalThis[Symbol.for("${this.hookName}")](args); }`,
197
+ arguments: ids.map((id) => ({ objectId: id })),
198
+ silent: true,
199
+ });
200
+ return this.received;
201
+ }
202
+ paused(event) {
203
+ if (event.reason !== "exception" && event.reason !== "promiseRejection")
204
+ return;
205
+ const { objectId, description: stack } = event.data ?? {};
206
+ if (event.data?.subtype !== "error" || !objectId || !stack || steers(stack) || !this.budget())
207
+ return;
208
+ const trace = this.traceId();
209
+ // The inspector describes an error by its stack. Read already in this trace, it is the same error thrown again on
210
+ // its way up.
211
+ if (trace === undefined || this.errors.get(stack)?.trace === trace)
212
+ return;
213
+ const wanted = this.frames(stack, event.callFrames);
214
+ if (wanted.length === 0)
215
+ return;
216
+ const scopes = this.objects(objectId, wanted.flatMap(({ scopes }) => scopes));
217
+ if (!scopes)
218
+ return;
219
+ const found = [];
220
+ let at = 0;
221
+ for (const frame of wanted) {
222
+ found[frame.index] = variables(scopes.slice(at, at + frame.scopes.length));
223
+ at += frame.scopes.length;
224
+ }
225
+ this.errors.delete(stack);
226
+ this.errors.set(stack, { trace, locals: found });
227
+ if (this.errors.size > MAX_ERRORS)
228
+ this.errors.delete(this.errors.keys().next().value);
229
+ }
230
+ /**
231
+ * The app's frames of the error's stack and the scopes of the frames that run them, paired by line or name: both go
232
+ * from the throw outwards. The stack's `async` callers have no frame running; its innermost frame may have none
233
+ * either, an error made in a helper and thrown by its caller. An error thrown again elsewhere (made outside a trace,
234
+ * thrown in one) has another stack than the debugger's: nothing pairs with its first frames, and none is read.
235
+ */
236
+ frames(stack, callFrames) {
237
+ const raw = parseStack(stack, false);
238
+ const mapped = parseStack(stack);
239
+ const waiting = asyncFrames(stack);
240
+ const found = [];
241
+ let next = 0;
242
+ for (const [index, frame] of raw.entries()) {
243
+ if (next === 0 && index > 1)
244
+ break;
245
+ if (waiting[index] || found.length >= MAX_FRAMES)
246
+ continue;
247
+ const match = callFrames.slice(next, next + 3).findIndex((callFrame) => same(frame, callFrame));
248
+ if (match < 0 || (next === 0 && match > 0))
249
+ continue;
250
+ const callFrame = callFrames[next + match];
251
+ next += match + 1;
252
+ if (!inApp(mapped[index]?.file ?? "", this.root))
253
+ continue;
254
+ const scopes = [];
255
+ for (const scope of callFrame.scopeChain) {
256
+ if (!OWN_SCOPES.has(scope.type))
257
+ break;
258
+ if (scope.object.objectId)
259
+ scopes.push(scope.object.objectId);
260
+ // The blocks past the function's own scope are around the function, not in it.
261
+ if (scope.type === "local")
262
+ break;
263
+ }
264
+ found.push({ index, scopes });
265
+ }
266
+ return found;
267
+ }
268
+ }
269
+ //# sourceMappingURL=locals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locals.js","sourceRoot":"","sources":["../src/locals.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,0FAA0F;AAC1F,EAAE;AACF,mHAAmH;AACnH,iHAAiH;AACjH,+GAA+G;AAC/G,qHAAqH;AACrH,8GAA8G;AAC9G,0GAA0G;AAC1G,qEAAqE;AAErE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAgB,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAmB,MAAM,YAAY,CAAC;AAE7E,0GAA0G;AAC1G,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,iGAAiG;AACjG,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,+EAA+E;AAC/E,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,qHAAqH;AACrH,kCAAkC;AAClC,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC;AAC9G,qGAAqG;AACrG,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAChE,wFAAwF;AACxF,IAAI,OAAO,GAAG,CAAC,CAAC;AAiBhB;;;;GAIG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Q,CAAC,CAAC;gBAC9D,+EAA+E;gBAC/E,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;oBAAE,MAAM;YACpC,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
2
+ import type { Attrs, Log } from "./model.js";
3
+ import type { TracepanelProcessor } from "./processor.js";
4
+ type LogRecord = Omit<Log, "span_id">;
5
+ type Fields = {
6
+ [key: string]: unknown;
7
+ };
8
+ /** A log's own fields as extra.* attributes, the way the Python SDK names the fields of `extra=`. */
9
+ export declare function extraAttrs(fields: Fields, skip?: ReadonlySet<string>): Attrs;
10
+ interface PinoSymbols {
11
+ writeSym: symbol;
12
+ messageKeySym: symbol;
13
+ errorKeySym: symbol;
14
+ }
15
+ interface PinoLogger {
16
+ bindings(): Fields;
17
+ [key: symbol]: unknown;
18
+ }
19
+ /** One call as pino's write gets it: the object logged, the message formatted, the level's number. */
20
+ export declare function pinoRecord(logger: PinoLogger, symbols: PinoSymbols, obj: unknown, msg: unknown, level: number): LogRecord;
21
+ /**
22
+ * Every pino logger, its children too, writes each enabled call through one method of the prototype they share
23
+ * (pino.symbols.writeSym): wrapped, it records the call as the app made it, whichever destination or transport the
24
+ * logger has. The prototype is reached through a logger made here that writes nowhere.
25
+ */
26
+ export declare function patchPino(exports: unknown, processor: TracepanelProcessor): void;
27
+ export declare class PinoLogs extends InstrumentationBase {
28
+ private readonly processor;
29
+ constructor(processor: TracepanelProcessor);
30
+ protected init(): InstrumentationNodeModuleDefinition;
31
+ }
32
+ declare const LEVEL: unique symbol;
33
+ declare const SPLAT: unique symbol;
34
+ /** What the app handed winston: `info` as logger.write gets it, before the logger's formats. */
35
+ export declare function winstonRecord(info: Fields & {
36
+ [LEVEL]?: unknown;
37
+ [SPLAT]?: unknown;
38
+ }): LogRecord;
39
+ /**
40
+ * Every winston logger (createLogger's, a child's, the default one) hands each call to its write() as one `info`
41
+ * object: wrapped, it records the call there, as the app made it, before the formats and whether or not a transport
42
+ * takes it later. The Console transport prints through console when told to (forceConsole): not recorded again.
43
+ */
44
+ export declare function patchWinston(exports: unknown, processor: TracepanelProcessor): void;
45
+ export declare class WinstonLogs extends InstrumentationBase {
46
+ private readonly processor;
47
+ constructor(processor: TracepanelProcessor);
48
+ protected init(): InstrumentationNodeModuleDefinition;
49
+ }
50
+ export {};
@@ -0,0 +1,201 @@
1
+ // pino's and winston's logs go to the request's or task's trace, as console's do (console.ts): the level on the same
2
+ // scale, the logger's own fields as extra.* attributes, the error with its stack. The logger still writes each one
3
+ // where the app sends it; what it prints through console is not recorded a second time.
4
+ import { format, inspect } from "node:util";
5
+ import { InstrumentationBase, InstrumentationNodeModuleDefinition } from "@opentelemetry/instrumentation";
6
+ import { quietly } from "./console.js";
7
+ import { MASK, sensitive } from "./request.js";
8
+ const WRAPPED = Symbol.for("tracepanel.loggers");
9
+ /** A log's own fields as extra.* attributes, the way the Python SDK names the fields of `extra=`. */
10
+ export function extraAttrs(fields, skip = new Set()) {
11
+ const attrs = {};
12
+ for (const [name, value] of Object.entries(fields)) {
13
+ if (skip.has(name) || value === undefined || typeof value === "function")
14
+ continue;
15
+ const key = `extra.${name
16
+ .toLowerCase()
17
+ .replace(/[^a-z0-9_]+/g, "_")
18
+ .replace(/^_+|_+$/g, "") || "value"}`;
19
+ if (sensitive(name))
20
+ attrs[key] = MASK;
21
+ else if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
22
+ attrs[key] = value;
23
+ else
24
+ attrs[key] = inspect(value, { depth: 2, breakLength: Number.POSITIVE_INFINITY, maxArrayLength: 20 });
25
+ }
26
+ return attrs;
27
+ }
28
+ /** Replaces a method once, however many times the module loads (CommonJS and ESM, or two copies of it). */
29
+ function wrap(target, key, make) {
30
+ const holder = target;
31
+ const original = holder[key];
32
+ if (typeof original !== "function" || original[WRAPPED])
33
+ return;
34
+ const wrapped = make(original);
35
+ wrapped[WRAPPED] = true;
36
+ holder[key] = wrapped;
37
+ }
38
+ /** pino's numbers: trace 10, debug 20, info 30, warn 40, error 50, fatal 60; a custom level falls between them. */
39
+ function pinoLevel(level) {
40
+ if (level >= 60)
41
+ return "critical";
42
+ if (level >= 50)
43
+ return "error";
44
+ if (level >= 40)
45
+ return "warning";
46
+ if (level >= 30)
47
+ return "info";
48
+ return "debug";
49
+ }
50
+ /** One call as pino's write gets it: the object logged, the message formatted, the level's number. */
51
+ export function pinoRecord(logger, symbols, obj, msg, level) {
52
+ const messageKey = logger[symbols.messageKeySym] ?? "msg";
53
+ const errorKey = logger[symbols.errorKeySym] ?? "err";
54
+ const { name, ...bindings } = logger.bindings();
55
+ const fields = obj instanceof Error || typeof obj !== "object" || obj === null ? {} : obj;
56
+ const error = obj instanceof Error ? obj : fields[errorKey] instanceof Error ? fields[errorKey] : null;
57
+ const message = msg ?? fields[messageKey] ?? error?.message ?? "";
58
+ return {
59
+ time: Date.now() * 1000,
60
+ level: pinoLevel(level),
61
+ logger: typeof name === "string" ? name : "pino",
62
+ message: typeof message === "string" ? message : format(message),
63
+ exception: error ? (error.stack ?? String(error)) : null,
64
+ attrs: { ...extraAttrs(bindings), ...extraAttrs(fields, new Set([messageKey, ...(error ? [errorKey] : [])])) },
65
+ };
66
+ }
67
+ /**
68
+ * Every pino logger, its children too, writes each enabled call through one method of the prototype they share
69
+ * (pino.symbols.writeSym): wrapped, it records the call as the app made it, whichever destination or transport the
70
+ * logger has. The prototype is reached through a logger made here that writes nowhere.
71
+ */
72
+ export function patchPino(exports, processor) {
73
+ const pino = (typeof exports === "function" ? exports : exports?.default);
74
+ const symbols = pino?.symbols;
75
+ if (typeof pino !== "function" || !symbols?.writeSym)
76
+ return;
77
+ const logger = pino({ level: "silent" }, { write() { } });
78
+ const prototype = Object.getPrototypeOf(Object.getPrototypeOf(logger));
79
+ if (!prototype || !Object.hasOwn(prototype, symbols.writeSym))
80
+ return;
81
+ wrap(prototype, symbols.writeSym, (original) => function (obj, msg, level, ...rest) {
82
+ if (processor.current() && typeof level === "number") {
83
+ processor.addLog(pinoRecord(this, symbols, obj, msg, level));
84
+ }
85
+ return quietly(() => original.call(this, obj, msg, level, ...rest));
86
+ });
87
+ }
88
+ export class PinoLogs extends InstrumentationBase {
89
+ processor;
90
+ constructor(processor) {
91
+ super("tracepanel-pino", "1.0.0", {});
92
+ this.processor = processor;
93
+ }
94
+ init() {
95
+ return new InstrumentationNodeModuleDefinition("pino", [">=8"], (exports) => {
96
+ patchPino(exports, this.processor);
97
+ return exports;
98
+ });
99
+ }
100
+ }
101
+ // winston
102
+ const LEVEL = Symbol.for("level");
103
+ const SPLAT = Symbol.for("splat");
104
+ // npm's levels (winston's default), syslog's and the cli's, by name: their numbers run the other way, and differ.
105
+ const WINSTON_LEVELS = {
106
+ emerg: "critical",
107
+ alert: "critical",
108
+ crit: "critical",
109
+ fatal: "critical",
110
+ error: "error",
111
+ warn: "warning",
112
+ warning: "warning",
113
+ notice: "info",
114
+ info: "info",
115
+ http: "info",
116
+ help: "info",
117
+ data: "info",
118
+ verbose: "debug",
119
+ debug: "debug",
120
+ input: "debug",
121
+ prompt: "debug",
122
+ silly: "debug",
123
+ trace: "debug",
124
+ };
125
+ const WINSTON_FIELDS = new Set(["level", "message", "stack"]);
126
+ /** The `%s` and the like in a message, which winston's splat format fills from the arguments after it. */
127
+ function placeholders(message) {
128
+ return (message.match(/%[sdifjoOc]/g) ?? []).length;
129
+ }
130
+ /** What the app handed winston: `info` as logger.write gets it, before the logger's formats. */
131
+ export function winstonRecord(info) {
132
+ const name = String(info[LEVEL] ?? info.level ?? "info");
133
+ const error = info instanceof Error ? info : (Object.values(info).find((value) => value instanceof Error) ?? null);
134
+ const fields = { ...info };
135
+ let message = info.message;
136
+ const splat = info[SPLAT];
137
+ if (typeof message === "string" && Array.isArray(splat) && placeholders(message) > 0) {
138
+ const count = placeholders(message);
139
+ message = format(message, ...splat.slice(0, count));
140
+ // The object after the message's values is its fields, as winston's splat format takes it.
141
+ for (const extra of splat.slice(count)) {
142
+ if (extra && typeof extra === "object" && !(extra instanceof Error))
143
+ Object.assign(fields, extra);
144
+ }
145
+ }
146
+ const stack = error?.stack ?? (typeof info.stack === "string" ? info.stack : null);
147
+ const skip = new Set(WINSTON_FIELDS);
148
+ for (const [key, value] of Object.entries(fields))
149
+ if (value === error)
150
+ skip.add(key);
151
+ return {
152
+ time: Date.now() * 1000,
153
+ level: WINSTON_LEVELS[name] ?? "info",
154
+ logger: "winston",
155
+ message: typeof message === "string" ? message : message === undefined ? "" : format(message),
156
+ exception: stack,
157
+ attrs: extraAttrs(fields, skip),
158
+ };
159
+ }
160
+ /**
161
+ * Every winston logger (createLogger's, a child's, the default one) hands each call to its write() as one `info`
162
+ * object: wrapped, it records the call there, as the app made it, before the formats and whether or not a transport
163
+ * takes it later. The Console transport prints through console when told to (forceConsole): not recorded again.
164
+ */
165
+ export function patchWinston(exports, processor) {
166
+ const winston = exports;
167
+ const Logger = winston.Logger ?? winston.default?.Logger;
168
+ if (Logger?.prototype) {
169
+ wrap(Logger.prototype, "write", (original) => function (info, ...rest) {
170
+ const logger = this;
171
+ if (processor.current() && info && typeof info === "object" && !logger.silent) {
172
+ const fields = info;
173
+ const level = String(fields[LEVEL] ?? fields.level);
174
+ if (typeof logger.isLevelEnabled !== "function" || logger.isLevelEnabled(level)) {
175
+ processor.addLog(winstonRecord(fields));
176
+ }
177
+ }
178
+ return quietly(() => original.call(this, info, ...rest));
179
+ });
180
+ }
181
+ const Console = (winston.transports ?? winston.default?.transports)?.Console;
182
+ if (Console?.prototype) {
183
+ wrap(Console.prototype, "log", (original) => function (...args) {
184
+ return quietly(() => original.apply(this, args));
185
+ });
186
+ }
187
+ }
188
+ export class WinstonLogs extends InstrumentationBase {
189
+ processor;
190
+ constructor(processor) {
191
+ super("tracepanel-winston", "1.0.0", {});
192
+ this.processor = processor;
193
+ }
194
+ init() {
195
+ return new InstrumentationNodeModuleDefinition("winston", [">=3"], (exports) => {
196
+ patchWinston(exports, this.processor);
197
+ return exports;
198
+ });
199
+ }
200
+ }
201
+ //# sourceMappingURL=loggers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggers.js","sourceRoot":"","sources":["../src/loggers.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,mHAAmH;AACnH,wFAAwF;AAExF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mCAAmC,EAAE,MAAM,gCAAgC,CAAC;AAC1G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAM/C,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEjD,qGAAqG;AACrG,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,IAAI,GAAwB,IAAI,GAAG,EAAE;IAC9E,MAAM,KAAK,GAAU,EAAE,CAAC;IACxB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU;YAAE,SAAS;QACnF,MAAM,GAAG,GAAG,SACV,IAAI;aACD,WAAW,EAAE;aACb,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;aAC5B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,OAChC,EAAE,CAAC;QACH,IAAI,SAAS,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;aAClC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,K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C;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/dist/model.d.ts CHANGED
@@ -26,7 +26,8 @@ export interface Frame {
26
26
  in_app: boolean;
27
27
  context_start: number | null;
28
28
  context: string[];
29
- locals: Record<string, string>;
29
+ /** The values of the frame's local variables, as text: the app's own frames, when they were read; else null. */
30
+ locals: Record<string, string> | null;
30
31
  }
31
32
  export interface TraceError {
32
33
  span_id: string | null;
@@ -50,6 +51,26 @@ export interface Trace {
50
51
  errors: TraceError[];
51
52
  links: unknown[];
52
53
  issues: unknown[];
54
+ /** Where its time went in code, when it was profiled. */
55
+ profile?: Profile;
56
+ }
57
+ /** A trace's profile: the functions its sampled stacks name, each once, and each stack as indexes into them. */
58
+ export interface Profile {
59
+ interval_us: number;
60
+ samples: number;
61
+ frames: ProfileFrame[];
62
+ stacks: {
63
+ frames: number[];
64
+ count: number;
65
+ }[];
66
+ }
67
+ export interface ProfileFrame {
68
+ function: string;
69
+ module: string | null;
70
+ file: string;
71
+ /** Where the function is defined. */
72
+ line: number;
73
+ in_app: boolean;
53
74
  }
54
75
  /** A ULID: 48 bits of milliseconds, 80 random bits, 26 characters of Crockford base32. */
55
76
  export declare function newId(now?: number): string;
@@ -60,7 +81,7 @@ export declare const MAX_SPANS = 2000;
60
81
  /** The most log records a trace keeps; the rest are counted (`tracepanel.dropped_logs`). */
61
82
  export declare const MAX_LOGS = 1000;
62
83
  /** Adds `count` to a trace's tally of what went unrecorded. */
63
- export declare function countDropped(trace: Trace, key: "tracepanel.dropped_spans" | "tracepanel.dropped_logs", count?: number): void;
84
+ export declare function countDropped(trace: Trace, key: "tracepanel.dropped_spans" | "tracepanel.dropped_logs" | "tracepanel.dropped_samples", count?: number): void;
64
85
  /**
65
86
  * The trace cut to MAX_SPANS: its earliest spans, its roots always. Spans end children first, so a cut as they end
66
87
  * would keep children whose parent went: by start, a parent always comes before its children.
package/dist/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","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ACH,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAC/G,CAAC;IACJ,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3E,YAAY,CAAC,KAAK,EAAE,0BAA0B,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAChF,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/next.js CHANGED
@@ -12,7 +12,9 @@
12
12
  // none of it is a trace of the app's.
13
13
  import http, {} from "node:http";
14
14
  import https from "node:https";
15
+ import { context } from "@opentelemetry/api";
15
16
  import { headersOnResponses } from "./headers.js";
17
+ import { ASKED as PROFILE, requested } from "./profile.js";
16
18
  import { answeredHere, browserModule, forward, PREFIX, recordingScript } from "./proxy.js";
17
19
  import { start } from "./setup.js";
18
20
  const SERVING = Symbol.for("tracepanel.next.console");
@@ -64,6 +66,10 @@ export function serveConsole(tracepanel) {
64
66
  answer(tracepanel, req, args[1]);
65
67
  return true;
66
68
  }
69
+ // A request that asks to be profiled: Next.js starts its root span in this context.
70
+ if (event === "request" && req && requested(req.headers)) {
71
+ return context.with(context.active().setValue(PROFILE, true), () => emit.call(this, event, ...args));
72
+ }
67
73
  return emit.call(this, event, ...args);
68
74
  };
69
75
  }
package/dist/next.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"next.js","sourceRoot":"","sources":["../src/next.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,0DAA0D;AAC1D,EAAE;AACF,0BAA0B;AAC1B,uCAAuC;AACvC,mGAAmG;AACnG,MAAM;AACN,EAAE;AACF,qHAAqH;AACrH,oHAAoH;AACpH,uHAAuH;AACvH,sCAAsC;AAEtC,OAAO,IAAI,EAAE,EAA6C,MAAM,WAAW,CAAC;AAC5E,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3F,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AACtD,mHAAmH;AACnH,iHAAiH;AACjH,MAAM,YAAY,GAAG,CAAC,oBAAoB,EAAE,0BAA0B,EAAE,oBAAoB,CAAC,CAAC;AAE9F,oGAAoG;AACpG,MAAM,UAAU,QAAQ;IACtB,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU;QAAE,OAAO;IACxB,kBAAkB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC1C,YAAY,CAAC,UAAU,CAAC,CAAC;AAC3B,CAAC;AAED,4GAA4G;AAC5G,SAAS,MAAM,CAAC,UAAmB,EAAE,GAAoB,EAAE,GAAmB;IAC5E,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;I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