autotel 6.5.0 → 7.0.1
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/README.md +30 -23
- package/dist/{attribute-redacting-processor-Pk7lAzWd.d.cts → attribute-redacting-processor-CvBE0z1p.d.cts} +33 -1
- package/dist/{attribute-redacting-processor-Pk7lAzWd.d.ts → attribute-redacting-processor-CvBE0z1p.d.ts} +33 -1
- package/dist/attribute-redacting-processor.cjs +34 -32
- package/dist/attribute-redacting-processor.d.cts +1 -1
- package/dist/attribute-redacting-processor.d.ts +1 -1
- package/dist/attribute-redacting-processor.js +35 -32
- package/dist/{attributes-aDmJYral.cjs → attributes-Cxys8tgr.cjs} +34 -35
- package/dist/{attributes-B7wix2VG.js → attributes-Dt4YUYbP.js} +34 -35
- package/dist/attributes.cjs +1 -1
- package/dist/attributes.d.cts +1 -1
- package/dist/attributes.d.ts +1 -1
- package/dist/attributes.js +1 -1
- package/dist/auto.cjs +1 -1
- package/dist/auto.js +1 -1
- package/dist/business-baggage.cjs +19 -12
- package/dist/business-baggage.d.cts +8 -3
- package/dist/business-baggage.d.ts +8 -3
- package/dist/business-baggage.js +19 -12
- package/dist/{canonical-log-line-processor-DxtBGZIi.cjs → canonical-log-line-processor-DolzdawH.cjs} +43 -32
- package/dist/{canonical-log-line-processor-B4WgG-VS.d.cts → canonical-log-line-processor-cPB4Axk-.d.ts} +4 -3
- package/dist/{canonical-log-line-processor-B0vq_QR6.js → canonical-log-line-processor-hFUmS__K.js} +43 -32
- package/dist/{canonical-log-line-processor-CL_J7gb5.d.ts → canonical-log-line-processor-l0Aqe6yp.d.cts} +4 -3
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{correlated-events-kSwLo3mi.cjs → correlated-events-CcuknWnU.cjs} +2 -1
- package/dist/{correlated-events-Bzh5y-UB.js → correlated-events-DwMMbItg.js} +3 -1
- package/dist/correlation-id.cjs +1 -1
- package/dist/correlation-id.js +1 -1
- package/dist/db.cjs +34 -19
- package/dist/db.js +34 -19
- package/dist/decorators.cjs +4 -2
- package/dist/decorators.d.cts +16 -11
- package/dist/decorators.d.ts +16 -11
- package/dist/decorators.js +4 -2
- package/dist/{define-event-CGG048HE.d.cts → define-event-BNeuKUPv.d.cts} +1 -1
- package/dist/{define-event-B2z1SBe7.d.ts → define-event-Bd8f8mST.d.ts} +1 -1
- package/dist/diagnostics.cjs +18 -16
- package/dist/diagnostics.d.cts +14 -10
- package/dist/diagnostics.d.ts +14 -10
- package/dist/diagnostics.js +18 -16
- package/dist/{event-subscriber-CWh8sTGh.d.cts → event-subscriber-DMACQA-1.d.cts} +19 -9
- package/dist/{event-subscriber-CWh8sTGh.d.ts → event-subscriber-DMACQA-1.d.ts} +19 -9
- package/dist/event-subscriber.d.cts +2 -2
- package/dist/event-subscriber.d.ts +2 -2
- package/dist/{event-testing-D0qWfqAy.d.cts → event-testing-CBtnJXE5.d.cts} +1 -1
- package/dist/{event-testing-CA2mIx1E.d.ts → event-testing-CkPgV3Ii.d.ts} +1 -1
- package/dist/event-testing.d.cts +1 -1
- package/dist/event-testing.d.ts +1 -1
- package/dist/event.cjs +1 -1
- package/dist/event.d.cts +5 -5
- package/dist/event.d.ts +5 -5
- package/dist/event.js +1 -1
- package/dist/exception-fingerprint.cjs +133 -0
- package/dist/exception-fingerprint.d.cts +51 -0
- package/dist/exception-fingerprint.d.ts +51 -0
- package/dist/exception-fingerprint.js +126 -0
- package/dist/{functional-C0uAZq2X.cjs → functional-C2ONG9PK.cjs} +27 -15
- package/dist/{functional-e6jw5zQj.d.cts → functional-CJn2zY4o.d.cts} +96 -39
- package/dist/{functional-AT22vCw6.d.ts → functional-DXy1cHFF.d.ts} +96 -39
- package/dist/{functional-DX7Zvag0.js → functional-nS5U4KCQ.js} +27 -15
- package/dist/functional.cjs +1 -1
- package/dist/functional.d.cts +2 -2
- package/dist/functional.d.ts +2 -2
- package/dist/functional.js +1 -1
- package/dist/http.cjs +11 -8
- package/dist/http.js +11 -8
- package/dist/{index-DolOVX6F.d.ts → index-CwrNAsgk.d.ts} +22 -26
- package/dist/{index-BPcxVucm.d.cts → index-DQHf4cNl.d.cts} +22 -26
- package/dist/index.cjs +41 -35
- package/dist/index.d.cts +45 -30
- package/dist/index.d.ts +45 -30
- package/dist/index.js +41 -35
- package/dist/{init-pPI3JRRf.d.ts → init-BgnYi2sm.d.ts} +6 -6
- package/dist/{init-CTtHITlX.cjs → init-C5aHRqi2.cjs} +111 -85
- package/dist/{init-WHYwyItd.js → init-DDyaLzeg.js} +106 -86
- package/dist/{init-ncTMKZ-s.d.cts → init-DrlL1eis.d.cts} +6 -6
- package/dist/instrumentation.cjs +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{logger-D3Ej3DII.js → logger-DdPp__xW.js} +63 -54
- package/dist/{logger-CN4xpzMd.d.cts → logger-S1Fgl0g3.d.cts} +0 -20
- package/dist/{logger-CN4xpzMd.d.ts → logger-S1Fgl0g3.d.ts} +0 -20
- package/dist/{logger-thMPLpOG.cjs → logger-Sm66cjKl.cjs} +63 -54
- package/dist/logger.cjs +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/messaging-adapters.cjs +26 -12
- package/dist/messaging-adapters.d.cts +0 -30
- package/dist/messaging-adapters.d.ts +0 -30
- package/dist/messaging-adapters.js +26 -12
- package/dist/messaging.cjs +37 -34
- package/dist/messaging.d.cts +21 -62
- package/dist/messaging.d.ts +21 -62
- package/dist/messaging.js +37 -34
- package/dist/{metric-testing-CpvP3ZIa.d.cts → metric-testing-86WO1wan.d.cts} +1 -1
- package/dist/{metric-testing-CWm6UhaR.d.ts → metric-testing-CbCxdPBp.d.ts} +1 -1
- package/dist/metric-testing.d.cts +1 -1
- package/dist/metric-testing.d.ts +1 -1
- package/dist/metric.d.cts +3 -3
- package/dist/metric.d.ts +3 -3
- package/dist/{node-require-vROmTeJ8.js → node-require-DSPjaw_l.js} +3 -2
- package/dist/{node-require-PFqDihze.cjs → node-require-EifOMikz.cjs} +3 -2
- package/dist/parse-error.cjs +18 -12
- package/dist/parse-error.d.cts +2 -1
- package/dist/parse-error.d.ts +2 -1
- package/dist/parse-error.js +19 -12
- package/dist/policy.cjs +0 -0
- package/dist/policy.js +0 -0
- package/dist/processors.cjs +1 -1
- package/dist/processors.d.cts +1 -1
- package/dist/processors.d.ts +1 -1
- package/dist/processors.js +1 -1
- package/dist/{sampling-BR9fkSwx.d.cts → sampling-CM5S2Lp3.d.ts} +5 -6
- package/dist/{sampling-CP3e7-Yr.d.ts → sampling-CmRdnXUi.d.cts} +5 -6
- package/dist/sampling.cjs +3 -2
- package/dist/sampling.d.cts +1 -1
- package/dist/sampling.d.ts +1 -1
- package/dist/sampling.js +3 -2
- package/dist/semantic-helpers.cjs +9 -9
- package/dist/semantic-helpers.d.cts +1 -1
- package/dist/semantic-helpers.d.ts +1 -1
- package/dist/semantic-helpers.js +9 -9
- package/dist/{stable-hash-ChFBIhNt.js → stable-hash-BkoAYVks.js} +4 -3
- package/dist/{stable-hash-CS9BxvVQ.cjs → stable-hash-C0pOegH_.cjs} +4 -3
- package/dist/{structured-error-CHg7DoIQ.cjs → structured-error--_wXpd_C.cjs} +34 -25
- package/dist/{structured-error-9--cxBay.js → structured-error-YIuka-FE.js} +34 -25
- package/dist/test-span-collector.cjs +15 -8
- package/dist/test-span-collector.js +15 -8
- package/dist/testing.cjs +16 -18
- package/dist/testing.d.cts +7 -6
- package/dist/testing.d.ts +7 -6
- package/dist/testing.js +16 -18
- package/dist/{trace-context-IuyoPyNq.d.cts → trace-context-C1Cn1q0y.d.cts} +8 -7
- package/dist/{trace-context-IuyoPyNq.d.ts → trace-context-f89xPJbK.d.ts} +8 -7
- package/dist/trace-helpers.cjs +16 -13
- package/dist/trace-helpers.d.cts +9 -4
- package/dist/trace-helpers.d.ts +9 -4
- package/dist/trace-helpers.js +16 -13
- package/dist/tracer-provider.cjs +8 -12
- package/dist/tracer-provider.js +8 -12
- package/dist/validate.cjs +22 -20
- package/dist/validate.d.cts +3 -2
- package/dist/validate.d.ts +3 -2
- package/dist/validate.js +22 -20
- package/dist/values-BenyvWKz.js +141 -0
- package/dist/values-CeMH-mYG.d.cts +8 -0
- package/dist/values-CeMH-mYG.d.ts +8 -0
- package/dist/values-DApyq53y.cjs +267 -0
- package/dist/webhook.cjs +3 -3
- package/dist/webhook.d.cts +1 -1
- package/dist/webhook.d.ts +1 -1
- package/dist/webhook.js +3 -3
- package/dist/workflow-distributed.cjs +9 -7
- package/dist/workflow-distributed.d.cts +9 -8
- package/dist/workflow-distributed.d.ts +9 -8
- package/dist/workflow-distributed.js +9 -7
- package/dist/workflow.cjs +26 -17
- package/dist/workflow.d.cts +1 -28
- package/dist/workflow.d.ts +1 -28
- package/dist/workflow.js +26 -17
- package/dist/yaml-config.cjs +26 -11
- package/dist/yaml-config.d.cts +9 -3
- package/dist/yaml-config.d.ts +9 -3
- package/dist/yaml-config.js +26 -11
- package/package.json +6 -1
package/dist/{canonical-log-line-processor-B0vq_QR6.js → canonical-log-line-processor-hFUmS__K.js}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { i as asNumber, l as asString, p as hasProcess, s as asRecord, t as asBoolean, x as toError } from "./values-BenyvWKz.js";
|
|
1
2
|
import { SeverityNumber, logs } from "@opentelemetry/api-logs";
|
|
2
3
|
|
|
3
4
|
//#region src/pretty-log-formatter.ts
|
|
@@ -8,12 +9,12 @@ const RED = "\x1B[31m";
|
|
|
8
9
|
const YELLOW = "\x1B[33m";
|
|
9
10
|
const GREEN = "\x1B[32m";
|
|
10
11
|
const CYAN = "\x1B[36m";
|
|
11
|
-
const LEVEL_COLORS =
|
|
12
|
-
debug
|
|
13
|
-
info
|
|
14
|
-
warn
|
|
15
|
-
error
|
|
16
|
-
|
|
12
|
+
const LEVEL_COLORS = /* @__PURE__ */ new Map([
|
|
13
|
+
["debug", "\x1B[90m"],
|
|
14
|
+
["info", GREEN],
|
|
15
|
+
["warn", YELLOW],
|
|
16
|
+
["error", RED]
|
|
17
|
+
]);
|
|
17
18
|
/** Internal OTel attributes to skip in pretty output. */
|
|
18
19
|
const SKIP_PREFIXES = [
|
|
19
20
|
"telemetry.",
|
|
@@ -40,12 +41,10 @@ const SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
|
40
41
|
"http.response.status_code"
|
|
41
42
|
]);
|
|
42
43
|
function useColor() {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
44
|
+
if (!hasProcess()) return false;
|
|
45
|
+
if (process.env.NO_COLOR) return false;
|
|
46
|
+
if (process.env.FORCE_COLOR) return true;
|
|
47
|
+
return process.stdout?.isTTY === true;
|
|
49
48
|
}
|
|
50
49
|
function c(color, text) {
|
|
51
50
|
return useColor() ? `${color}${text}${RESET}` : text;
|
|
@@ -76,8 +75,10 @@ function formatTime(iso) {
|
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
77
|
function formatValue(value) {
|
|
79
|
-
|
|
80
|
-
if (
|
|
78
|
+
const text = asString(value);
|
|
79
|
+
if (text !== void 0) return text;
|
|
80
|
+
const scalar = asNumber(value) ?? asBoolean(value);
|
|
81
|
+
if (scalar !== void 0) return String(scalar);
|
|
81
82
|
if (value == null) return "";
|
|
82
83
|
try {
|
|
83
84
|
return JSON.stringify(value);
|
|
@@ -101,8 +102,13 @@ function groupAttributes(event) {
|
|
|
101
102
|
let current = tree;
|
|
102
103
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
103
104
|
const part = parts[i];
|
|
104
|
-
|
|
105
|
-
current =
|
|
105
|
+
const branch = asRecord(current[part]);
|
|
106
|
+
if (branch) current = branch;
|
|
107
|
+
else {
|
|
108
|
+
const created = {};
|
|
109
|
+
current[part] = created;
|
|
110
|
+
current = created;
|
|
111
|
+
}
|
|
106
112
|
}
|
|
107
113
|
current[parts.at(-1)] = value;
|
|
108
114
|
}
|
|
@@ -115,10 +121,11 @@ function renderTree(obj, indent, isLast) {
|
|
|
115
121
|
for (const [idx, [key, value]] of entries.entries()) {
|
|
116
122
|
const last = idx === entries.length - 1;
|
|
117
123
|
const prefix = indent + (last ? "└─" : "├─") + " ";
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
124
|
+
const nested = asRecord(value);
|
|
125
|
+
if (nested) {
|
|
126
|
+
const nestedObjs = Object.entries(nested).filter(([, v]) => asRecord(v));
|
|
127
|
+
const flatValues = Object.entries(nested).filter(([, v]) => asRecord(v) === void 0);
|
|
128
|
+
if (nestedObjs.length === 0) {
|
|
122
129
|
const inline = flatValues.map(([k, v]) => `${c(CYAN, k)}=${formatValue(v)}`).join(" ");
|
|
123
130
|
lines.push(`${prefix}${c(BOLD, key)}: ${inline}`);
|
|
124
131
|
} else {
|
|
@@ -141,7 +148,7 @@ function formatPrettyLogLine(ctx) {
|
|
|
141
148
|
const path = event["http.route"] || event["url.path"] || "";
|
|
142
149
|
const status = event["http.response.status_code"] || "";
|
|
143
150
|
const duration = formatDuration(Number(event.duration_ms ?? 0));
|
|
144
|
-
const levelStr = c(LEVEL_COLORS
|
|
151
|
+
const levelStr = c(LEVEL_COLORS.get(level) ?? "", level.toUpperCase().padEnd(5));
|
|
145
152
|
const parts = [c(DIM, timestamp), levelStr];
|
|
146
153
|
if (service) parts.push(c(DIM, `[${service}]`));
|
|
147
154
|
if (method) parts.push(c(BOLD, String(method)));
|
|
@@ -162,6 +169,12 @@ function formatPrettyLogLine(ctx) {
|
|
|
162
169
|
|
|
163
170
|
//#endregion
|
|
164
171
|
//#region src/processors/canonical-log-line-processor.ts
|
|
172
|
+
const SEVERITY_NUMBERS = /* @__PURE__ */ new Map([
|
|
173
|
+
["debug", SeverityNumber.DEBUG],
|
|
174
|
+
["info", SeverityNumber.INFO],
|
|
175
|
+
["warn", SeverityNumber.WARN],
|
|
176
|
+
["error", SeverityNumber.ERROR]
|
|
177
|
+
]);
|
|
165
178
|
/**
|
|
166
179
|
* Span processor that automatically emits spans as canonical log lines
|
|
167
180
|
*
|
|
@@ -241,7 +254,7 @@ var CanonicalLogLineProcessor = class {
|
|
|
241
254
|
this.shouldEmit = options.shouldEmit ?? this.buildKeepPredicate(options.keep);
|
|
242
255
|
this.drain = options.drain;
|
|
243
256
|
this.onDrainError = options.onDrainError;
|
|
244
|
-
this.pretty = options.pretty ?? (
|
|
257
|
+
this.pretty = options.pretty ?? (hasProcess() && process.env.NODE_ENV === "development");
|
|
245
258
|
if (!this.logger) this.getOTelLogger = () => logs.getLogger("autotel.canonical-log-line");
|
|
246
259
|
}
|
|
247
260
|
buildKeepPredicate(keep) {
|
|
@@ -319,8 +332,11 @@ var CanonicalLogLineProcessor = class {
|
|
|
319
332
|
}
|
|
320
333
|
emitViaOTel(level, message, canonicalLogLine, otelLogger) {
|
|
321
334
|
const otelAttributes = {};
|
|
322
|
-
for (const [key, value] of Object.entries(canonicalLogLine))
|
|
323
|
-
|
|
335
|
+
for (const [key, value] of Object.entries(canonicalLogLine)) {
|
|
336
|
+
const scalar = asString(value) ?? asNumber(value) ?? asBoolean(value);
|
|
337
|
+
if (scalar !== void 0) otelAttributes[key] = scalar;
|
|
338
|
+
else if (value !== null && value !== void 0) otelAttributes[key] = String(value);
|
|
339
|
+
}
|
|
324
340
|
otelLogger.emit({
|
|
325
341
|
severityNumber: this.getSeverityNumber(level),
|
|
326
342
|
severityText: level.toUpperCase(),
|
|
@@ -344,15 +360,10 @@ var CanonicalLogLineProcessor = class {
|
|
|
344
360
|
return levels.indexOf(level) >= levels.indexOf(this.minLevel);
|
|
345
361
|
}
|
|
346
362
|
getSeverityNumber(level) {
|
|
347
|
-
return
|
|
348
|
-
debug: SeverityNumber.DEBUG,
|
|
349
|
-
info: SeverityNumber.INFO,
|
|
350
|
-
warn: SeverityNumber.WARN,
|
|
351
|
-
error: SeverityNumber.ERROR
|
|
352
|
-
}[level] ?? SeverityNumber.INFO;
|
|
363
|
+
return SEVERITY_NUMBERS.get(level) ?? SeverityNumber.INFO;
|
|
353
364
|
}
|
|
354
|
-
reportInternalWarning(message,
|
|
355
|
-
const err =
|
|
365
|
+
reportInternalWarning(message, cause) {
|
|
366
|
+
const err = cause === void 0 ? "unknown error" : toError(cause).message;
|
|
356
367
|
if (this.logger) {
|
|
357
368
|
this.logger.warn({ error: err }, `[autotel] ${message}`);
|
|
358
369
|
return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as UnknownRecord } from "./values-CeMH-mYG.cjs";
|
|
2
|
+
import { s as Logger } from "./logger-S1Fgl0g3.cjs";
|
|
2
3
|
import { ReadableSpan, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
4
|
import { AttributeValue } from "@opentelemetry/api";
|
|
4
5
|
//#region src/processors/canonical-log-line-processor.d.ts
|
|
@@ -10,7 +11,7 @@ interface CanonicalLogLineEvent {
|
|
|
10
11
|
span: ReadableSpan;
|
|
11
12
|
level: 'debug' | 'info' | 'warn' | 'error';
|
|
12
13
|
message: string;
|
|
13
|
-
event:
|
|
14
|
+
event: UnknownRecord;
|
|
14
15
|
}
|
|
15
16
|
interface KeepCondition {
|
|
16
17
|
/** Keep events where HTTP status >= this value. */
|
|
@@ -50,7 +51,7 @@ interface CanonicalLogLineOptions {
|
|
|
50
51
|
/** Callback invoked after emit for custom fan-out. */
|
|
51
52
|
drain?: (ctx: CanonicalLogLineEvent) => void | Promise<void>;
|
|
52
53
|
/** Handler for drain failures. */
|
|
53
|
-
onDrainError?: (
|
|
54
|
+
onDrainError?: (cause: unknown, ctx: CanonicalLogLineEvent) => void;
|
|
54
55
|
/**
|
|
55
56
|
* Pretty-print canonical log lines to console in a tree format.
|
|
56
57
|
* Defaults to true when NODE_ENV is 'development'.
|
package/dist/config.d.cts
CHANGED
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/correlated-events.ts
|
|
3
4
|
function sanitizeEventKey(input) {
|
|
@@ -11,7 +12,7 @@ function nextSequence(target) {
|
|
|
11
12
|
}
|
|
12
13
|
function emitCorrelatedEvent(ctx, name, attrs = {}) {
|
|
13
14
|
const eventName = sanitizeEventKey(name);
|
|
14
|
-
if (
|
|
15
|
+
if (require_values.isFunction(ctx.addEvent)) {
|
|
15
16
|
ctx.addEvent.call(ctx, eventName, attrs);
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { h as isFunction } from "./values-BenyvWKz.js";
|
|
2
|
+
|
|
1
3
|
//#region src/correlated-events.ts
|
|
2
4
|
function sanitizeEventKey(input) {
|
|
3
5
|
return input.replaceAll(/[^a-zA-Z0-9_.-]/g, "_");
|
|
@@ -10,7 +12,7 @@ function nextSequence(target) {
|
|
|
10
12
|
}
|
|
11
13
|
function emitCorrelatedEvent(ctx, name, attrs = {}) {
|
|
12
14
|
const eventName = sanitizeEventKey(name);
|
|
13
|
-
if (
|
|
15
|
+
if (isFunction(ctx.addEvent)) {
|
|
14
16
|
ctx.addEvent.call(ctx, eventName, attrs);
|
|
15
17
|
return;
|
|
16
18
|
}
|
package/dist/correlation-id.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_init = require('./init-
|
|
2
|
+
const require_init = require('./init-C5aHRqi2.cjs');
|
|
3
3
|
|
|
4
4
|
exports.CORRELATION_ID_BAGGAGE_KEY = require_init.CORRELATION_ID_BAGGAGE_KEY;
|
|
5
5
|
exports.generateCorrelationId = require_init.generateCorrelationId;
|
package/dist/correlation-id.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as setCorrelationId, S as runWithCorrelationId, _ as CORRELATION_ID_BAGGAGE_KEY, b as getCorrelationStorage, v as generateCorrelationId, w as setCorrelationIdInBaggage, x as getOrCreateCorrelationId, y as getCorrelationId } from "./init-
|
|
1
|
+
import { C as setCorrelationId, S as runWithCorrelationId, _ as CORRELATION_ID_BAGGAGE_KEY, b as getCorrelationStorage, v as generateCorrelationId, w as setCorrelationIdInBaggage, x as getOrCreateCorrelationId, y as getCorrelationId } from "./init-DDyaLzeg.js";
|
|
2
2
|
|
|
3
3
|
export { CORRELATION_ID_BAGGAGE_KEY, generateCorrelationId, getCorrelationId, getCorrelationStorage, getOrCreateCorrelationId, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage };
|
package/dist/db.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
2
3
|
const require_config = require('./config.cjs');
|
|
3
4
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
4
5
|
|
|
@@ -167,7 +168,8 @@ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.db.instrumented");
|
|
|
167
168
|
* ```
|
|
168
169
|
*/
|
|
169
170
|
function instrumentDatabase(client, options) {
|
|
170
|
-
|
|
171
|
+
const target = clientMembers(client);
|
|
172
|
+
if (target[INSTRUMENTED_SYMBOL]) return client;
|
|
171
173
|
const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
|
|
172
174
|
const tracer = require_config.getConfig().tracer;
|
|
173
175
|
const methodsToInstrument = methods || extractDatabaseMethods(client);
|
|
@@ -175,10 +177,10 @@ function instrumentDatabase(client, options) {
|
|
|
175
177
|
for (const methodName of methodsToInstrument) {
|
|
176
178
|
if (skipSet.has(methodName)) continue;
|
|
177
179
|
if (methodName.startsWith("_")) continue;
|
|
178
|
-
const method =
|
|
179
|
-
if (
|
|
180
|
+
const method = require_values.asFunction(target[methodName]);
|
|
181
|
+
if (!method) continue;
|
|
180
182
|
const originalMethod = method;
|
|
181
|
-
|
|
183
|
+
target[methodName] = async function(...args) {
|
|
182
184
|
const operation = inferDbOperation(methodName);
|
|
183
185
|
const table = inferTableName(methodName);
|
|
184
186
|
const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
|
|
@@ -221,12 +223,24 @@ function instrumentDatabase(client, options) {
|
|
|
221
223
|
}
|
|
222
224
|
});
|
|
223
225
|
};
|
|
224
|
-
Object.defineProperty(
|
|
226
|
+
Object.defineProperty(target[methodName], "name", {
|
|
225
227
|
value: methodName,
|
|
226
228
|
configurable: true
|
|
227
229
|
});
|
|
228
230
|
}
|
|
229
|
-
|
|
231
|
+
target[INSTRUMENTED_SYMBOL] = true;
|
|
232
|
+
return client;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* A client's members, so the wrapper can read a method off it and write the
|
|
236
|
+
* wrapped one back.
|
|
237
|
+
*
|
|
238
|
+
* SAFETY: instrumentDatabase's whole job is to replace named methods on a
|
|
239
|
+
* client it was handed. TypeScript describes that client by the methods the
|
|
240
|
+
* caller declared, which is precisely the set being rewritten - so this says
|
|
241
|
+
* once that the client is being addressed by name.
|
|
242
|
+
*/
|
|
243
|
+
function clientMembers(client) {
|
|
230
244
|
return client;
|
|
231
245
|
}
|
|
232
246
|
/**
|
|
@@ -234,11 +248,10 @@ function instrumentDatabase(client, options) {
|
|
|
234
248
|
*/
|
|
235
249
|
function extractDatabaseMethods(client) {
|
|
236
250
|
const methods = [];
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
}
|
|
251
|
+
const own = clientMembers(client);
|
|
252
|
+
const proto = clientMembers(Object.getPrototypeOf(client) ?? {});
|
|
253
|
+
for (const key of Object.getOwnPropertyNames(client)) if (require_values.isFunction(own[key]) && !key.startsWith("_")) methods.push(key);
|
|
254
|
+
for (const key of Object.getOwnPropertyNames(proto)) if (require_values.isFunction(proto[key]) && !key.startsWith("_") && key !== "constructor") methods.push(key);
|
|
242
255
|
return [...new Set(methods)];
|
|
243
256
|
}
|
|
244
257
|
/**
|
|
@@ -247,14 +260,16 @@ function extractDatabaseMethods(client) {
|
|
|
247
260
|
function extractQueryFromArgs(args) {
|
|
248
261
|
if (args.length === 0) return void 0;
|
|
249
262
|
const firstArg = args[0];
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
263
|
+
const rawSql = require_values.asString(firstArg);
|
|
264
|
+
if (rawSql !== void 0) return rawSql;
|
|
265
|
+
const query = require_values.asRecord(firstArg);
|
|
266
|
+
if (query) {
|
|
267
|
+
const stated = require_values.asString(query.sql) ?? require_values.asString(query.text);
|
|
268
|
+
if (stated !== void 0) return stated;
|
|
269
|
+
if (require_values.isFunction(query.toQuery)) try {
|
|
270
|
+
const queryResult = query.toQuery();
|
|
271
|
+
const built = require_values.asString(queryResult) ?? require_values.asString(require_values.readProperty(queryResult, "sql"));
|
|
272
|
+
if (built !== void 0) return built;
|
|
258
273
|
} catch {}
|
|
259
274
|
}
|
|
260
275
|
}
|
package/dist/db.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _ as readProperty, h as isFunction, l as asString, r as asFunction, s as asRecord } from "./values-BenyvWKz.js";
|
|
1
2
|
import { getConfig } from "./config.js";
|
|
2
3
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
3
4
|
|
|
@@ -166,7 +167,8 @@ const INSTRUMENTED_SYMBOL = Symbol.for("autotel.db.instrumented");
|
|
|
166
167
|
* ```
|
|
167
168
|
*/
|
|
168
169
|
function instrumentDatabase(client, options) {
|
|
169
|
-
|
|
170
|
+
const target = clientMembers(client);
|
|
171
|
+
if (target[INSTRUMENTED_SYMBOL]) return client;
|
|
170
172
|
const { dbSystem, dbName, methods, skipMethods = [], sanitizeQuery = true, slowQueryThresholdMs = 1e3 } = options;
|
|
171
173
|
const tracer = getConfig().tracer;
|
|
172
174
|
const methodsToInstrument = methods || extractDatabaseMethods(client);
|
|
@@ -174,10 +176,10 @@ function instrumentDatabase(client, options) {
|
|
|
174
176
|
for (const methodName of methodsToInstrument) {
|
|
175
177
|
if (skipSet.has(methodName)) continue;
|
|
176
178
|
if (methodName.startsWith("_")) continue;
|
|
177
|
-
const method =
|
|
178
|
-
if (
|
|
179
|
+
const method = asFunction(target[methodName]);
|
|
180
|
+
if (!method) continue;
|
|
179
181
|
const originalMethod = method;
|
|
180
|
-
|
|
182
|
+
target[methodName] = async function(...args) {
|
|
181
183
|
const operation = inferDbOperation(methodName);
|
|
182
184
|
const table = inferTableName(methodName);
|
|
183
185
|
const spanName = table ? `${dbSystem}.${operation} ${table}` : `${dbSystem}.${operation}`;
|
|
@@ -220,12 +222,24 @@ function instrumentDatabase(client, options) {
|
|
|
220
222
|
}
|
|
221
223
|
});
|
|
222
224
|
};
|
|
223
|
-
Object.defineProperty(
|
|
225
|
+
Object.defineProperty(target[methodName], "name", {
|
|
224
226
|
value: methodName,
|
|
225
227
|
configurable: true
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
|
-
|
|
230
|
+
target[INSTRUMENTED_SYMBOL] = true;
|
|
231
|
+
return client;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* A client's members, so the wrapper can read a method off it and write the
|
|
235
|
+
* wrapped one back.
|
|
236
|
+
*
|
|
237
|
+
* SAFETY: instrumentDatabase's whole job is to replace named methods on a
|
|
238
|
+
* client it was handed. TypeScript describes that client by the methods the
|
|
239
|
+
* caller declared, which is precisely the set being rewritten - so this says
|
|
240
|
+
* once that the client is being addressed by name.
|
|
241
|
+
*/
|
|
242
|
+
function clientMembers(client) {
|
|
229
243
|
return client;
|
|
230
244
|
}
|
|
231
245
|
/**
|
|
@@ -233,11 +247,10 @@ function instrumentDatabase(client, options) {
|
|
|
233
247
|
*/
|
|
234
248
|
function extractDatabaseMethods(client) {
|
|
235
249
|
const methods = [];
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
}
|
|
250
|
+
const own = clientMembers(client);
|
|
251
|
+
const proto = clientMembers(Object.getPrototypeOf(client) ?? {});
|
|
252
|
+
for (const key of Object.getOwnPropertyNames(client)) if (isFunction(own[key]) && !key.startsWith("_")) methods.push(key);
|
|
253
|
+
for (const key of Object.getOwnPropertyNames(proto)) if (isFunction(proto[key]) && !key.startsWith("_") && key !== "constructor") methods.push(key);
|
|
241
254
|
return [...new Set(methods)];
|
|
242
255
|
}
|
|
243
256
|
/**
|
|
@@ -246,14 +259,16 @@ function extractDatabaseMethods(client) {
|
|
|
246
259
|
function extractQueryFromArgs(args) {
|
|
247
260
|
if (args.length === 0) return void 0;
|
|
248
261
|
const firstArg = args[0];
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
const rawSql = asString(firstArg);
|
|
263
|
+
if (rawSql !== void 0) return rawSql;
|
|
264
|
+
const query = asRecord(firstArg);
|
|
265
|
+
if (query) {
|
|
266
|
+
const stated = asString(query.sql) ?? asString(query.text);
|
|
267
|
+
if (stated !== void 0) return stated;
|
|
268
|
+
if (isFunction(query.toQuery)) try {
|
|
269
|
+
const queryResult = query.toQuery();
|
|
270
|
+
const built = asString(queryResult) ?? asString(readProperty(queryResult, "sql"));
|
|
271
|
+
if (built !== void 0) return built;
|
|
257
272
|
} catch {}
|
|
258
273
|
}
|
|
259
274
|
}
|
package/dist/decorators.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_values = require('./values-DApyq53y.cjs');
|
|
2
3
|
const require_config = require('./config.cjs');
|
|
3
|
-
const require_init = require('./init-
|
|
4
|
+
const require_init = require('./init-C5aHRqi2.cjs');
|
|
4
5
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
5
6
|
|
|
6
7
|
//#region src/decorators.ts
|
|
7
8
|
function Trace(nameOrOptions, maybeOptions) {
|
|
8
|
-
const name
|
|
9
|
+
const { name: nameArgument, options } = require_values.splitNameOrOptions(nameOrOptions);
|
|
10
|
+
const name = nameArgument ?? options?.name;
|
|
9
11
|
return function(originalMethod, context) {
|
|
10
12
|
const methodName = String(context.name);
|
|
11
13
|
const methodStr = originalMethod?.toString() || "";
|
package/dist/decorators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as TraceContext } from "./trace-context-
|
|
2
|
-
import { m as TracingOptions } from "./functional-
|
|
1
|
+
import { n as TraceContext } from "./trace-context-C1Cn1q0y.cjs";
|
|
2
|
+
import { m as TracingOptions } from "./functional-CJn2zY4o.cjs";
|
|
3
3
|
//#region src/decorators.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Options for @Trace method decorator
|
|
@@ -10,6 +10,15 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
10
10
|
*/
|
|
11
11
|
name?: string;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The receiver of a decorated method. `@Trace` lends the method its span's
|
|
15
|
+
* context for the duration of the call, and puts back whatever was there.
|
|
16
|
+
*/
|
|
17
|
+
interface WithTraceContext {
|
|
18
|
+
ctx?: TraceContext;
|
|
19
|
+
}
|
|
20
|
+
/** The decorator a `@Trace(...)` call produces. */
|
|
21
|
+
type TraceDecorator = <TArgs extends unknown[], TResult>(originalMethod: (...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext) => (...args: TArgs) => Promise<TResult>;
|
|
13
22
|
/**
|
|
14
23
|
* @Trace - Method decorator for fine-grained tracing
|
|
15
24
|
*
|
|
@@ -39,15 +48,11 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
39
48
|
*
|
|
40
49
|
* @example Accessing ctx
|
|
41
50
|
* ```typescript
|
|
42
|
-
* interface WithTraceContext {
|
|
43
|
-
* ctx?: TraceContext
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
51
|
* class UserService {
|
|
47
52
|
* @Trace()
|
|
48
|
-
* async createUser(data: UserData) {
|
|
53
|
+
* async createUser(this: WithTraceContext, data: UserData) {
|
|
49
54
|
* // Access ctx via this.ctx (available during execution)
|
|
50
|
-
* const ctx =
|
|
55
|
+
* const ctx = this.ctx
|
|
51
56
|
* if (ctx) {
|
|
52
57
|
* ctx.setAttribute('user.id', data.id)
|
|
53
58
|
* }
|
|
@@ -56,7 +61,7 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
56
61
|
* }
|
|
57
62
|
* ```
|
|
58
63
|
*/
|
|
59
|
-
declare function Trace(options?: TraceDecoratorOptions):
|
|
60
|
-
declare function Trace(name?: string, options?: TraceDecoratorOptions):
|
|
64
|
+
declare function Trace(options?: TraceDecoratorOptions): TraceDecorator;
|
|
65
|
+
declare function Trace(name?: string, options?: TraceDecoratorOptions): TraceDecorator;
|
|
61
66
|
//#endregion
|
|
62
|
-
export { Trace, type TraceContext, TraceDecoratorOptions, type TracingOptions };
|
|
67
|
+
export { Trace, type TraceContext, TraceDecorator, TraceDecoratorOptions, type TracingOptions, WithTraceContext };
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as TraceContext } from "./trace-context-
|
|
2
|
-
import { m as TracingOptions } from "./functional-
|
|
1
|
+
import { n as TraceContext } from "./trace-context-f89xPJbK.js";
|
|
2
|
+
import { m as TracingOptions } from "./functional-DXy1cHFF.js";
|
|
3
3
|
//#region src/decorators.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Options for @Trace method decorator
|
|
@@ -10,6 +10,15 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
10
10
|
*/
|
|
11
11
|
name?: string;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The receiver of a decorated method. `@Trace` lends the method its span's
|
|
15
|
+
* context for the duration of the call, and puts back whatever was there.
|
|
16
|
+
*/
|
|
17
|
+
interface WithTraceContext {
|
|
18
|
+
ctx?: TraceContext;
|
|
19
|
+
}
|
|
20
|
+
/** The decorator a `@Trace(...)` call produces. */
|
|
21
|
+
type TraceDecorator = <TArgs extends unknown[], TResult>(originalMethod: (...args: TArgs) => Promise<TResult>, context: ClassMethodDecoratorContext) => (...args: TArgs) => Promise<TResult>;
|
|
13
22
|
/**
|
|
14
23
|
* @Trace - Method decorator for fine-grained tracing
|
|
15
24
|
*
|
|
@@ -39,15 +48,11 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
39
48
|
*
|
|
40
49
|
* @example Accessing ctx
|
|
41
50
|
* ```typescript
|
|
42
|
-
* interface WithTraceContext {
|
|
43
|
-
* ctx?: TraceContext
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
51
|
* class UserService {
|
|
47
52
|
* @Trace()
|
|
48
|
-
* async createUser(data: UserData) {
|
|
53
|
+
* async createUser(this: WithTraceContext, data: UserData) {
|
|
49
54
|
* // Access ctx via this.ctx (available during execution)
|
|
50
|
-
* const ctx =
|
|
55
|
+
* const ctx = this.ctx
|
|
51
56
|
* if (ctx) {
|
|
52
57
|
* ctx.setAttribute('user.id', data.id)
|
|
53
58
|
* }
|
|
@@ -56,7 +61,7 @@ interface TraceDecoratorOptions extends Omit<TracingOptions, 'name'> {
|
|
|
56
61
|
* }
|
|
57
62
|
* ```
|
|
58
63
|
*/
|
|
59
|
-
declare function Trace(options?: TraceDecoratorOptions):
|
|
60
|
-
declare function Trace(name?: string, options?: TraceDecoratorOptions):
|
|
64
|
+
declare function Trace(options?: TraceDecoratorOptions): TraceDecorator;
|
|
65
|
+
declare function Trace(name?: string, options?: TraceDecoratorOptions): TraceDecorator;
|
|
61
66
|
//#endregion
|
|
62
|
-
export { Trace, type TraceContext, TraceDecoratorOptions, type TracingOptions };
|
|
67
|
+
export { Trace, type TraceContext, TraceDecorator, TraceDecoratorOptions, type TracingOptions, WithTraceContext };
|
package/dist/decorators.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { y as splitNameOrOptions } from "./values-BenyvWKz.js";
|
|
1
2
|
import { getConfig } from "./config.js";
|
|
2
|
-
import { T as createTraceContext } from "./init-
|
|
3
|
+
import { T as createTraceContext } from "./init-DDyaLzeg.js";
|
|
3
4
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
4
5
|
|
|
5
6
|
//#region src/decorators.ts
|
|
6
7
|
function Trace(nameOrOptions, maybeOptions) {
|
|
7
|
-
const name
|
|
8
|
+
const { name: nameArgument, options } = splitNameOrOptions(nameOrOptions);
|
|
9
|
+
const name = nameArgument ?? options?.name;
|
|
8
10
|
return function(originalMethod, context) {
|
|
9
11
|
const methodName = String(context.name);
|
|
10
12
|
const methodStr = originalMethod?.toString() || "";
|