@autter/runtime-node 1.9.1 → 1.10.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/README.md +30 -6
- package/dist/chunk-3UODRQBD.js +878 -0
- package/dist/chunk-HBH64LWQ.cjs +878 -0
- package/dist/{chunk-VIP2EL47.js → chunk-KWAJIELR.js} +304 -201
- package/dist/{chunk-3P573RHA.cjs → chunk-S6WJ5YLP.cjs} +304 -201
- package/dist/{chunk-FV64SIRQ.cjs → chunk-STOXJZ7Z.cjs} +21 -10
- package/dist/{chunk-D3PJ7TQ4.js → chunk-V65UY6LU.js} +13 -2
- package/dist/cli.cjs +36 -9
- package/dist/cli.js +32 -5
- package/dist/index.cjs +622 -281
- package/dist/index.d.cts +152 -11
- package/dist/index.d.ts +152 -11
- package/dist/index.js +403 -62
- package/dist/testing.cjs +8 -8
- package/dist/testing.js +2 -2
- package/package.json +2 -1
- package/dist/chunk-FYMEBULO.js +0 -203
- package/dist/chunk-LYXQC4FI.cjs +0 -203
package/dist/index.cjs
CHANGED
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
var
|
|
54
|
+
var _chunkSTOXJZ7Zcjs = require('./chunk-STOXJZ7Z.cjs');
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
var _chunkLYXQC4FIcjs = require('./chunk-LYXQC4FI.cjs');
|
|
58
57
|
|
|
58
|
+
var _chunkHBH64LWQcjs = require('./chunk-HBH64LWQ.cjs');
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
@@ -76,7 +76,13 @@ var _chunkLYXQC4FIcjs = require('./chunk-LYXQC4FI.cjs');
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
var _chunkS6WJ5YLPcjs = require('./chunk-S6WJ5YLP.cjs');
|
|
80
86
|
|
|
81
87
|
// src/relay.ts
|
|
82
88
|
var IpWindow = (_class = class {
|
|
@@ -336,7 +342,7 @@ function relayContext(raw, redactor) {
|
|
|
336
342
|
return Array.isArray(bounded) ? {} : { context: redactor(bounded) };
|
|
337
343
|
}
|
|
338
344
|
function relayBreadcrumbs(raw, redactor) {
|
|
339
|
-
const breadcrumbs =
|
|
345
|
+
const breadcrumbs = _chunkSTOXJZ7Zcjs.sanitizeBreadcrumbs.call(void 0, raw, redactor);
|
|
340
346
|
return breadcrumbs ? { breadcrumbs } : {};
|
|
341
347
|
}
|
|
342
348
|
var DEBUG_ID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
@@ -353,23 +359,58 @@ function relayDebugIds(raw, redactor) {
|
|
|
353
359
|
return count ? { debugIds } : {};
|
|
354
360
|
}
|
|
355
361
|
function relayFingerprint(raw, redactor) {
|
|
356
|
-
const values =
|
|
362
|
+
const values = _chunkSTOXJZ7Zcjs.fingerprintValues.call(void 0, raw, redactor.text);
|
|
357
363
|
return values ? { fingerprint: Array.isArray(raw) ? values : values[0] } : {};
|
|
358
364
|
}
|
|
359
|
-
var defaultRelayRedactor =
|
|
365
|
+
var defaultRelayRedactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true);
|
|
360
366
|
function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
|
|
361
|
-
|
|
367
|
+
const checked = checkBrowserPayload(raw, redactor);
|
|
368
|
+
return "payload" in checked ? checked.payload : null;
|
|
369
|
+
}
|
|
370
|
+
var MAX_RELAY_ISSUES = 5;
|
|
371
|
+
function describe(value) {
|
|
372
|
+
if (value === null) return "null";
|
|
373
|
+
if (Array.isArray(value)) return "an array";
|
|
374
|
+
if (typeof value === "string") return value ? `"${value.slice(0, 40)}"` : "an empty string";
|
|
375
|
+
return typeof value === "undefined" ? "missing" : `a ${typeof value}`;
|
|
376
|
+
}
|
|
377
|
+
function checkBrowserPayload(raw, redactor = defaultRelayRedactor) {
|
|
378
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
379
|
+
return { issues: [{ path: [], message: `expected a JSON object, got ${describe(raw)}` }] };
|
|
380
|
+
}
|
|
362
381
|
const p = raw;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
382
|
+
const issues = [];
|
|
383
|
+
const issue = (path, message) => {
|
|
384
|
+
if (issues.length < MAX_RELAY_ISSUES) issues.push({ path, message });
|
|
385
|
+
};
|
|
386
|
+
if (p.version !== 1) issue(["version"], `expected 1, got ${describe(p.version)}`);
|
|
387
|
+
if (typeof p.service !== "string" || !p.service) issue(["service"], `expected a non-empty string, got ${describe(p.service)}`);
|
|
388
|
+
if (typeof p.environment !== "string" || !p.environment) {
|
|
389
|
+
issue(["environment"], `expected a non-empty string, got ${describe(p.environment)}`);
|
|
390
|
+
}
|
|
391
|
+
if (!Array.isArray(p.events)) issue(["events"], `expected an array, got ${describe(p.events)}`);
|
|
392
|
+
else if (p.events.length > MAX_EVENTS) issue(["events"], `at most ${MAX_EVENTS} events per batch, got ${p.events.length}`);
|
|
393
|
+
if (Array.isArray(p.events) && p.events.length <= MAX_EVENTS) {
|
|
394
|
+
p.events.forEach((rawEvent, index) => {
|
|
395
|
+
if (typeof rawEvent !== "object" || rawEvent === null) {
|
|
396
|
+
issue(["events", index], `expected an object, got ${describe(rawEvent)}`);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
const e = rawEvent;
|
|
400
|
+
if (typeof e.type !== "string" || !EVENT_TYPES.has(e.type)) {
|
|
401
|
+
issue(["events", index, "type"], `expected one of ${[...EVENT_TYPES].join(", ")}, got ${describe(e.type)}`);
|
|
402
|
+
}
|
|
403
|
+
if (typeof e.timestamp !== "string") {
|
|
404
|
+
issue(["events", index, "timestamp"], `expected an ISO 8601 string, got ${describe(e.timestamp)}`);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (issues.length) return { issues };
|
|
409
|
+
const service = p.service;
|
|
410
|
+
const environment = p.environment;
|
|
367
411
|
const events = [];
|
|
368
412
|
for (const rawEvent of p.events) {
|
|
369
|
-
if (typeof rawEvent !== "object" || rawEvent === null) return null;
|
|
370
413
|
const e = rawEvent;
|
|
371
|
-
if (typeof e.type !== "string" || !EVENT_TYPES.has(e.type)) return null;
|
|
372
|
-
if (typeof e.timestamp !== "string") return null;
|
|
373
414
|
events.push({
|
|
374
415
|
type: e.type,
|
|
375
416
|
timestamp: e.timestamp,
|
|
@@ -390,24 +431,28 @@ function sanitizeBrowserPayload(raw, redactor = defaultRelayRedactor) {
|
|
|
390
431
|
...typeof e.traceId === "string" && TRACE_ID.test(e.traceId) ? { traceId: e.traceId } : {}
|
|
391
432
|
});
|
|
392
433
|
}
|
|
393
|
-
return {
|
|
434
|
+
return { payload: {
|
|
394
435
|
version: 1,
|
|
395
436
|
...typeof p.sessionId === "string" ? { sessionId: p.sessionId.slice(0, 100) } : {},
|
|
396
|
-
service:
|
|
397
|
-
environment:
|
|
437
|
+
service: service.slice(0, 200),
|
|
438
|
+
environment: environment.slice(0, 100),
|
|
398
439
|
...typeof p.release === "string" ? { release: p.release.slice(0, 200) } : {},
|
|
399
440
|
// @autter/runtime-browser version, for the ingester's compat records.
|
|
400
441
|
...typeof p.sdk === "string" && /^\d{1,6}\.\d{1,6}\.\d{1,6}[0-9A-Za-z.+-]{0,20}$/.test(p.sdk) ? { sdk: p.sdk } : {},
|
|
401
442
|
events
|
|
402
|
-
};
|
|
443
|
+
} };
|
|
403
444
|
}
|
|
445
|
+
var NO_KEY_BODY = {
|
|
446
|
+
error: "relay has no ingest key",
|
|
447
|
+
fix: "set AUTTER_RUNTIME_KEY (a server key, autter_rt_\u2026) where the relay runs"
|
|
448
|
+
};
|
|
404
449
|
var FORWARD_ATTEMPTS = 3;
|
|
405
450
|
var FORWARD_MAX_WAIT_MS = 1e4;
|
|
406
|
-
function forward(payload, opts) {
|
|
451
|
+
function forward(payload, opts, apiKey) {
|
|
407
452
|
const endpoint = (_nullishCoalesce(opts.endpoint, () => ( DEFAULT_ENDPOINT))).replace(/\/$/, "");
|
|
408
453
|
const url = `${endpoint}/v1/browser`;
|
|
409
454
|
const compat = opts.compatCheck !== false;
|
|
410
|
-
if (compat)
|
|
455
|
+
if (compat) _chunkS6WJ5YLPcjs.ensureCompatConfigured.call(void 0, endpoint);
|
|
411
456
|
const body = JSON.stringify(payload);
|
|
412
457
|
const attempt = async (n) => {
|
|
413
458
|
let response;
|
|
@@ -416,7 +461,7 @@ function forward(payload, opts) {
|
|
|
416
461
|
method: "POST",
|
|
417
462
|
headers: {
|
|
418
463
|
"content-type": "application/json",
|
|
419
|
-
|
|
464
|
+
..._chunkS6WJ5YLPcjs.authHeaders.call(void 0, apiKey)
|
|
420
465
|
},
|
|
421
466
|
body,
|
|
422
467
|
signal: AbortSignal.timeout(1e4)
|
|
@@ -433,16 +478,25 @@ function forward(payload, opts) {
|
|
|
433
478
|
await sleep(seconds > 0 ? Math.min(seconds * 1e3, FORWARD_MAX_WAIT_MS) : 1e3 * 2 ** (n - 1));
|
|
434
479
|
return attempt(n + 1);
|
|
435
480
|
}
|
|
481
|
+
if (!response.ok) {
|
|
482
|
+
_chunkS6WJ5YLPcjs.noteIngestRefusal.call(void 0, {
|
|
483
|
+
status: response.status,
|
|
484
|
+
route: "/v1/browser",
|
|
485
|
+
endpoint,
|
|
486
|
+
body: await response.clone().text().catch(() => ""),
|
|
487
|
+
via: "relay"
|
|
488
|
+
});
|
|
489
|
+
}
|
|
436
490
|
if (!compat) return;
|
|
437
491
|
const types = new Set(
|
|
438
492
|
(_nullishCoalesce(payload.events, () => ( []))).map((e) => String(e.type))
|
|
439
493
|
);
|
|
440
|
-
|
|
441
|
-
for (const feature of
|
|
494
|
+
_chunkS6WJ5YLPcjs.observeIngesterResponse.call(void 0, { status: response.status, headers: response.headers });
|
|
495
|
+
for (const feature of _chunkS6WJ5YLPcjs.featuresForBrowserEvents.call(void 0, types)) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, feature);
|
|
442
496
|
if ((_nullishCoalesce(payload.events, () => ( []))).some((e) => e.traceId)) {
|
|
443
|
-
|
|
497
|
+
_chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "browser_trace_propagation");
|
|
444
498
|
}
|
|
445
|
-
|
|
499
|
+
_chunkS6WJ5YLPcjs.noteRelayRejection.call(void 0, types, response.status, response.headers);
|
|
446
500
|
};
|
|
447
501
|
void attempt(1).catch((err) => {
|
|
448
502
|
(_nullishCoalesce(opts.onError, () => ( ((e) => console.warn("autter relay forward failed:", e)))))(
|
|
@@ -455,12 +509,21 @@ function sleep(ms) {
|
|
|
455
509
|
}
|
|
456
510
|
function createBrowserRelayFetchHandler(opts) {
|
|
457
511
|
const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
|
|
458
|
-
const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor :
|
|
512
|
+
const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, opts.redact);
|
|
459
513
|
const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
|
|
514
|
+
const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, opts.apiKey);
|
|
515
|
+
if (!apiKey) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "relay");
|
|
516
|
+
else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
|
|
460
517
|
return async (request) => {
|
|
461
518
|
if (request.method !== "POST") {
|
|
462
519
|
return new Response(null, { status: 405 });
|
|
463
520
|
}
|
|
521
|
+
if (!apiKey) {
|
|
522
|
+
return new Response(JSON.stringify(NO_KEY_BODY), {
|
|
523
|
+
status: 500,
|
|
524
|
+
headers: { "content-type": "application/json" }
|
|
525
|
+
});
|
|
526
|
+
}
|
|
464
527
|
if (limiter) {
|
|
465
528
|
const ip = fetchClientKey(request, opts);
|
|
466
529
|
if (!limiter.allow(ip)) {
|
|
@@ -490,19 +553,20 @@ function createBrowserRelayFetchHandler(opts) {
|
|
|
490
553
|
status: 400
|
|
491
554
|
});
|
|
492
555
|
}
|
|
493
|
-
const
|
|
494
|
-
if (!payload) {
|
|
495
|
-
return new Response(JSON.stringify({ error: "invalid payload" }), {
|
|
496
|
-
status: 400
|
|
556
|
+
const checked = checkBrowserPayload(raw, redactor);
|
|
557
|
+
if (!("payload" in checked)) {
|
|
558
|
+
return new Response(JSON.stringify({ error: "invalid payload", issues: checked.issues }), {
|
|
559
|
+
status: 400,
|
|
560
|
+
headers: { "content-type": "application/json" }
|
|
497
561
|
});
|
|
498
562
|
}
|
|
499
|
-
forward(payload, opts);
|
|
563
|
+
forward(checked.payload, opts, apiKey);
|
|
500
564
|
return new Response(null, { status: 202 });
|
|
501
565
|
};
|
|
502
566
|
}
|
|
503
567
|
function createBrowserRelayHandler(opts) {
|
|
504
568
|
const maxBody = _nullishCoalesce(opts.maxBodyBytes, () => ( DEFAULT_MAX_BODY));
|
|
505
|
-
const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor :
|
|
569
|
+
const redactor = opts.redact === void 0 || opts.redact === true ? defaultRelayRedactor : _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, opts.redact);
|
|
506
570
|
const limiter = opts.perIpRateLimit === false ? null : new IpWindow(_nullishCoalesce(opts.perIpRateLimit, () => ( 120)));
|
|
507
571
|
function respond(res, status, body) {
|
|
508
572
|
res.statusCode = status;
|
|
@@ -513,13 +577,16 @@ function createBrowserRelayHandler(opts) {
|
|
|
513
577
|
res.end();
|
|
514
578
|
}
|
|
515
579
|
}
|
|
580
|
+
const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, opts.apiKey);
|
|
581
|
+
if (!apiKey) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "relay");
|
|
582
|
+
else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
|
|
516
583
|
function handleParsed(raw, res) {
|
|
517
|
-
const
|
|
518
|
-
if (!payload) {
|
|
519
|
-
respond(res, 400, { error: "invalid payload" });
|
|
584
|
+
const checked = checkBrowserPayload(raw, redactor);
|
|
585
|
+
if (!("payload" in checked)) {
|
|
586
|
+
respond(res, 400, { error: "invalid payload", issues: checked.issues });
|
|
520
587
|
return;
|
|
521
588
|
}
|
|
522
|
-
forward(payload, opts);
|
|
589
|
+
forward(checked.payload, opts, apiKey);
|
|
523
590
|
respond(res, 202);
|
|
524
591
|
}
|
|
525
592
|
return (req, res) => {
|
|
@@ -527,6 +594,10 @@ function createBrowserRelayHandler(opts) {
|
|
|
527
594
|
respond(res, 405);
|
|
528
595
|
return;
|
|
529
596
|
}
|
|
597
|
+
if (!apiKey) {
|
|
598
|
+
respond(res, 500, NO_KEY_BODY);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
530
601
|
if (limiter) {
|
|
531
602
|
const ip = nodeClientKey(req, opts);
|
|
532
603
|
if (!limiter.allow(ip)) {
|
|
@@ -828,6 +899,73 @@ var RedactingMetricExporter = class {
|
|
|
828
899
|
}
|
|
829
900
|
};
|
|
830
901
|
|
|
902
|
+
// src/ingest-exporters.ts
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
function refusalOf(result) {
|
|
908
|
+
if (result.code === _core.ExportResultCode.SUCCESS) return null;
|
|
909
|
+
const error = result.error;
|
|
910
|
+
return typeof _optionalChain([error, 'optionalAccess', _13 => _13.code]) === "number" ? { status: error.code, body: error.data } : null;
|
|
911
|
+
}
|
|
912
|
+
var NO_KEY = {
|
|
913
|
+
code: _core.ExportResultCode.FAILED,
|
|
914
|
+
error: new Error("no Autter ingest key: not sent (set AUTTER_RUNTIME_KEY)")
|
|
915
|
+
};
|
|
916
|
+
function observe(endpoint, route, callback) {
|
|
917
|
+
return (result) => {
|
|
918
|
+
const refusal = refusalOf(result);
|
|
919
|
+
if (refusal) _chunkS6WJ5YLPcjs.noteIngestRefusal.call(void 0, { ...refusal, endpoint, route });
|
|
920
|
+
callback(result);
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
var IngestSpanExporter = class {
|
|
924
|
+
constructor(inner, target) {
|
|
925
|
+
this.inner = inner;
|
|
926
|
+
this.target = target;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
export(spans, resultCallback) {
|
|
931
|
+
if (!this.target.hasKey) {
|
|
932
|
+
resultCallback(NO_KEY);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
this.inner.export(spans, observe(this.target.endpoint, "/v1/traces", resultCallback));
|
|
936
|
+
}
|
|
937
|
+
shutdown() {
|
|
938
|
+
return this.inner.shutdown();
|
|
939
|
+
}
|
|
940
|
+
forceFlush() {
|
|
941
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _14 => _14.inner, 'access', _15 => _15.forceFlush, 'optionalCall', _16 => _16()]), () => ( Promise.resolve()));
|
|
942
|
+
}
|
|
943
|
+
};
|
|
944
|
+
var IngestMetricExporter = class {
|
|
945
|
+
constructor(inner, target) {
|
|
946
|
+
this.inner = inner;
|
|
947
|
+
this.target = target;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
export(metrics2, resultCallback) {
|
|
952
|
+
if (!this.target.hasKey) {
|
|
953
|
+
resultCallback(NO_KEY);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
this.inner.export(metrics2, observe(this.target.endpoint, "/v1/metrics", resultCallback));
|
|
957
|
+
}
|
|
958
|
+
forceFlush() {
|
|
959
|
+
return this.inner.forceFlush();
|
|
960
|
+
}
|
|
961
|
+
shutdown() {
|
|
962
|
+
return this.inner.shutdown();
|
|
963
|
+
}
|
|
964
|
+
selectAggregationTemporality(instrumentType) {
|
|
965
|
+
return this.inner.selectAggregationTemporality ? this.inner.selectAggregationTemporality(instrumentType) : _sdkmetrics.AggregationTemporality.CUMULATIVE;
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
|
|
831
969
|
// src/memory.ts
|
|
832
970
|
var _perf_hooks = require('perf_hooks');
|
|
833
971
|
var _v8 = require('v8');
|
|
@@ -849,7 +987,7 @@ function startMemoryMetrics() {
|
|
|
849
987
|
[heapUsed, (result) => result.observe(process.memoryUsage().heapUsed)],
|
|
850
988
|
[heapLimit, (result) => result.observe(_v8.getHeapStatistics.call(void 0, ).heap_size_limit)],
|
|
851
989
|
[containerLimit, (result) => {
|
|
852
|
-
const constrained = _nullishCoalesce(_optionalChain([process, 'access',
|
|
990
|
+
const constrained = _nullishCoalesce(_optionalChain([process, 'access', _17 => _17.constrainedMemory, 'optionalCall', _18 => _18()]), () => ( 0));
|
|
853
991
|
if (constrained > 0) result.observe(constrained);
|
|
854
992
|
}],
|
|
855
993
|
[afterGc, (result) => {
|
|
@@ -900,19 +1038,19 @@ function decide(rule, error, fallback) {
|
|
|
900
1038
|
}
|
|
901
1039
|
function expressRouteOf(req) {
|
|
902
1040
|
const props = req;
|
|
903
|
-
const path = _optionalChain([props, 'optionalAccess',
|
|
1041
|
+
const path = _optionalChain([props, 'optionalAccess', _19 => _19.route, 'optionalAccess', _20 => _20.path]);
|
|
904
1042
|
if (typeof path !== "string" || path === "") return null;
|
|
905
|
-
const base = typeof _optionalChain([props, 'optionalAccess',
|
|
1043
|
+
const base = typeof _optionalChain([props, 'optionalAccess', _21 => _21.baseUrl]) === "string" ? props.baseUrl : "";
|
|
906
1044
|
const route = base + path;
|
|
907
1045
|
return route.startsWith("/") ? route : null;
|
|
908
1046
|
}
|
|
909
1047
|
function defaultShouldCapture(error) {
|
|
910
|
-
return error instanceof
|
|
1048
|
+
return error instanceof _chunkSTOXJZ7Zcjs.RuntimeError || _chunkSTOXJZ7Zcjs.errorCodeOf.call(void 0, error) !== void 0 || _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error) >= 500;
|
|
911
1049
|
}
|
|
912
1050
|
function onRequestSpan(fn) {
|
|
913
1051
|
const active = _api.context.active();
|
|
914
1052
|
const metadata = _core.getRPCMetadata.call(void 0, active);
|
|
915
|
-
const span = _optionalChain([metadata, 'optionalAccess',
|
|
1053
|
+
const span = _optionalChain([metadata, 'optionalAccess', _22 => _22.type]) === _core.RPCType.HTTP ? metadata.span : void 0;
|
|
916
1054
|
if (!span || !span.isRecording() || _api.trace.getSpan(active) === span) {
|
|
917
1055
|
fn();
|
|
918
1056
|
return;
|
|
@@ -927,29 +1065,50 @@ function captureAtBoundary(error, state, rule = void 0, attributes) {
|
|
|
927
1065
|
wanted = false;
|
|
928
1066
|
}
|
|
929
1067
|
if (!wanted) return;
|
|
930
|
-
if (
|
|
931
|
-
|
|
1068
|
+
if (_chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error)) return;
|
|
1069
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
932
1070
|
try {
|
|
933
1071
|
const run = () => onRequestSpan(() => capturer(error, attributes));
|
|
934
|
-
if (state && !state.sealed)
|
|
1072
|
+
if (state && !state.sealed) _chunkSTOXJZ7Zcjs.local.run(state, run);
|
|
935
1073
|
else run();
|
|
936
1074
|
} catch (e17) {
|
|
937
1075
|
}
|
|
938
1076
|
}
|
|
1077
|
+
function requestScopeAttributes() {
|
|
1078
|
+
try {
|
|
1079
|
+
const out = {};
|
|
1080
|
+
const state = _chunkSTOXJZ7Zcjs.local.getStore();
|
|
1081
|
+
const active = _api.context.active();
|
|
1082
|
+
const metadata = _core.getRPCMetadata.call(void 0, active);
|
|
1083
|
+
const http = _optionalChain([metadata, 'optionalAccess', _23 => _23.type]) === _core.RPCType.HTTP ? metadata : void 0;
|
|
1084
|
+
const spanAttributes = _optionalChain([http, 'optionalAccess', _24 => _24.span, 'optionalAccess', _25 => _25.attributes]);
|
|
1085
|
+
const req = _optionalChain([state, 'optionalAccess', _26 => _26.req]);
|
|
1086
|
+
const nodeRequest = !!req && typeof req === "object" && typeof req.url === "string" && req.url.startsWith("/");
|
|
1087
|
+
const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _27 => _27.requestId]), () => ( _optionalChain([spanAttributes, 'optionalAccess', _28 => _28["autter.request.id"]])));
|
|
1088
|
+
if (typeof requestId === "string" && requestId) out["autter.request.id"] = requestId;
|
|
1089
|
+
const route = _nullishCoalesce(_nullishCoalesce(_optionalChain([http, 'optionalAccess', _29 => _29.route]), () => ( _optionalChain([spanAttributes, 'optionalAccess', _30 => _30["http.route"]]))), () => ( (nodeRequest ? _nullishCoalesce(expressRouteOf(req), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, pathOf(req)))) : void 0)));
|
|
1090
|
+
if (typeof route === "string" && route) out["http.route"] = route;
|
|
1091
|
+
const method = _nullishCoalesce(_nullishCoalesce((nodeRequest ? req.method : void 0), () => ( _optionalChain([spanAttributes, 'optionalAccess', _31 => _31["http.request.method"]]))), () => ( _optionalChain([spanAttributes, 'optionalAccess', _32 => _32["http.method"]])));
|
|
1092
|
+
if (typeof method === "string" && method) out["http.request.method"] = method.toUpperCase();
|
|
1093
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
1094
|
+
} catch (e18) {
|
|
1095
|
+
return void 0;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
939
1098
|
function requestStateOf(req) {
|
|
940
1099
|
if (!req || typeof req !== "object") return void 0;
|
|
941
1100
|
return req[REQUEST_STATE];
|
|
942
1101
|
}
|
|
943
1102
|
function captureRequestError(error, attributes) {
|
|
944
|
-
if (
|
|
1103
|
+
if (_chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error)) {
|
|
945
1104
|
if (!attributes) return;
|
|
946
1105
|
try {
|
|
947
1106
|
onRequestSpan(() => annotator(attributes));
|
|
948
|
-
} catch (
|
|
1107
|
+
} catch (e19) {
|
|
949
1108
|
}
|
|
950
1109
|
return;
|
|
951
1110
|
}
|
|
952
|
-
captureAtBoundary(error,
|
|
1111
|
+
captureAtBoundary(error, _chunkSTOXJZ7Zcjs.currentOperation.call(void 0, ), true, attributes);
|
|
953
1112
|
}
|
|
954
1113
|
function bindEmitter(emitter, state) {
|
|
955
1114
|
const target = emitter;
|
|
@@ -961,7 +1120,7 @@ function bindEmitter(emitter, state) {
|
|
|
961
1120
|
let wrapped = wrappers.get(listener);
|
|
962
1121
|
if (!wrapped) {
|
|
963
1122
|
wrapped = function(...args) {
|
|
964
|
-
return
|
|
1123
|
+
return _chunkSTOXJZ7Zcjs.local.run(
|
|
965
1124
|
state,
|
|
966
1125
|
() => listener.apply(this, args)
|
|
967
1126
|
);
|
|
@@ -1016,7 +1175,7 @@ function exposeOnCors(res, header) {
|
|
|
1016
1175
|
if (value && key && inline) inline[key] = value;
|
|
1017
1176
|
else if (value) res.setHeader("access-control-expose-headers", value);
|
|
1018
1177
|
}
|
|
1019
|
-
} catch (
|
|
1178
|
+
} catch (e20) {
|
|
1020
1179
|
}
|
|
1021
1180
|
return original.apply(this, args);
|
|
1022
1181
|
};
|
|
@@ -1028,7 +1187,7 @@ function pathOf(req) {
|
|
|
1028
1187
|
function finishRequest(state, input) {
|
|
1029
1188
|
if (state.sealed) return;
|
|
1030
1189
|
state.name = (_nullishCoalesce(input.name, () => ( `${input.method} ${input.route}`))).slice(0, 200);
|
|
1031
|
-
state.outcome =
|
|
1190
|
+
state.outcome = _chunkSTOXJZ7Zcjs.requestOutcome.call(void 0, {
|
|
1032
1191
|
...state.explicitOutcome ? { explicit: state.outcome } : {},
|
|
1033
1192
|
...state.error !== void 0 ? { error: state.error } : {},
|
|
1034
1193
|
...state.errorThrown ? { thrown: true } : {},
|
|
@@ -1037,15 +1196,15 @@ function finishRequest(state, input) {
|
|
|
1037
1196
|
...state.degraded ? { degraded: true } : {}
|
|
1038
1197
|
});
|
|
1039
1198
|
const span = _api.trace.getActiveSpan();
|
|
1040
|
-
if (_optionalChain([span, 'optionalAccess',
|
|
1199
|
+
if (_optionalChain([span, 'optionalAccess', _33 => _33.isRecording, 'call', _34 => _34()])) span.setAttribute("autter.operation.outcome", state.outcome);
|
|
1041
1200
|
if (input.span) {
|
|
1042
1201
|
const remote = _api.trace.wrapSpanContext(input.span);
|
|
1043
1202
|
_api.context.with(
|
|
1044
1203
|
_api.trace.setSpan(_api.context.active(), remote),
|
|
1045
|
-
() =>
|
|
1204
|
+
() => _chunkSTOXJZ7Zcjs.reportExplicitFailure.call(void 0, state)
|
|
1046
1205
|
);
|
|
1047
|
-
} else
|
|
1048
|
-
|
|
1206
|
+
} else _chunkSTOXJZ7Zcjs.reportExplicitFailure.call(void 0, state);
|
|
1207
|
+
_chunkSTOXJZ7Zcjs.emitSummary.call(void 0, state, {
|
|
1049
1208
|
http: {
|
|
1050
1209
|
"http.request.method": input.method,
|
|
1051
1210
|
"http.route": input.route,
|
|
@@ -1056,14 +1215,14 @@ function finishRequest(state, input) {
|
|
|
1056
1215
|
});
|
|
1057
1216
|
}
|
|
1058
1217
|
function beginNodeRequest(req, res, options, route) {
|
|
1059
|
-
const header = (_nullishCoalesce(options.requestIdHeader, () => (
|
|
1060
|
-
const requestId =
|
|
1218
|
+
const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
|
|
1219
|
+
const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
|
|
1061
1220
|
options.trustRequestId === false ? void 0 : req.headers[header]
|
|
1062
1221
|
);
|
|
1063
1222
|
const method = (_nullishCoalesce(req.method, () => ( "GET"))).toUpperCase();
|
|
1064
1223
|
const path = pathOf(req);
|
|
1065
|
-
const state =
|
|
1066
|
-
name: `${method} ${
|
|
1224
|
+
const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
|
|
1225
|
+
name: `${method} ${_chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, path)}`,
|
|
1067
1226
|
requestId,
|
|
1068
1227
|
req,
|
|
1069
1228
|
res
|
|
@@ -1072,22 +1231,22 @@ function beginNodeRequest(req, res, options, route) {
|
|
|
1072
1231
|
try {
|
|
1073
1232
|
if (!res.headersSent) res.setHeader(header, requestId);
|
|
1074
1233
|
exposeOnCors(res, header);
|
|
1075
|
-
} catch (
|
|
1234
|
+
} catch (e21) {
|
|
1076
1235
|
}
|
|
1077
1236
|
const span = _api.trace.getActiveSpan();
|
|
1078
|
-
if (_optionalChain([span, 'optionalAccess',
|
|
1237
|
+
if (_optionalChain([span, 'optionalAccess', _35 => _35.isRecording, 'call', _36 => _36()]))
|
|
1079
1238
|
span.setAttributes({
|
|
1080
1239
|
"autter.request.id": requestId,
|
|
1081
1240
|
"autter.operation.kind": "request"
|
|
1082
1241
|
});
|
|
1083
|
-
const spanContext = _optionalChain([span, 'optionalAccess',
|
|
1242
|
+
const spanContext = _optionalChain([span, 'optionalAccess', _37 => _37.spanContext, 'call', _38 => _38()]);
|
|
1084
1243
|
bindEmitter(req, state);
|
|
1085
1244
|
bindEmitter(res, state);
|
|
1086
1245
|
let finished = false;
|
|
1087
1246
|
const done = () => {
|
|
1088
1247
|
finishRequest(state, {
|
|
1089
1248
|
method,
|
|
1090
|
-
route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall',
|
|
1249
|
+
route: _nullishCoalesce(_nullishCoalesce(_optionalChain([route, 'optionalCall', _39 => _39()]), () => ( expressRouteOf(req))), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, path))),
|
|
1091
1250
|
status: res.statusCode,
|
|
1092
1251
|
aborted: !finished,
|
|
1093
1252
|
...spanContext ? { span: spanContext } : {}
|
|
@@ -1101,50 +1260,50 @@ function beginNodeRequest(req, res, options, route) {
|
|
|
1101
1260
|
return state;
|
|
1102
1261
|
}
|
|
1103
1262
|
function autterRequests(options = {}) {
|
|
1104
|
-
const ignored =
|
|
1263
|
+
const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, options.ignore);
|
|
1105
1264
|
return function autterRequestsMiddleware(req, res, next) {
|
|
1106
1265
|
if (req[REQUEST_STATE] || ignored(pathOf(req))) {
|
|
1107
1266
|
next();
|
|
1108
1267
|
return;
|
|
1109
1268
|
}
|
|
1110
1269
|
const state = beginNodeRequest(req, res, options);
|
|
1111
|
-
|
|
1270
|
+
_chunkSTOXJZ7Zcjs.local.run(state, () => next());
|
|
1112
1271
|
};
|
|
1113
1272
|
}
|
|
1114
1273
|
function autterErrorResponse(options = {}) {
|
|
1115
1274
|
return function autterErrorResponseMiddleware(error, req, res, next) {
|
|
1116
1275
|
const state = req[REQUEST_STATE];
|
|
1117
|
-
if (state)
|
|
1276
|
+
if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
|
|
1118
1277
|
captureAtBoundary(error, state, options.capture);
|
|
1119
1278
|
if (res.headersSent) {
|
|
1120
1279
|
next(error);
|
|
1121
1280
|
return;
|
|
1122
1281
|
}
|
|
1123
|
-
const header = (_nullishCoalesce(options.requestIdHeader, () => (
|
|
1124
|
-
const inbound = _optionalChain([req, 'access',
|
|
1125
|
-
const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess',
|
|
1126
|
-
res.statusCode =
|
|
1282
|
+
const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
|
|
1283
|
+
const inbound = _optionalChain([req, 'access', _40 => _40.headers, 'optionalAccess', _41 => _41[header]]);
|
|
1284
|
+
const requestId = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _42 => _42.requestId]), () => ( (typeof inbound === "string" ? inbound.slice(0, 128) : void 0)));
|
|
1285
|
+
res.statusCode = _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error);
|
|
1127
1286
|
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
1128
|
-
res.end(JSON.stringify(
|
|
1287
|
+
res.end(JSON.stringify(_chunkSTOXJZ7Zcjs.toClientError.call(void 0, error, requestId)));
|
|
1129
1288
|
};
|
|
1130
1289
|
}
|
|
1131
1290
|
var RESOURCE = /* @__PURE__ */ Symbol.for("autter.runtime.resource");
|
|
1132
1291
|
function autterFastify(fastify, options, done) {
|
|
1133
1292
|
const opts = _nullishCoalesce(options, () => ( {}));
|
|
1134
|
-
const header = (_nullishCoalesce(opts.requestIdHeader, () => (
|
|
1135
|
-
const ignored =
|
|
1293
|
+
const header = (_nullishCoalesce(opts.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
|
|
1294
|
+
const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, opts.ignore);
|
|
1136
1295
|
const stateOf = (request) => request[REQUEST_STATE];
|
|
1137
1296
|
fastify.addHook("onRequest", ((request, reply, next) => {
|
|
1138
1297
|
if (ignored(request.url) || request.raw[REQUEST_STATE]) {
|
|
1139
1298
|
next();
|
|
1140
1299
|
return;
|
|
1141
1300
|
}
|
|
1142
|
-
const requestId =
|
|
1301
|
+
const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
|
|
1143
1302
|
opts.trustRequestId === false ? void 0 : request.headers[header]
|
|
1144
1303
|
);
|
|
1145
1304
|
const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
|
|
1146
|
-
const state =
|
|
1147
|
-
name: `${method} ${
|
|
1305
|
+
const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
|
|
1306
|
+
name: `${method} ${_chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, request.url)}`,
|
|
1148
1307
|
requestId,
|
|
1149
1308
|
req: request.raw,
|
|
1150
1309
|
res: reply.raw
|
|
@@ -1153,18 +1312,18 @@ function autterFastify(fastify, options, done) {
|
|
|
1153
1312
|
request.raw[REQUEST_STATE] = state;
|
|
1154
1313
|
reply.header(header, requestId);
|
|
1155
1314
|
const span = _api.trace.getActiveSpan();
|
|
1156
|
-
if (_optionalChain([span, 'optionalAccess',
|
|
1315
|
+
if (_optionalChain([span, 'optionalAccess', _43 => _43.isRecording, 'call', _44 => _44()]))
|
|
1157
1316
|
span.setAttributes({
|
|
1158
1317
|
"autter.request.id": requestId,
|
|
1159
1318
|
"autter.operation.kind": "request"
|
|
1160
1319
|
});
|
|
1161
|
-
const spanContext = _optionalChain([span, 'optionalAccess',
|
|
1320
|
+
const spanContext = _optionalChain([span, 'optionalAccess', _45 => _45.spanContext, 'call', _46 => _46()]);
|
|
1162
1321
|
bindEmitter(request.raw, state);
|
|
1163
1322
|
bindEmitter(reply.raw, state);
|
|
1164
1323
|
let finished = false;
|
|
1165
1324
|
const finish = (aborted) => finishRequest(state, {
|
|
1166
1325
|
method,
|
|
1167
|
-
route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access',
|
|
1326
|
+
route: _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'access', _47 => _47.routeOptions, 'optionalAccess', _48 => _48.url]), () => ( request.routerPath)), () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, request.url))),
|
|
1168
1327
|
status: reply.raw.statusCode || reply.statusCode,
|
|
1169
1328
|
aborted,
|
|
1170
1329
|
...spanContext ? { span: spanContext } : {}
|
|
@@ -1174,7 +1333,7 @@ function autterFastify(fastify, options, done) {
|
|
|
1174
1333
|
finish(false);
|
|
1175
1334
|
});
|
|
1176
1335
|
reply.raw.once("close", () => finish(!finished));
|
|
1177
|
-
|
|
1336
|
+
_chunkSTOXJZ7Zcjs.local.run(state, () => {
|
|
1178
1337
|
request[RESOURCE] = new (0, _async_hooks.AsyncResource)("autter-request");
|
|
1179
1338
|
next();
|
|
1180
1339
|
});
|
|
@@ -1190,13 +1349,13 @@ function autterFastify(fastify, options, done) {
|
|
|
1190
1349
|
const value = exposeHeaderValue(reply.getHeader("access-control-expose-headers"), header);
|
|
1191
1350
|
if (value) reply.header("access-control-expose-headers", value);
|
|
1192
1351
|
}
|
|
1193
|
-
} catch (
|
|
1352
|
+
} catch (e22) {
|
|
1194
1353
|
}
|
|
1195
1354
|
next(null, payload);
|
|
1196
1355
|
}));
|
|
1197
1356
|
fastify.addHook("onError", ((request, _reply, error, next) => {
|
|
1198
1357
|
const state = stateOf(request);
|
|
1199
|
-
if (state)
|
|
1358
|
+
if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
|
|
1200
1359
|
captureAtBoundary(error, state);
|
|
1201
1360
|
next();
|
|
1202
1361
|
}));
|
|
@@ -1218,54 +1377,54 @@ function withHeaders(response, header, requestId) {
|
|
|
1218
1377
|
};
|
|
1219
1378
|
try {
|
|
1220
1379
|
return apply(response);
|
|
1221
|
-
} catch (
|
|
1380
|
+
} catch (e23) {
|
|
1222
1381
|
try {
|
|
1223
1382
|
return apply(new Response(response.body, response));
|
|
1224
|
-
} catch (
|
|
1383
|
+
} catch (e24) {
|
|
1225
1384
|
return response;
|
|
1226
1385
|
}
|
|
1227
1386
|
}
|
|
1228
1387
|
}
|
|
1229
1388
|
function withRuntimeRequest(handler, options = {}) {
|
|
1230
|
-
const header = (_nullishCoalesce(options.requestIdHeader, () => (
|
|
1231
|
-
const ignored =
|
|
1389
|
+
const header = (_nullishCoalesce(options.requestIdHeader, () => ( _chunkSTOXJZ7Zcjs.DEFAULT_REQUEST_ID_HEADER))).toLowerCase();
|
|
1390
|
+
const ignored = _chunkSTOXJZ7Zcjs.compileIgnore.call(void 0, options.ignore);
|
|
1232
1391
|
return async (request, ...rest) => {
|
|
1233
1392
|
let pathname = "/";
|
|
1234
1393
|
try {
|
|
1235
1394
|
pathname = new URL(request.url, "http://localhost").pathname;
|
|
1236
|
-
} catch (
|
|
1395
|
+
} catch (e25) {
|
|
1237
1396
|
}
|
|
1238
1397
|
if (ignored(pathname)) return handler(request, ...rest);
|
|
1239
|
-
const requestId =
|
|
1398
|
+
const requestId = _chunkSTOXJZ7Zcjs.resolveRequestId.call(void 0,
|
|
1240
1399
|
options.trustRequestId === false ? void 0 : request.headers.get(header)
|
|
1241
1400
|
);
|
|
1242
1401
|
const method = String(_nullishCoalesce(request.method, () => ( "GET"))).toUpperCase();
|
|
1243
|
-
const route = _nullishCoalesce(options.route, () => (
|
|
1244
|
-
const state =
|
|
1402
|
+
const route = _nullishCoalesce(options.route, () => ( _chunkSTOXJZ7Zcjs.normalizeRoutePath.call(void 0, pathname)));
|
|
1403
|
+
const state = _chunkSTOXJZ7Zcjs.createRequestState.call(void 0, {
|
|
1245
1404
|
name: `${method} ${_nullishCoalesce(options.name, () => ( route))}`,
|
|
1246
1405
|
requestId,
|
|
1247
1406
|
req: request
|
|
1248
1407
|
});
|
|
1249
1408
|
const span = _api.trace.getActiveSpan();
|
|
1250
|
-
if (_optionalChain([span, 'optionalAccess',
|
|
1409
|
+
if (_optionalChain([span, 'optionalAccess', _49 => _49.isRecording, 'call', _50 => _50()]))
|
|
1251
1410
|
span.setAttributes({
|
|
1252
1411
|
"autter.request.id": requestId,
|
|
1253
1412
|
"autter.operation.kind": "request"
|
|
1254
1413
|
});
|
|
1255
|
-
const spanContext = _optionalChain([span, 'optionalAccess',
|
|
1414
|
+
const spanContext = _optionalChain([span, 'optionalAccess', _51 => _51.spanContext, 'call', _52 => _52()]);
|
|
1256
1415
|
let status = 500;
|
|
1257
1416
|
try {
|
|
1258
|
-
const response = await
|
|
1417
|
+
const response = await _chunkSTOXJZ7Zcjs.local.run(state, async () => {
|
|
1259
1418
|
try {
|
|
1260
1419
|
return await handler(request, ...rest);
|
|
1261
1420
|
} catch (error) {
|
|
1262
1421
|
if (decide(options.capture, error, true)) {
|
|
1263
|
-
|
|
1422
|
+
_chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, true, state);
|
|
1264
1423
|
captureAtBoundary(error, state, true);
|
|
1265
1424
|
}
|
|
1266
1425
|
if (!decide(options.errorResponse, error, false)) throw error;
|
|
1267
|
-
return new Response(JSON.stringify(
|
|
1268
|
-
status:
|
|
1426
|
+
return new Response(JSON.stringify(_chunkSTOXJZ7Zcjs.toClientError.call(void 0, error, requestId)), {
|
|
1427
|
+
status: _chunkSTOXJZ7Zcjs.responseStatusOf.call(void 0, error),
|
|
1269
1428
|
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1270
1429
|
});
|
|
1271
1430
|
}
|
|
@@ -1273,7 +1432,7 @@ function withRuntimeRequest(handler, options = {}) {
|
|
|
1273
1432
|
status = response.status;
|
|
1274
1433
|
return withHeaders(response, header, requestId);
|
|
1275
1434
|
} finally {
|
|
1276
|
-
const aborted = _optionalChain([request, 'access',
|
|
1435
|
+
const aborted = _optionalChain([request, 'access', _53 => _53.signal, 'optionalAccess', _54 => _54.aborted]) === true;
|
|
1277
1436
|
finishRequest(state, {
|
|
1278
1437
|
method,
|
|
1279
1438
|
route,
|
|
@@ -1284,9 +1443,9 @@ function withRuntimeRequest(handler, options = {}) {
|
|
|
1284
1443
|
});
|
|
1285
1444
|
if (options.waitUntil) {
|
|
1286
1445
|
try {
|
|
1287
|
-
options.waitUntil(
|
|
1446
|
+
options.waitUntil(_chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ).catch(() => {
|
|
1288
1447
|
}));
|
|
1289
|
-
} catch (
|
|
1448
|
+
} catch (e26) {
|
|
1290
1449
|
}
|
|
1291
1450
|
}
|
|
1292
1451
|
}
|
|
@@ -1296,7 +1455,7 @@ function startHookRequest(res) {
|
|
|
1296
1455
|
const req = res.req;
|
|
1297
1456
|
if (!req || req[REQUEST_STATE]) return;
|
|
1298
1457
|
const state = beginNodeRequest(req, res, {});
|
|
1299
|
-
|
|
1458
|
+
_chunkSTOXJZ7Zcjs.local.enterWith(state);
|
|
1300
1459
|
}
|
|
1301
1460
|
|
|
1302
1461
|
// src/unhandled-rejections.ts
|
|
@@ -1322,7 +1481,7 @@ var recorded = /* @__PURE__ */ new WeakSet();
|
|
|
1322
1481
|
function markRecorded(reason) {
|
|
1323
1482
|
if (!reason || typeof reason !== "object") return;
|
|
1324
1483
|
recorded.add(reason);
|
|
1325
|
-
_optionalChain([setImmediate, 'call',
|
|
1484
|
+
_optionalChain([setImmediate, 'call', _55 => _55(() => recorded.delete(reason)), 'access', _56 => _56.unref, 'optionalCall', _57 => _57()]);
|
|
1326
1485
|
}
|
|
1327
1486
|
function recordedAsRejection(error) {
|
|
1328
1487
|
return !!error && typeof error === "object" && recorded.has(error);
|
|
@@ -1348,7 +1507,7 @@ function unhandledRejectionsMode(execArgv = process.execArgv, nodeOptions = proc
|
|
|
1348
1507
|
function isErrorLike(value) {
|
|
1349
1508
|
try {
|
|
1350
1509
|
return typeof value === "object" && value !== null && Object.prototype.hasOwnProperty.call(value, "stack");
|
|
1351
|
-
} catch (
|
|
1510
|
+
} catch (e27) {
|
|
1352
1511
|
return false;
|
|
1353
1512
|
}
|
|
1354
1513
|
}
|
|
@@ -1356,16 +1515,16 @@ function describeReason(reason) {
|
|
|
1356
1515
|
if (typeof reason !== "object" && typeof reason !== "function" || reason === null) {
|
|
1357
1516
|
try {
|
|
1358
1517
|
return String(reason);
|
|
1359
|
-
} catch (
|
|
1518
|
+
} catch (e28) {
|
|
1360
1519
|
return typeof reason;
|
|
1361
1520
|
}
|
|
1362
1521
|
}
|
|
1363
1522
|
try {
|
|
1364
1523
|
const proto = Object.getPrototypeOf(reason);
|
|
1365
|
-
const ctor = _optionalChain([proto, 'optionalAccess',
|
|
1524
|
+
const ctor = _optionalChain([proto, 'optionalAccess', _58 => _58.constructor]);
|
|
1366
1525
|
const name = typeof ctor === "function" ? ctor.name : "";
|
|
1367
1526
|
return name ? `#<${name}>` : "[object Object]";
|
|
1368
|
-
} catch (
|
|
1527
|
+
} catch (e29) {
|
|
1369
1528
|
return "[object Object]";
|
|
1370
1529
|
}
|
|
1371
1530
|
}
|
|
@@ -1376,7 +1535,7 @@ function toUncaught(reason, from) {
|
|
|
1376
1535
|
);
|
|
1377
1536
|
error.name = "UnhandledPromiseRejection";
|
|
1378
1537
|
error.code = "ERR_UNHANDLED_REJECTION";
|
|
1379
|
-
_optionalChain([Error, 'access',
|
|
1538
|
+
_optionalChain([Error, 'access', _59 => _59.captureStackTrace, 'optionalCall', _60 => _60(error, from)]);
|
|
1380
1539
|
return error;
|
|
1381
1540
|
}
|
|
1382
1541
|
var warningId = 0;
|
|
@@ -1388,7 +1547,7 @@ function emitNodeWarning(reason) {
|
|
|
1388
1547
|
`Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag \`--unhandled-rejections=strict\` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: ${++warningId})`,
|
|
1389
1548
|
"UnhandledPromiseRejectionWarning"
|
|
1390
1549
|
);
|
|
1391
|
-
} catch (
|
|
1550
|
+
} catch (e30) {
|
|
1392
1551
|
}
|
|
1393
1552
|
}
|
|
1394
1553
|
function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMode()) {
|
|
@@ -1415,7 +1574,7 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
|
|
|
1415
1574
|
}
|
|
1416
1575
|
markRecorded(reason);
|
|
1417
1576
|
capture(reason);
|
|
1418
|
-
} catch (
|
|
1577
|
+
} catch (e31) {
|
|
1419
1578
|
}
|
|
1420
1579
|
};
|
|
1421
1580
|
listener[LISTENER_MARK] = true;
|
|
@@ -1425,14 +1584,181 @@ function installUnhandledRejectionCapture(capture, mode = unhandledRejectionsMod
|
|
|
1425
1584
|
};
|
|
1426
1585
|
}
|
|
1427
1586
|
|
|
1587
|
+
// src/express-errors.ts
|
|
1588
|
+
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
var _requireinthemiddle = require('require-in-the-middle');
|
|
1592
|
+
var PATCHED = /* @__PURE__ */ Symbol.for("autter.runtime.express.layer");
|
|
1593
|
+
var WRAPPED = /* @__PURE__ */ Symbol.for("autter.runtime.express.next");
|
|
1594
|
+
var ERRORS = /* @__PURE__ */ Symbol.for("autter.runtime.express.errors");
|
|
1595
|
+
var MAX_ERRORS = 8;
|
|
1596
|
+
function noteExpressError(req, error) {
|
|
1597
|
+
if (error === void 0 || error === null || error === false) return;
|
|
1598
|
+
if (error === "route" || error === "router") return;
|
|
1599
|
+
if (!req || typeof req !== "object") return;
|
|
1600
|
+
try {
|
|
1601
|
+
const target = req;
|
|
1602
|
+
let list = target[ERRORS];
|
|
1603
|
+
if (!list) {
|
|
1604
|
+
list = [];
|
|
1605
|
+
target[ERRORS] = list;
|
|
1606
|
+
}
|
|
1607
|
+
if (list.length < MAX_ERRORS && !list.includes(error)) list.push(error);
|
|
1608
|
+
} catch (e32) {
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function wrapNext(req, next) {
|
|
1612
|
+
if (typeof next !== "function") return next;
|
|
1613
|
+
const fn = next;
|
|
1614
|
+
const existing = fn[WRAPPED];
|
|
1615
|
+
if (existing) return existing;
|
|
1616
|
+
const wrapped = function autterExpressNext(...args) {
|
|
1617
|
+
if (args.length > 0) noteExpressError(req, args[0]);
|
|
1618
|
+
return fn.apply(this, args);
|
|
1619
|
+
};
|
|
1620
|
+
try {
|
|
1621
|
+
fn[WRAPPED] = wrapped;
|
|
1622
|
+
} catch (e33) {
|
|
1623
|
+
}
|
|
1624
|
+
return wrapped;
|
|
1625
|
+
}
|
|
1626
|
+
function patchLayerPrototype(proto) {
|
|
1627
|
+
if (!proto || typeof proto !== "object") return false;
|
|
1628
|
+
const target = proto;
|
|
1629
|
+
if (target[PATCHED]) return true;
|
|
1630
|
+
const requestName = typeof target.handleRequest === "function" ? "handleRequest" : typeof target.handle_request === "function" ? "handle_request" : null;
|
|
1631
|
+
const errorName = typeof target.handleError === "function" ? "handleError" : typeof target.handle_error === "function" ? "handle_error" : null;
|
|
1632
|
+
if (!requestName || !errorName) return false;
|
|
1633
|
+
const handleRequest = target[requestName];
|
|
1634
|
+
const handleError = target[errorName];
|
|
1635
|
+
target[requestName] = function autterHandleRequest(req, res, next) {
|
|
1636
|
+
let wrapped = next;
|
|
1637
|
+
try {
|
|
1638
|
+
wrapped = wrapNext(req, next);
|
|
1639
|
+
} catch (e34) {
|
|
1640
|
+
wrapped = next;
|
|
1641
|
+
}
|
|
1642
|
+
return handleRequest.call(this, req, res, wrapped);
|
|
1643
|
+
};
|
|
1644
|
+
target[errorName] = function autterHandleError(error, req, res, next) {
|
|
1645
|
+
let wrapped = next;
|
|
1646
|
+
try {
|
|
1647
|
+
noteExpressError(req, error);
|
|
1648
|
+
wrapped = wrapNext(req, next);
|
|
1649
|
+
} catch (e35) {
|
|
1650
|
+
wrapped = next;
|
|
1651
|
+
}
|
|
1652
|
+
return handleError.call(this, error, req, res, wrapped);
|
|
1653
|
+
};
|
|
1654
|
+
try {
|
|
1655
|
+
Object.defineProperty(target, PATCHED, { value: true });
|
|
1656
|
+
} catch (e36) {
|
|
1657
|
+
target[PATCHED] = true;
|
|
1658
|
+
}
|
|
1659
|
+
return true;
|
|
1660
|
+
}
|
|
1661
|
+
var LAYER_FILES = ["express/lib/router/layer.js", "router/lib/layer.js"];
|
|
1662
|
+
function patchLayerModule(exports) {
|
|
1663
|
+
try {
|
|
1664
|
+
const Layer = exports;
|
|
1665
|
+
if (typeof Layer === "function" && patchLayerPrototype(Layer.prototype))
|
|
1666
|
+
_chunkS6WJ5YLPcjs.debugLog.call(void 0, "express: error capture installed");
|
|
1667
|
+
} catch (e37) {
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
function scanModuleCache() {
|
|
1671
|
+
try {
|
|
1672
|
+
const cache = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-express.cjs")).cache;
|
|
1673
|
+
for (const [key, entry] of Object.entries(cache)) {
|
|
1674
|
+
const path = key.replace(/\\/g, "/");
|
|
1675
|
+
if (LAYER_FILES.some((file) => path.endsWith(`/node_modules/${file}`)))
|
|
1676
|
+
patchLayerModule(_optionalChain([entry, 'optionalAccess', _61 => _61.exports]));
|
|
1677
|
+
}
|
|
1678
|
+
} catch (e38) {
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
var installed = false;
|
|
1682
|
+
function installExpressErrorCapture() {
|
|
1683
|
+
if (installed) return;
|
|
1684
|
+
installed = true;
|
|
1685
|
+
scanModuleCache();
|
|
1686
|
+
try {
|
|
1687
|
+
new (0, _requireinthemiddle.Hook)(["express", "router"], { internals: true }, (exports, name) => {
|
|
1688
|
+
const file = name.replace(/\\/g, "/");
|
|
1689
|
+
if (LAYER_FILES.includes(file)) patchLayerModule(exports);
|
|
1690
|
+
return exports;
|
|
1691
|
+
});
|
|
1692
|
+
} catch (e39) {
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
function patchFromRequest(req) {
|
|
1696
|
+
try {
|
|
1697
|
+
const app = _optionalChain([req, 'optionalAccess', _62 => _62.app]);
|
|
1698
|
+
if (!app || typeof app !== "function" && typeof app !== "object") return;
|
|
1699
|
+
const router = _nullishCoalesce(app._router, () => ( app.router));
|
|
1700
|
+
const layer = _optionalChain([router, 'optionalAccess', _63 => _63.stack, 'optionalAccess', _64 => _64[0]]);
|
|
1701
|
+
if (layer && typeof layer === "object" && patchLayerPrototype(Object.getPrototypeOf(layer)))
|
|
1702
|
+
_chunkS6WJ5YLPcjs.debugLog.call(void 0, "express: error capture installed (from a request)");
|
|
1703
|
+
} catch (e40) {
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
function declaredStatus(error) {
|
|
1707
|
+
if (!error || typeof error !== "object") return void 0;
|
|
1708
|
+
try {
|
|
1709
|
+
const value = _nullishCoalesce(error.status, () => ( error.statusCode));
|
|
1710
|
+
const status = typeof value === "string" ? Number(value) : value;
|
|
1711
|
+
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status < 600 ? status : void 0;
|
|
1712
|
+
} catch (e41) {
|
|
1713
|
+
return void 0;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
function watchExpressResponse(span, res, enabled) {
|
|
1717
|
+
const req = res.req;
|
|
1718
|
+
if (!req) return;
|
|
1719
|
+
const ctx = _api.context.active();
|
|
1720
|
+
let done = false;
|
|
1721
|
+
const settle = (finished) => {
|
|
1722
|
+
if (done) return;
|
|
1723
|
+
done = true;
|
|
1724
|
+
try {
|
|
1725
|
+
const errors = req[ERRORS];
|
|
1726
|
+
if (!_optionalChain([errors, 'optionalAccess', _65 => _65.length])) {
|
|
1727
|
+
patchFromRequest(req);
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
req[ERRORS] = void 0;
|
|
1731
|
+
if (!enabled()) return;
|
|
1732
|
+
if (finished && !(res.statusCode >= 500)) return;
|
|
1733
|
+
if (errors.some((error2) => _chunkSTOXJZ7Zcjs.isCaptured.call(void 0, error2))) return;
|
|
1734
|
+
const error = errors.find((candidate) => {
|
|
1735
|
+
const status = declaredStatus(candidate);
|
|
1736
|
+
return status === void 0 || status >= 500;
|
|
1737
|
+
});
|
|
1738
|
+
if (error === void 0) return;
|
|
1739
|
+
const state = requestStateOf(req);
|
|
1740
|
+
if (state && !state.sealed) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, false, state);
|
|
1741
|
+
const run = () => captureAtBoundary(error, state, true);
|
|
1742
|
+
if (span.isRecording()) _api.context.with(_api.trace.setSpan(ctx, span), run);
|
|
1743
|
+
else _api.context.with(ctx, run);
|
|
1744
|
+
} catch (e42) {
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
try {
|
|
1748
|
+
res.prependListener("finish", () => settle(true));
|
|
1749
|
+
res.prependListener("close", () => settle(false));
|
|
1750
|
+
} catch (e43) {
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1428
1754
|
// src/route-label.ts
|
|
1429
1755
|
|
|
1430
1756
|
var ours = /* @__PURE__ */ new WeakMap();
|
|
1431
1757
|
var RAW_PATH_SPAN_TYPES = /* @__PURE__ */ new Set(["BaseServer.renderToResponse"]);
|
|
1432
1758
|
function noteFrameworkRoute(parent, attributes) {
|
|
1433
|
-
const route = _optionalChain([attributes, 'optionalAccess',
|
|
1759
|
+
const route = _optionalChain([attributes, 'optionalAccess', _66 => _66["next.route"]]);
|
|
1434
1760
|
if (typeof route !== "string" || !route.startsWith("/")) return;
|
|
1435
|
-
if (RAW_PATH_SPAN_TYPES.has(String(_nullishCoalesce(_optionalChain([attributes, 'optionalAccess',
|
|
1761
|
+
if (RAW_PATH_SPAN_TYPES.has(String(_nullishCoalesce(_optionalChain([attributes, 'optionalAccess', _67 => _67["next.span_type"]]), () => ( ""))))) return;
|
|
1436
1762
|
const rpc = _core.getRPCMetadata.call(void 0, parent);
|
|
1437
1763
|
if (!rpc || rpc.type !== _core.RPCType.HTTP) return;
|
|
1438
1764
|
const mine = ours.get(rpc);
|
|
@@ -1450,7 +1776,7 @@ var RouteLabelSampler = class {
|
|
|
1450
1776
|
shouldSample(ctx, traceId, spanName, spanKind, attributes, links) {
|
|
1451
1777
|
try {
|
|
1452
1778
|
noteFrameworkRoute(ctx, attributes);
|
|
1453
|
-
} catch (
|
|
1779
|
+
} catch (e44) {
|
|
1454
1780
|
}
|
|
1455
1781
|
return this.delegate.shouldSample(ctx, traceId, spanName, spanKind, attributes, links);
|
|
1456
1782
|
}
|
|
@@ -1460,10 +1786,10 @@ var RouteLabelSampler = class {
|
|
|
1460
1786
|
};
|
|
1461
1787
|
|
|
1462
1788
|
// src/server.ts
|
|
1463
|
-
var S =
|
|
1789
|
+
var S = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "server", () => ({
|
|
1464
1790
|
active: null,
|
|
1465
1791
|
alwaysOnProvider: null,
|
|
1466
|
-
redactor:
|
|
1792
|
+
redactor: _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true),
|
|
1467
1793
|
loggerOnlyCapture: null,
|
|
1468
1794
|
handled: null,
|
|
1469
1795
|
loggerOnlyHandled: null,
|
|
@@ -1565,7 +1891,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
|
|
|
1565
1891
|
this.retainErrors = retainErrors;
|
|
1566
1892
|
this.slowThresholdMs = slowThresholdMs;
|
|
1567
1893
|
this.sweeper = setInterval(() => this.sweep(), RETENTION_SWEEP_INTERVAL_MS);
|
|
1568
|
-
_optionalChain([this, 'access',
|
|
1894
|
+
_optionalChain([this, 'access', _68 => _68.sweeper, 'access', _69 => _69.unref, 'optionalCall', _70 => _70()]);
|
|
1569
1895
|
}
|
|
1570
1896
|
|
|
1571
1897
|
|
|
@@ -1596,7 +1922,7 @@ var ErrorTraceRetentionProcessor = (_class2 = class {
|
|
|
1596
1922
|
}
|
|
1597
1923
|
/** Promote the active trace, if any — called on captured errors. */
|
|
1598
1924
|
retainActiveTrace() {
|
|
1599
|
-
const active = _optionalChain([_api.trace, 'access',
|
|
1925
|
+
const active = _optionalChain([_api.trace, 'access', _71 => _71.getActiveSpan, 'call', _72 => _72(), 'optionalAccess', _73 => _73.spanContext, 'call', _74 => _74()]);
|
|
1600
1926
|
if (!active || (active.traceFlags & _api.TraceFlags.SAMPLED) !== 0) return;
|
|
1601
1927
|
const entry = this.entryFor(active.traceId);
|
|
1602
1928
|
if (entry.retained) return;
|
|
@@ -1717,15 +2043,15 @@ async function runLlmSpan(tracer, info, fn) {
|
|
|
1717
2043
|
return result;
|
|
1718
2044
|
} catch (err) {
|
|
1719
2045
|
recordError(span, err);
|
|
1720
|
-
if (
|
|
2046
|
+
if (_chunkSTOXJZ7Zcjs.isError.call(void 0, err)) span.setAttribute("error.type", err.name);
|
|
1721
2047
|
throw err;
|
|
1722
2048
|
} finally {
|
|
1723
2049
|
span.end();
|
|
1724
|
-
|
|
2050
|
+
_chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, { ...usage, model: _nullishCoalesce(responseModel, () => ( info.model)) });
|
|
1725
2051
|
}
|
|
1726
2052
|
}
|
|
1727
2053
|
function recordLlmCall(tracer, call) {
|
|
1728
|
-
|
|
2054
|
+
_chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, { ...call, model: call.model });
|
|
1729
2055
|
const durationMs = Math.max(0, _nullishCoalesce(call.durationMs, () => ( 0)));
|
|
1730
2056
|
const endTime = /* @__PURE__ */ new Date();
|
|
1731
2057
|
const startTime = new Date(endTime.getTime() - durationMs);
|
|
@@ -1739,7 +2065,7 @@ function recordLlmCall(tracer, call) {
|
|
|
1739
2065
|
);
|
|
1740
2066
|
if (call.error !== void 0 && call.error !== null) {
|
|
1741
2067
|
recordError(span, call.error);
|
|
1742
|
-
if (
|
|
2068
|
+
if (_chunkSTOXJZ7Zcjs.isError.call(void 0, call.error)) {
|
|
1743
2069
|
span.setAttribute("error.type", call.error.name);
|
|
1744
2070
|
}
|
|
1745
2071
|
} else {
|
|
@@ -1750,7 +2076,7 @@ function recordLlmCall(tracer, call) {
|
|
|
1750
2076
|
async function runWithSpan(tracer, name, fn, attributes, links) {
|
|
1751
2077
|
const span = tracer.startSpan(name, {
|
|
1752
2078
|
attributes,
|
|
1753
|
-
..._optionalChain([links, 'optionalAccess',
|
|
2079
|
+
..._optionalChain([links, 'optionalAccess', _75 => _75.length]) ? { links } : {}
|
|
1754
2080
|
});
|
|
1755
2081
|
try {
|
|
1756
2082
|
const result = await _api.context.with(
|
|
@@ -1767,14 +2093,14 @@ async function runWithSpan(tracer, name, fn, attributes, links) {
|
|
|
1767
2093
|
}
|
|
1768
2094
|
}
|
|
1769
2095
|
function recordError(span, err) {
|
|
1770
|
-
const isErr =
|
|
2096
|
+
const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, err);
|
|
1771
2097
|
const message = S.redactor.text(isErr ? err.message : String(err));
|
|
1772
2098
|
if (isErr) {
|
|
1773
2099
|
span.addEvent("exception", {
|
|
1774
2100
|
"exception.type": err.name,
|
|
1775
2101
|
"exception.message": message,
|
|
1776
2102
|
...err.stack ? { "exception.stacktrace": S.redactor.text(err.stack) } : {},
|
|
1777
|
-
...
|
|
2103
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text, err)
|
|
1778
2104
|
});
|
|
1779
2105
|
}
|
|
1780
2106
|
span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
|
|
@@ -1787,14 +2113,14 @@ function patchLoadedHttpModules() {
|
|
|
1787
2113
|
const load = _module.createRequire.call(void 0, _path.join.call(void 0, process.cwd(), "autter-runtime-http.cjs"));
|
|
1788
2114
|
load("http");
|
|
1789
2115
|
load("https");
|
|
1790
|
-
} catch (
|
|
2116
|
+
} catch (e45) {
|
|
1791
2117
|
}
|
|
1792
2118
|
}
|
|
1793
2119
|
var METRIC_ROUTE_ATTR = "autter.metric_has_route";
|
|
1794
2120
|
function captureRequestRoute(span, response) {
|
|
1795
2121
|
if (!(response instanceof _http.ServerResponse)) return;
|
|
1796
2122
|
const rpcMetadata = _core.getRPCMetadata.call(void 0, _api.context.active());
|
|
1797
|
-
if (_optionalChain([rpcMetadata, 'optionalAccess',
|
|
2123
|
+
if (_optionalChain([rpcMetadata, 'optionalAccess', _76 => _76.type]) !== _core.RPCType.HTTP) return;
|
|
1798
2124
|
let failed = false;
|
|
1799
2125
|
response.on(_events.errorMonitor, () => {
|
|
1800
2126
|
failed = true;
|
|
@@ -1809,17 +2135,18 @@ function captureRequestRoute(span, response) {
|
|
|
1809
2135
|
setRoute();
|
|
1810
2136
|
if (rpcMetadata.route && !failed) span.setAttribute(METRIC_ROUTE_ATTR, true);
|
|
1811
2137
|
});
|
|
2138
|
+
if (S.expressErrors) watchExpressResponse(span, response, () => S.expressErrors === true);
|
|
1812
2139
|
if (S.hookRequests) startHookRequest(response);
|
|
1813
2140
|
}
|
|
1814
2141
|
function structuredErrorAttributes(error) {
|
|
1815
|
-
const attrs = { ...
|
|
1816
|
-
const internal =
|
|
2142
|
+
const attrs = { ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error, { causes: false }) };
|
|
2143
|
+
const internal = _chunkSTOXJZ7Zcjs.errorInternal.call(void 0, error);
|
|
1817
2144
|
if (internal) {
|
|
1818
2145
|
try {
|
|
1819
2146
|
attrs["autter.error.internal"] = JSON.stringify(
|
|
1820
2147
|
S.redactor(internal)
|
|
1821
2148
|
).slice(0, 4e3);
|
|
1822
|
-
} catch (
|
|
2149
|
+
} catch (e46) {
|
|
1823
2150
|
}
|
|
1824
2151
|
}
|
|
1825
2152
|
return attrs;
|
|
@@ -1830,22 +2157,26 @@ function initAutterServer(options) {
|
|
|
1830
2157
|
/\/$/,
|
|
1831
2158
|
""
|
|
1832
2159
|
);
|
|
1833
|
-
const
|
|
1834
|
-
const
|
|
2160
|
+
const apiKey = _chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, options.apiKey);
|
|
2161
|
+
const headers = _chunkS6WJ5YLPcjs.authHeaders.call(void 0, apiKey);
|
|
2162
|
+
const ingestTarget = { endpoint, hasKey: apiKey !== null };
|
|
2163
|
+
const redactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
|
|
1835
2164
|
const queryPolicy = makeUrlQueryPolicy(options.keepQueryParams);
|
|
1836
|
-
const traceExporter = () => new (0,
|
|
2165
|
+
const traceExporter = () => new (0, _chunkS6WJ5YLPcjs.CountingExporter)(
|
|
1837
2166
|
new RedactingSpanExporter(
|
|
1838
|
-
new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }),
|
|
2167
|
+
new IngestSpanExporter(new (0, _exportertraceotlphttp.OTLPTraceExporter)({ url: `${endpoint}/v1/traces`, headers }), ingestTarget),
|
|
1839
2168
|
() => redactor,
|
|
1840
2169
|
queryPolicy
|
|
1841
2170
|
)
|
|
1842
2171
|
);
|
|
1843
2172
|
const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
|
|
1844
|
-
if (
|
|
1845
|
-
|
|
2173
|
+
if (_chunkS6WJ5YLPcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkS6WJ5YLPcjs.setDebugMode.call(void 0, true);
|
|
2174
|
+
_chunkS6WJ5YLPcjs.debugLog.call(void 0, `initialising service=${options.service} endpoint=${endpoint}`);
|
|
2175
|
+
if (apiKey === null) _chunkS6WJ5YLPcjs.warnMissingKey.call(void 0, "server", options.service);
|
|
2176
|
+
else _chunkS6WJ5YLPcjs.warnKeyKind.call(void 0, apiKey);
|
|
1846
2177
|
S.redactor = redactor;
|
|
1847
|
-
const distro = _nullishCoalesce(options.distro, () => (
|
|
1848
|
-
|
|
2178
|
+
const distro = _nullishCoalesce(options.distro, () => ( _chunkS6WJ5YLPcjs.SDK_IDENTITY));
|
|
2179
|
+
_chunkS6WJ5YLPcjs.configureCompatCheck.call(void 0, { endpoint, enabled: options.compatCheck !== false, sdk: distro });
|
|
1849
2180
|
const resource = new (0, _resources.Resource)({
|
|
1850
2181
|
[_semanticconventions.ATTR_SERVICE_NAME]: options.service,
|
|
1851
2182
|
"service.instance.id": (options.instanceId || process.env.AUTTER_RUNTIME_INSTANCE_ID || _crypto.randomUUID.call(void 0, )).slice(0, 128),
|
|
@@ -1866,7 +2197,7 @@ function initAutterServer(options) {
|
|
|
1866
2197
|
// its span-fed per-route counts.
|
|
1867
2198
|
"autter.metrics_routes": true
|
|
1868
2199
|
});
|
|
1869
|
-
const errorFilter =
|
|
2200
|
+
const errorFilter = _chunkSTOXJZ7Zcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
|
|
1870
2201
|
const rootSampler = new (0, _sdktracebase.TraceIdRatioBasedSampler)(_nullishCoalesce(options.traceSampleRate, () => ( 0.01)));
|
|
1871
2202
|
const headSampler = new (0, _sdktracebase.ParentBasedSampler)({
|
|
1872
2203
|
root: rootSampler,
|
|
@@ -1891,7 +2222,7 @@ function initAutterServer(options) {
|
|
|
1891
2222
|
const mainSpanProcessor = new (0, _sdktracebase.BatchSpanProcessor)(traceExporter());
|
|
1892
2223
|
const metricReader = new (0, _sdkmetrics.PeriodicExportingMetricReader)({
|
|
1893
2224
|
exporter: new RedactingMetricExporter(
|
|
1894
|
-
new (0, _exportermetricsotlphttp.OTLPMetricExporter)({
|
|
2225
|
+
new IngestMetricExporter(new (0, _exportermetricsotlphttp.OTLPMetricExporter)({
|
|
1895
2226
|
url: `${endpoint}/v1/metrics`,
|
|
1896
2227
|
headers,
|
|
1897
2228
|
// Deltas, not lifetime totals: the ingester SUMs data points
|
|
@@ -1899,7 +2230,7 @@ function initAutterServer(options) {
|
|
|
1899
2230
|
// temporality would re-count every past request on each
|
|
1900
2231
|
// 60 s export.
|
|
1901
2232
|
temporalityPreference: _exportermetricsotlphttp.AggregationTemporalityPreference.DELTA
|
|
1902
|
-
}),
|
|
2233
|
+
}), ingestTarget),
|
|
1903
2234
|
() => redactor
|
|
1904
2235
|
),
|
|
1905
2236
|
exportIntervalMillis: _nullishCoalesce(options.metricIntervalMs, () => ( 6e4))
|
|
@@ -1928,9 +2259,9 @@ function initAutterServer(options) {
|
|
|
1928
2259
|
sdk.start();
|
|
1929
2260
|
patchLoadedHttpModules();
|
|
1930
2261
|
const stopMemoryMetrics = options.memoryMetrics === false ? null : startMemoryMetrics();
|
|
1931
|
-
|
|
1932
|
-
if (stopMemoryMetrics)
|
|
1933
|
-
if (options.llmTracing !== false)
|
|
2262
|
+
_chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "endpoint_latency");
|
|
2263
|
+
if (stopMemoryMetrics) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "memory_metrics");
|
|
2264
|
+
if (options.llmTracing !== false) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "llm_calls");
|
|
1934
2265
|
const alwaysOnProvider = new (0, _sdktracebase.BasicTracerProvider)({
|
|
1935
2266
|
resource,
|
|
1936
2267
|
sampler: new (0, _sdktracebase.AlwaysOnSampler)(),
|
|
@@ -1942,44 +2273,47 @@ function initAutterServer(options) {
|
|
|
1942
2273
|
const processTracer = alwaysOnProvider.getTracer("autter-processes");
|
|
1943
2274
|
const llmTracer = alwaysOnProvider.getTracer("autter-llm");
|
|
1944
2275
|
function captureException2(error, attributes) {
|
|
1945
|
-
const isErrValue =
|
|
2276
|
+
const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
|
|
1946
2277
|
const reported = errorFilter({
|
|
1947
2278
|
type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
|
|
1948
2279
|
message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
|
|
1949
|
-
crash: _optionalChain([attributes, 'optionalAccess',
|
|
2280
|
+
crash: _optionalChain([attributes, 'optionalAccess', _77 => _77["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _78 => _78["autter.unhandled_rejection"]]) === true
|
|
1950
2281
|
});
|
|
1951
2282
|
if (!reported) {
|
|
1952
|
-
|
|
2283
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
1953
2284
|
return;
|
|
1954
2285
|
}
|
|
1955
|
-
_optionalChain([errorTraceBuffer, 'optionalAccess',
|
|
1956
|
-
|
|
1957
|
-
const isErr =
|
|
2286
|
+
_optionalChain([errorTraceBuffer, 'optionalAccess', _79 => _79.retainActiveTrace, 'call', _80 => _80()]);
|
|
2287
|
+
_chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
|
|
2288
|
+
const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
|
|
1958
2289
|
const message = redactor.text(isErr ? error.message : String(error));
|
|
1959
2290
|
const stackText = isErr && error.stack ? redactor.text(error.stack) : "";
|
|
1960
|
-
const split =
|
|
1961
|
-
const fingerprint =
|
|
1962
|
-
if (fingerprint["autter.fingerprint"])
|
|
2291
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
2292
|
+
const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
|
|
2293
|
+
if (fingerprint["autter.fingerprint"]) _chunkS6WJ5YLPcjs.noteCompatFeature.call(void 0, "fingerprint_override");
|
|
1963
2294
|
const redacted = redactor(split.attributes);
|
|
2295
|
+
const crash = _optionalChain([attributes, 'optionalAccess', _81 => _81["autter.unhandled"]]) === true;
|
|
1964
2296
|
const activeSpan = _api.trace.getActiveSpan();
|
|
1965
|
-
const reuseActive = _optionalChain([activeSpan, 'optionalAccess',
|
|
2297
|
+
const reuseActive = !crash && _optionalChain([activeSpan, 'optionalAccess', _82 => _82.isRecording, 'call', _83 => _83()]) === true;
|
|
1966
2298
|
const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
|
|
2299
|
+
const scope = reuseActive ? void 0 : requestScopeAttributes();
|
|
1967
2300
|
const structured = structuredErrorAttributes(error);
|
|
1968
|
-
const causes =
|
|
2301
|
+
const causes = _chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error);
|
|
1969
2302
|
const declared = {
|
|
1970
2303
|
...Object.fromEntries(Object.entries(causes).filter(([key]) => key !== "autter.error.internal")),
|
|
1971
2304
|
...fingerprint
|
|
1972
2305
|
};
|
|
1973
|
-
const requestId = _optionalChain([
|
|
2306
|
+
const requestId = _optionalChain([_chunkSTOXJZ7Zcjs.currentOperation.call(void 0, ), 'optionalAccess', _84 => _84.requestId]);
|
|
1974
2307
|
span.setAttributes({
|
|
2308
|
+
...scope,
|
|
1975
2309
|
"autter.severity": "error",
|
|
1976
2310
|
...redacted,
|
|
1977
2311
|
...structured,
|
|
1978
2312
|
...requestId ? { "autter.request.id": requestId } : {}
|
|
1979
2313
|
});
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2314
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
2315
|
+
_chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
|
|
2316
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
|
|
1983
2317
|
if (isErr && stackText) {
|
|
1984
2318
|
span.addEvent("exception", {
|
|
1985
2319
|
"exception.type": error.name,
|
|
@@ -1987,17 +2321,17 @@ function initAutterServer(options) {
|
|
|
1987
2321
|
"exception.stacktrace": stackText,
|
|
1988
2322
|
...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
|
|
1989
2323
|
...declared,
|
|
1990
|
-
...
|
|
2324
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
|
|
1991
2325
|
});
|
|
1992
2326
|
} else {
|
|
1993
|
-
const stack = _optionalChain([new Error(), 'access',
|
|
2327
|
+
const stack = _optionalChain([new Error(), 'access', _85 => _85.stack, 'optionalAccess', _86 => _86.split, 'call', _87 => _87("\n"), 'access', _88 => _88.filter, 'call', _89 => _89((line, i) => i === 0 || !line.includes("captureException")), 'access', _90 => _90.join, 'call', _91 => _91("\n")]);
|
|
1994
2328
|
span.addEvent("exception", {
|
|
1995
2329
|
"exception.type": isErr ? error.name : "Error",
|
|
1996
2330
|
"exception.message": message,
|
|
1997
2331
|
...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
|
|
1998
2332
|
...redacted["autter.handled"] === true ? { "autter.handled": true, "autter.sampled": redacted["autter.sampled"] === true } : {},
|
|
1999
2333
|
...declared,
|
|
2000
|
-
...
|
|
2334
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
|
|
2001
2335
|
});
|
|
2002
2336
|
}
|
|
2003
2337
|
span.setStatus({ code: _api.SpanStatusCode.ERROR, message });
|
|
@@ -2006,10 +2340,10 @@ function initAutterServer(options) {
|
|
|
2006
2340
|
function captureMessage2(message, severity = "warning", attributes) {
|
|
2007
2341
|
if (!errorFilter({ type: "Message", message: String(message), severity })) return;
|
|
2008
2342
|
if (severity === "error" || severity === "fatal") {
|
|
2009
|
-
_optionalChain([errorTraceBuffer, 'optionalAccess',
|
|
2343
|
+
_optionalChain([errorTraceBuffer, 'optionalAccess', _92 => _92.retainActiveTrace, 'call', _93 => _93()]);
|
|
2010
2344
|
}
|
|
2011
|
-
|
|
2012
|
-
const stack = _optionalChain([new Error(), 'access',
|
|
2345
|
+
_chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
|
|
2346
|
+
const stack = _optionalChain([new Error(), 'access', _94 => _94.stack, 'optionalAccess', _95 => _95.split, 'call', _96 => _96("\n"), 'access', _97 => _97.filter, 'call', _98 => _98((line, i) => i === 0 || !line.includes("captureMessage")), 'access', _99 => _99.join, 'call', _100 => _100("\n")]);
|
|
2013
2347
|
const safeMessage = redactor.text(message);
|
|
2014
2348
|
const span = errorTracer.startSpan("Message", {
|
|
2015
2349
|
attributes: { "autter.severity": severity, ...redactor(attributes) }
|
|
@@ -2019,17 +2353,17 @@ function initAutterServer(options) {
|
|
|
2019
2353
|
"exception.message": safeMessage,
|
|
2020
2354
|
...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
|
|
2021
2355
|
"autter.severity": severity,
|
|
2022
|
-
...
|
|
2356
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text)
|
|
2023
2357
|
});
|
|
2024
2358
|
span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
|
|
2025
2359
|
span.end();
|
|
2026
2360
|
}
|
|
2027
2361
|
function reportOutcome2(name, message, attributes) {
|
|
2028
2362
|
if (!errorFilter({ type: "OutcomeFailure", message: `${name}: ${message}` })) return;
|
|
2029
|
-
_optionalChain([errorTraceBuffer, 'optionalAccess',
|
|
2030
|
-
|
|
2363
|
+
_optionalChain([errorTraceBuffer, 'optionalAccess', _101 => _101.retainActiveTrace, 'call', _102 => _102()]);
|
|
2364
|
+
_chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
|
|
2031
2365
|
const activeSpan = _api.trace.getActiveSpan();
|
|
2032
|
-
const reuseActive = _optionalChain([activeSpan, 'optionalAccess',
|
|
2366
|
+
const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _103 => _103.isRecording, 'call', _104 => _104()]) === true;
|
|
2033
2367
|
const span = reuseActive ? activeSpan : errorTracer.startSpan("OutcomeFailure");
|
|
2034
2368
|
const safeOutcome = redactor({ "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
|
|
2035
2369
|
const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
|
|
@@ -2044,39 +2378,39 @@ function initAutterServer(options) {
|
|
|
2044
2378
|
if (!reuseActive) span.end();
|
|
2045
2379
|
}
|
|
2046
2380
|
function captureHandled(error, attributes, severity) {
|
|
2047
|
-
const isErr =
|
|
2381
|
+
const isErr = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
|
|
2048
2382
|
if (!errorFilter({
|
|
2049
2383
|
type: isErr ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
|
|
2050
2384
|
message: isErr ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
|
|
2051
2385
|
severity
|
|
2052
2386
|
})) return;
|
|
2053
|
-
if (severity === "error") _optionalChain([errorTraceBuffer, 'optionalAccess',
|
|
2054
|
-
|
|
2387
|
+
if (severity === "error") _optionalChain([errorTraceBuffer, 'optionalAccess', _105 => _105.retainActiveTrace, 'call', _106 => _106()]);
|
|
2388
|
+
_chunkS6WJ5YLPcjs.telemetryStats.markCaptured();
|
|
2055
2389
|
const message = redactor.text(isErr ? error.message : String(error));
|
|
2056
|
-
const stack = isErr && error.stack ? error.stack : _optionalChain([new Error(), 'access',
|
|
2057
|
-
const split =
|
|
2058
|
-
const fingerprint =
|
|
2390
|
+
const stack = isErr && error.stack ? error.stack : _optionalChain([new Error(), 'access', _107 => _107.stack, 'optionalAccess', _108 => _108.split, 'call', _109 => _109("\n"), 'access', _110 => _110.filter, 'call', _111 => _111((line, i) => i === 0 || !/captureHandled|report(?:Degraded|LoggedError)/.test(line)), 'access', _112 => _112.join, 'call', _113 => _113("\n")]);
|
|
2391
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
2392
|
+
const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redactor.text);
|
|
2059
2393
|
const redacted = redactor(split.attributes);
|
|
2060
2394
|
const activeSpan = _api.trace.getActiveSpan();
|
|
2061
|
-
const reuseActive = _optionalChain([activeSpan, 'optionalAccess',
|
|
2395
|
+
const reuseActive = _optionalChain([activeSpan, 'optionalAccess', _114 => _114.isRecording, 'call', _115 => _115()]) === true;
|
|
2062
2396
|
const span = reuseActive ? activeSpan : errorTracer.startSpan(isErr ? error.name : "Error");
|
|
2063
|
-
|
|
2064
|
-
|
|
2397
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
2398
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
|
|
2065
2399
|
span.addEvent("exception", {
|
|
2066
2400
|
...redacted,
|
|
2067
2401
|
"exception.type": isErr ? error.name : "Error",
|
|
2068
2402
|
"exception.message": message,
|
|
2069
2403
|
...stack ? { "exception.stacktrace": redactor.text(stack) } : {},
|
|
2070
2404
|
"autter.severity": severity,
|
|
2071
|
-
...
|
|
2405
|
+
..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
|
|
2072
2406
|
...fingerprint,
|
|
2073
|
-
...
|
|
2407
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, redactor.text, error)
|
|
2074
2408
|
});
|
|
2075
2409
|
if (!reuseActive) span.end();
|
|
2076
2410
|
}
|
|
2077
|
-
|
|
2411
|
+
_chunkSTOXJZ7Zcjs.configureRuntimeLogger.call(void 0, {
|
|
2078
2412
|
endpoint,
|
|
2079
|
-
apiKey:
|
|
2413
|
+
apiKey: _nullishCoalesce(apiKey, () => ( "")),
|
|
2080
2414
|
service: options.service,
|
|
2081
2415
|
environment,
|
|
2082
2416
|
distro,
|
|
@@ -2086,9 +2420,11 @@ function initAutterServer(options) {
|
|
|
2086
2420
|
run: (name, fn, attributes, links) => runWithSpan(processTracer, name, fn, redactor(attributes), links),
|
|
2087
2421
|
reportOutcome: reportOutcome2
|
|
2088
2422
|
});
|
|
2089
|
-
S.hookRequests = _optionalChain([options, 'access',
|
|
2423
|
+
S.hookRequests = _optionalChain([options, 'access', _116 => _116.logging, 'optionalAccess', _117 => _117.requests]) === true;
|
|
2424
|
+
S.expressErrors = options.captureExpressErrors !== false;
|
|
2425
|
+
if (S.expressErrors) installExpressErrorCapture();
|
|
2090
2426
|
S.handled = captureHandled;
|
|
2091
|
-
|
|
2427
|
+
_chunkSTOXJZ7Zcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
|
|
2092
2428
|
let onCrash = null;
|
|
2093
2429
|
let uninstallRejections = null;
|
|
2094
2430
|
if (options.captureGlobalErrors !== false) {
|
|
@@ -2108,7 +2444,7 @@ function initAutterServer(options) {
|
|
|
2108
2444
|
const flushTarget = {
|
|
2109
2445
|
forceFlush: async () => {
|
|
2110
2446
|
const results = await Promise.allSettled([
|
|
2111
|
-
|
|
2447
|
+
_chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ),
|
|
2112
2448
|
Promise.resolve().then(() => alwaysOnProvider.forceFlush()),
|
|
2113
2449
|
Promise.resolve().then(() => mainSpanProcessor.forceFlush()),
|
|
2114
2450
|
...errorTraceBuffer ? [Promise.resolve().then(() => errorTraceBuffer.forceFlush())] : [],
|
|
@@ -2122,10 +2458,10 @@ function initAutterServer(options) {
|
|
|
2122
2458
|
}
|
|
2123
2459
|
}
|
|
2124
2460
|
};
|
|
2125
|
-
|
|
2461
|
+
_chunkS6WJ5YLPcjs.registerFlushTarget.call(void 0, "active-server", flushTarget);
|
|
2126
2462
|
let autoFlushHandle = null;
|
|
2127
2463
|
if (options.autoFlush !== false) {
|
|
2128
|
-
autoFlushHandle =
|
|
2464
|
+
autoFlushHandle = _chunkS6WJ5YLPcjs.installAutterAutoFlush.call(void 0, );
|
|
2129
2465
|
}
|
|
2130
2466
|
const server = {
|
|
2131
2467
|
captureException: captureException2,
|
|
@@ -2135,24 +2471,25 @@ function initAutterServer(options) {
|
|
|
2135
2471
|
withLlmCall: (info, fn) => runLlmSpan(llmTracer, info, fn),
|
|
2136
2472
|
trackLlmCall: (call) => recordLlmCall(llmTracer, call),
|
|
2137
2473
|
shutdown: async () => {
|
|
2138
|
-
if (S.active === server)
|
|
2139
|
-
const logShutdown = await Promise.allSettled([
|
|
2474
|
+
if (S.active === server) _chunkSTOXJZ7Zcjs.stopLoggedErrorCapture.call(void 0, );
|
|
2475
|
+
const logShutdown = await Promise.allSettled([_chunkSTOXJZ7Zcjs.shutdownRuntimeLogger.call(void 0, )]);
|
|
2140
2476
|
if (onCrash) process.off("uncaughtExceptionMonitor", onCrash);
|
|
2141
|
-
_optionalChain([uninstallRejections, 'optionalCall',
|
|
2142
|
-
_optionalChain([stopMemoryMetrics, 'optionalCall',
|
|
2477
|
+
_optionalChain([uninstallRejections, 'optionalCall', _118 => _118()]);
|
|
2478
|
+
_optionalChain([stopMemoryMetrics, 'optionalCall', _119 => _119()]);
|
|
2143
2479
|
if (S.active === server) {
|
|
2144
2480
|
S.active = null;
|
|
2145
2481
|
S.alwaysOnProvider = null;
|
|
2146
2482
|
S.handled = null;
|
|
2147
2483
|
S.hookRequests = false;
|
|
2148
|
-
S.
|
|
2484
|
+
S.expressErrors = false;
|
|
2485
|
+
S.redactor = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, true);
|
|
2149
2486
|
}
|
|
2150
|
-
_optionalChain([autoFlushHandle, 'optionalAccess',
|
|
2487
|
+
_optionalChain([autoFlushHandle, 'optionalAccess', _120 => _120.dispose, 'call', _121 => _121()]);
|
|
2151
2488
|
autoFlushHandle = null;
|
|
2152
|
-
|
|
2153
|
-
|
|
2489
|
+
_chunkS6WJ5YLPcjs.unregisterFlushTargets.call(void 0, );
|
|
2490
|
+
_chunkS6WJ5YLPcjs.telemetryStats.markAllFlushed();
|
|
2154
2491
|
await Promise.allSettled([alwaysOnProvider.shutdown(), sdk.shutdown()]);
|
|
2155
|
-
if (_optionalChain([logShutdown, 'access',
|
|
2492
|
+
if (_optionalChain([logShutdown, 'access', _122 => _122[0], 'optionalAccess', _123 => _123.status]) === "rejected") throw logShutdown[0].reason;
|
|
2156
2493
|
}
|
|
2157
2494
|
};
|
|
2158
2495
|
S.active = server;
|
|
@@ -2168,12 +2505,12 @@ function captureException(error, attributes) {
|
|
|
2168
2505
|
S.loggerOnlyCapture(error, attributes);
|
|
2169
2506
|
return;
|
|
2170
2507
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
const split =
|
|
2174
|
-
const fingerprint =
|
|
2175
|
-
|
|
2176
|
-
const span = _api.trace.getTracer("autter-errors").startSpan(
|
|
2508
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
2509
|
+
_chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
|
|
2510
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
2511
|
+
const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text);
|
|
2512
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...split.attributes, ...fingerprint });
|
|
2513
|
+
const span = _api.trace.getTracer("autter-errors").startSpan(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error", {
|
|
2177
2514
|
attributes: { ...S.redactor(split.attributes), ...fingerprint }
|
|
2178
2515
|
});
|
|
2179
2516
|
recordError(span, error);
|
|
@@ -2185,25 +2522,25 @@ function setLoggerOnlyCapture(fn, handled = null) {
|
|
|
2185
2522
|
}
|
|
2186
2523
|
function captureHandledError(error, attributes, severity) {
|
|
2187
2524
|
if (S.active) {
|
|
2188
|
-
_optionalChain([S, 'access',
|
|
2525
|
+
_optionalChain([S, 'access', _124 => _124.handled, 'optionalCall', _125 => _125(error, attributes, severity)]);
|
|
2189
2526
|
return;
|
|
2190
2527
|
}
|
|
2191
2528
|
if (S.loggerOnlyHandled) {
|
|
2192
2529
|
S.loggerOnlyHandled(error, attributes, severity);
|
|
2193
2530
|
return;
|
|
2194
2531
|
}
|
|
2195
|
-
|
|
2196
|
-
const split =
|
|
2197
|
-
|
|
2198
|
-
const span = _api.trace.getTracer("autter-errors").startSpan(
|
|
2532
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
2533
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
2534
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...split.attributes, "autter.severity": severity });
|
|
2535
|
+
const span = _api.trace.getTracer("autter-errors").startSpan(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error");
|
|
2199
2536
|
span.addEvent("exception", {
|
|
2200
2537
|
...S.redactor(split.attributes),
|
|
2201
|
-
"exception.type":
|
|
2202
|
-
"exception.message": S.redactor.text(
|
|
2203
|
-
...
|
|
2538
|
+
"exception.type": _chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.name : "Error",
|
|
2539
|
+
"exception.message": S.redactor.text(_chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.message : String(error)),
|
|
2540
|
+
..._chunkSTOXJZ7Zcjs.isError.call(void 0, error) && error.stack ? { "exception.stacktrace": S.redactor.text(error.stack) } : {},
|
|
2204
2541
|
"autter.severity": severity,
|
|
2205
|
-
...
|
|
2206
|
-
...
|
|
2542
|
+
..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
|
|
2543
|
+
..._chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, S.redactor.text)
|
|
2207
2544
|
});
|
|
2208
2545
|
span.end();
|
|
2209
2546
|
}
|
|
@@ -2211,10 +2548,10 @@ function serverActive() {
|
|
|
2211
2548
|
return S.active !== null;
|
|
2212
2549
|
}
|
|
2213
2550
|
setRequestExceptionCapturer((error, attributes) => captureException(error, attributes));
|
|
2214
|
-
|
|
2551
|
+
_chunkSTOXJZ7Zcjs.setHandledCapture.call(void 0, captureHandledError);
|
|
2215
2552
|
setRequestSpanAnnotator((attributes) => {
|
|
2216
2553
|
const span = _api.trace.getActiveSpan();
|
|
2217
|
-
if (_optionalChain([span, 'optionalAccess',
|
|
2554
|
+
if (_optionalChain([span, 'optionalAccess', _126 => _126.isRecording, 'call', _127 => _127()])) span.setAttributes(S.redactor(_chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes).attributes));
|
|
2218
2555
|
});
|
|
2219
2556
|
function withProcessSpan(name, fn, attributes) {
|
|
2220
2557
|
if (S.active) return S.active.withProcessSpan(name, fn, attributes);
|
|
@@ -2249,7 +2586,7 @@ function captureMessage(message, severity = "warning", attributes) {
|
|
|
2249
2586
|
"exception.type": "Message",
|
|
2250
2587
|
"exception.message": safeMessage,
|
|
2251
2588
|
"autter.severity": severity,
|
|
2252
|
-
...
|
|
2589
|
+
..._chunkSTOXJZ7Zcjs.breadcrumbEventAttributes.call(void 0, S.redactor.text)
|
|
2253
2590
|
});
|
|
2254
2591
|
span.setStatus({ code: _api.SpanStatusCode.ERROR, message: safeMessage });
|
|
2255
2592
|
span.end();
|
|
@@ -2257,11 +2594,11 @@ function captureMessage(message, severity = "warning", attributes) {
|
|
|
2257
2594
|
function reportOutcome(name, message, attributes) {
|
|
2258
2595
|
if (S.active) return S.active.reportOutcome(name, message, attributes);
|
|
2259
2596
|
const span = _api.trace.getTracer("autter-outcomes").startSpan("OutcomeFailure");
|
|
2260
|
-
const safeOutcome =
|
|
2597
|
+
const safeOutcome = _chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, { "autter.outcome.name": name.slice(0, 200), "autter.outcome.message": message.slice(0, 1e3) });
|
|
2261
2598
|
const safeName = String(_nullishCoalesce(safeOutcome["autter.outcome.name"], () => ( "operation")));
|
|
2262
2599
|
const safeMessage = String(_nullishCoalesce(safeOutcome["autter.outcome.message"], () => ( "failed")));
|
|
2263
2600
|
span.addEvent("autter.outcome", {
|
|
2264
|
-
...
|
|
2601
|
+
..._chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, attributes),
|
|
2265
2602
|
"autter.outcome.status": "error",
|
|
2266
2603
|
"autter.outcome.name": safeName,
|
|
2267
2604
|
"autter.outcome.message": safeMessage
|
|
@@ -2270,7 +2607,7 @@ function reportOutcome(name, message, attributes) {
|
|
|
2270
2607
|
span.end();
|
|
2271
2608
|
}
|
|
2272
2609
|
function makeSafeCapture(options) {
|
|
2273
|
-
const clean = (attributes) => attributes ? { ...
|
|
2610
|
+
const clean = (attributes) => attributes ? { ..._chunkSTOXJZ7Zcjs.redactAttributes.call(void 0, attributes, options) } : void 0;
|
|
2274
2611
|
return {
|
|
2275
2612
|
captureException: (error, attributes) => captureException(error, clean(attributes)),
|
|
2276
2613
|
captureMessage: (message, severity, attributes) => captureMessage(message, _nullishCoalesce(severity, () => ( "warning")), clean(attributes))
|
|
@@ -2297,7 +2634,7 @@ async function emitLlmSelftestTrace() {
|
|
|
2297
2634
|
attributes: { "autter.selftest": true }
|
|
2298
2635
|
},
|
|
2299
2636
|
(llm) => {
|
|
2300
|
-
traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access',
|
|
2637
|
+
traceId = _nullishCoalesce(_optionalChain([_api.trace, 'access', _128 => _128.getActiveSpan, 'call', _129 => _129(), 'optionalAccess', _130 => _130.spanContext, 'call', _131 => _131(), 'access', _132 => _132.traceId]), () => ( ""));
|
|
2301
2638
|
llm.setUsage({ inputTokens: 1, outputTokens: 1 });
|
|
2302
2639
|
llm.setCost(0);
|
|
2303
2640
|
}
|
|
@@ -2325,7 +2662,7 @@ var CALL_METHODS = /* @__PURE__ */ new Set([
|
|
|
2325
2662
|
// openai beta structured outputs
|
|
2326
2663
|
]);
|
|
2327
2664
|
function detectProvider(client) {
|
|
2328
|
-
const name = _nullishCoalesce(_optionalChain([client, 'access',
|
|
2665
|
+
const name = _nullishCoalesce(_optionalChain([client, 'access', _133 => _133.constructor, 'optionalAccess', _134 => _134.name, 'optionalAccess', _135 => _135.toLowerCase, 'call', _136 => _136()]), () => ( ""));
|
|
2329
2666
|
for (const known of ["openai", "anthropic", "mistral", "groq", "cohere"]) {
|
|
2330
2667
|
if (name.includes(known)) return known;
|
|
2331
2668
|
}
|
|
@@ -2333,7 +2670,7 @@ function detectProvider(client) {
|
|
|
2333
2670
|
const baseUrl = String(
|
|
2334
2671
|
_nullishCoalesce(_nullishCoalesce(client.baseURL, () => ( client.baseUrl)), () => ( ""))
|
|
2335
2672
|
);
|
|
2336
|
-
const host = _nullishCoalesce(_optionalChain([baseUrl, 'access',
|
|
2673
|
+
const host = _nullishCoalesce(_optionalChain([baseUrl, 'access', _137 => _137.match, 'call', _138 => _138(/https?:\/\/([^/]+)/), 'optionalAccess', _139 => _139[1]]), () => ( ""));
|
|
2337
2674
|
if (host.includes("openai")) return "openai";
|
|
2338
2675
|
if (host.includes("anthropic")) return "anthropic";
|
|
2339
2676
|
if (host.includes("googleapis")) return "google";
|
|
@@ -2343,13 +2680,13 @@ function detectProvider(client) {
|
|
|
2343
2680
|
}
|
|
2344
2681
|
function extractUsage(result) {
|
|
2345
2682
|
const r = result;
|
|
2346
|
-
const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess',
|
|
2347
|
-
const meta = _optionalChain([r, 'optionalAccess',
|
|
2348
|
-
const details = _optionalChain([usage, 'optionalAccess',
|
|
2349
|
-
const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess',
|
|
2350
|
-
const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess',
|
|
2351
|
-
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess',
|
|
2352
|
-
const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess',
|
|
2683
|
+
const usage = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _140 => _140.usage]), () => ( _optionalChain([r, 'optionalAccess', _141 => _141.message, 'optionalAccess', _142 => _142.usage])));
|
|
2684
|
+
const meta = _optionalChain([r, 'optionalAccess', _143 => _143.usageMetadata]);
|
|
2685
|
+
const details = _optionalChain([usage, 'optionalAccess', _144 => _144.prompt_tokens_details]);
|
|
2686
|
+
const cached = _nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _145 => _145.cache_read_input_tokens]), () => ( (typeof _optionalChain([details, 'optionalAccess', _146 => _146.cached_tokens]) === "number" ? details.cached_tokens : void 0))), () => ( _optionalChain([meta, 'optionalAccess', _147 => _147.cachedContentTokenCount])));
|
|
2687
|
+
const input = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _148 => _148.prompt_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _149 => _149.input_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _150 => _150.promptTokenCount]))), () => ( void 0));
|
|
2688
|
+
const output = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([usage, 'optionalAccess', _151 => _151.completion_tokens]), () => ( _optionalChain([usage, 'optionalAccess', _152 => _152.output_tokens]))), () => ( _optionalChain([meta, 'optionalAccess', _153 => _153.candidatesTokenCount]))), () => ( void 0));
|
|
2689
|
+
const responseModel = _nullishCoalesce(_optionalChain([r, 'optionalAccess', _154 => _154.model]), () => ( _optionalChain([r, 'optionalAccess', _155 => _155.modelVersion])));
|
|
2353
2690
|
return {
|
|
2354
2691
|
inputTokens: typeof input === "number" ? input : void 0,
|
|
2355
2692
|
outputTokens: typeof output === "number" ? output : void 0,
|
|
@@ -2358,7 +2695,7 @@ function extractUsage(result) {
|
|
|
2358
2695
|
};
|
|
2359
2696
|
}
|
|
2360
2697
|
function rollUp(model, usage) {
|
|
2361
|
-
|
|
2698
|
+
_chunkSTOXJZ7Zcjs.recordOperationAiUsage.call(void 0, {
|
|
2362
2699
|
model: _nullishCoalesce(usage.responseModel, () => ( model)),
|
|
2363
2700
|
...usage.inputTokens !== void 0 ? { inputTokens: usage.inputTokens } : {},
|
|
2364
2701
|
...usage.outputTokens !== void 0 ? { outputTokens: usage.outputTokens } : {},
|
|
@@ -2442,10 +2779,10 @@ function wrapStream(stream, span, model) {
|
|
|
2442
2779
|
});
|
|
2443
2780
|
}
|
|
2444
2781
|
function instrumentLlmClient(client, options) {
|
|
2445
|
-
const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2782
|
+
const provider = (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _156 => _156.provider]), () => ( detectProvider(client)))).toLowerCase();
|
|
2446
2783
|
const proxied = /* @__PURE__ */ new WeakMap();
|
|
2447
2784
|
function resolveUserId() {
|
|
2448
|
-
return typeof _optionalChain([options, 'optionalAccess',
|
|
2785
|
+
return typeof _optionalChain([options, 'optionalAccess', _157 => _157.userId]) === "function" ? options.userId() : _optionalChain([options, 'optionalAccess', _158 => _158.userId]);
|
|
2449
2786
|
}
|
|
2450
2787
|
function traceCall(fn, self, callPath, args) {
|
|
2451
2788
|
const request = args[0];
|
|
@@ -2459,7 +2796,7 @@ function instrumentLlmClient(client, options) {
|
|
|
2459
2796
|
"gen_ai.system": provider,
|
|
2460
2797
|
"gen_ai.request.model": request.model,
|
|
2461
2798
|
...userId ? { "autter.user_id": userId } : {},
|
|
2462
|
-
...redactWithActive(_optionalChain([options, 'optionalAccess',
|
|
2799
|
+
...redactWithActive(_optionalChain([options, 'optionalAccess', _159 => _159.attributes]))
|
|
2463
2800
|
}
|
|
2464
2801
|
});
|
|
2465
2802
|
let result;
|
|
@@ -2583,9 +2920,9 @@ ${frames.join("\n")}`;
|
|
|
2583
2920
|
function recordBoundaryError(error, req, rule) {
|
|
2584
2921
|
try {
|
|
2585
2922
|
const state = requestStateOf(req);
|
|
2586
|
-
if (state)
|
|
2923
|
+
if (state) _chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error, false, state);
|
|
2587
2924
|
captureAtBoundary(error, state, rule);
|
|
2588
|
-
} catch (
|
|
2925
|
+
} catch (e47) {
|
|
2589
2926
|
}
|
|
2590
2927
|
}
|
|
2591
2928
|
function autterErrorHandler(options = {}) {
|
|
@@ -2595,12 +2932,12 @@ function autterErrorHandler(options = {}) {
|
|
|
2595
2932
|
};
|
|
2596
2933
|
}
|
|
2597
2934
|
function autterFastifyErrors(fastify, options, done) {
|
|
2598
|
-
const rule = _optionalChain([options, 'optionalAccess',
|
|
2935
|
+
const rule = _optionalChain([options, 'optionalAccess', _160 => _160.capture]);
|
|
2599
2936
|
fastify.addHook("onError", ((request, _reply, error, next) => {
|
|
2600
|
-
recordBoundaryError(error, _optionalChain([request, 'optionalAccess',
|
|
2937
|
+
recordBoundaryError(error, _optionalChain([request, 'optionalAccess', _161 => _161.raw]), rule);
|
|
2601
2938
|
next();
|
|
2602
2939
|
}));
|
|
2603
|
-
_optionalChain([done, 'optionalCall',
|
|
2940
|
+
_optionalChain([done, 'optionalCall', _162 => _162()]);
|
|
2604
2941
|
}
|
|
2605
2942
|
autterFastifyErrors[/* @__PURE__ */ Symbol.for("skip-override")] = true;
|
|
2606
2943
|
autterFastifyErrors[/* @__PURE__ */ Symbol.for("fastify.display-name")] = "autter-runtime-errors";
|
|
@@ -2609,7 +2946,7 @@ function autterKoa(options = {}) {
|
|
|
2609
2946
|
try {
|
|
2610
2947
|
await next();
|
|
2611
2948
|
} catch (error) {
|
|
2612
|
-
recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess',
|
|
2949
|
+
recordBoundaryError(error, _optionalChain([ctx, 'optionalAccess', _163 => _163.req]), options.capture);
|
|
2613
2950
|
throw error;
|
|
2614
2951
|
}
|
|
2615
2952
|
};
|
|
@@ -2620,7 +2957,7 @@ function autterKoa(options = {}) {
|
|
|
2620
2957
|
|
|
2621
2958
|
|
|
2622
2959
|
|
|
2623
|
-
var L =
|
|
2960
|
+
var L = _chunkS6WJ5YLPcjs.sharedSlot.call(void 0, "logging", () => ({ active: null }));
|
|
2624
2961
|
function initAutterLogging(options) {
|
|
2625
2962
|
if (L.active) return L.active;
|
|
2626
2963
|
if (serverActive()) {
|
|
@@ -2629,37 +2966,37 @@ function initAutterLogging(options) {
|
|
|
2629
2966
|
);
|
|
2630
2967
|
return {
|
|
2631
2968
|
captureException,
|
|
2632
|
-
flush:
|
|
2969
|
+
flush: _chunkSTOXJZ7Zcjs.flushRuntimeLogs,
|
|
2633
2970
|
shutdown: async () => {
|
|
2634
2971
|
}
|
|
2635
2972
|
};
|
|
2636
2973
|
}
|
|
2637
|
-
if (
|
|
2974
|
+
if (_chunkS6WJ5YLPcjs.isDebugEnabled.call(void 0, ) || options.debug === true) _chunkS6WJ5YLPcjs.setDebugMode.call(void 0, true);
|
|
2638
2975
|
const endpoint = (_nullishCoalesce(options.endpoint, () => ( "https://otlp.autter.dev"))).replace(/\/$/, "");
|
|
2639
2976
|
const environment = _nullishCoalesce(_nullishCoalesce(options.environment, () => ( process.env.NODE_ENV)), () => ( "production"));
|
|
2640
|
-
const redact =
|
|
2977
|
+
const redact = _chunkSTOXJZ7Zcjs.makeRedactor.call(void 0, _nullishCoalesce(options.redactAttributes, () => ( true)));
|
|
2641
2978
|
const mode = _nullishCoalesce(options.exceptions, () => ( "auto"));
|
|
2642
|
-
|
|
2643
|
-
const errorFilter =
|
|
2979
|
+
_chunkS6WJ5YLPcjs.debugLog.call(void 0, `initialising logger-only service=${options.service} endpoint=${endpoint}`);
|
|
2980
|
+
const errorFilter = _chunkSTOXJZ7Zcjs.createErrorFilter.call(void 0, { ignoreErrors: options.ignoreErrors, sampleRate: options.sampleRate });
|
|
2644
2981
|
function captureException2(error, attributes) {
|
|
2645
|
-
|
|
2646
|
-
const isErrValue =
|
|
2982
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
2983
|
+
const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
|
|
2647
2984
|
const reported = errorFilter({
|
|
2648
2985
|
type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
|
|
2649
2986
|
message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
|
|
2650
|
-
crash: _optionalChain([attributes, 'optionalAccess',
|
|
2987
|
+
crash: _optionalChain([attributes, 'optionalAccess', _164 => _164["autter.unhandled"]]) === true || _optionalChain([attributes, 'optionalAccess', _165 => _165["autter.unhandled_rejection"]]) === true
|
|
2651
2988
|
});
|
|
2652
2989
|
if (!reported) return;
|
|
2653
|
-
const split =
|
|
2654
|
-
const fingerprint =
|
|
2990
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
2991
|
+
const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
|
|
2655
2992
|
const redacted = redact(split.attributes);
|
|
2656
2993
|
const span = _api.trace.getActiveSpan();
|
|
2657
|
-
if (mode === "auto" && _optionalChain([span, 'optionalAccess',
|
|
2658
|
-
|
|
2659
|
-
|
|
2994
|
+
if (mode === "auto" && _optionalChain([span, 'optionalAccess', _166 => _166.isRecording, 'call', _167 => _167()])) {
|
|
2995
|
+
_chunkSTOXJZ7Zcjs.noteOperationError.call(void 0, error);
|
|
2996
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
|
|
2660
2997
|
span.setAttributes({ "autter.severity": "error", ...redacted, ...structuredErrorAttributes(error) });
|
|
2661
|
-
const declared = { ...
|
|
2662
|
-
if (
|
|
2998
|
+
const declared = { ..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error), ...fingerprint };
|
|
2999
|
+
if (_chunkSTOXJZ7Zcjs.isError.call(void 0, error)) {
|
|
2663
3000
|
span.addEvent("exception", {
|
|
2664
3001
|
"exception.type": error.name,
|
|
2665
3002
|
"exception.message": error.message,
|
|
@@ -2675,51 +3012,53 @@ function initAutterLogging(options) {
|
|
|
2675
3012
|
}
|
|
2676
3013
|
span.setStatus({
|
|
2677
3014
|
code: _api.SpanStatusCode.ERROR,
|
|
2678
|
-
message:
|
|
3015
|
+
message: _chunkSTOXJZ7Zcjs.isError.call(void 0, error) ? error.message : String(error)
|
|
2679
3016
|
});
|
|
2680
3017
|
return;
|
|
2681
3018
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
3019
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint });
|
|
3020
|
+
_chunkSTOXJZ7Zcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint });
|
|
2684
3021
|
}
|
|
2685
3022
|
function captureHandled(error, attributes, severity) {
|
|
2686
|
-
|
|
2687
|
-
const isErrValue =
|
|
3023
|
+
_chunkSTOXJZ7Zcjs.markCaptured.call(void 0, error);
|
|
3024
|
+
const isErrValue = _chunkSTOXJZ7Zcjs.isError.call(void 0, error);
|
|
2688
3025
|
if (!errorFilter({
|
|
2689
3026
|
type: isErrValue ? String(_nullishCoalesce(error.name, () => ( ""))) : "Error",
|
|
2690
3027
|
message: isErrValue ? String(_nullishCoalesce(error.message, () => ( ""))) : String(error),
|
|
2691
3028
|
severity
|
|
2692
3029
|
})) return;
|
|
2693
|
-
const split =
|
|
2694
|
-
const fingerprint =
|
|
3030
|
+
const split = _chunkSTOXJZ7Zcjs.splitFingerprint.call(void 0, attributes);
|
|
3031
|
+
const fingerprint = _chunkSTOXJZ7Zcjs.fingerprintEventAttributes.call(void 0, split.fingerprint, redact.text);
|
|
2695
3032
|
const redacted = redact(split.attributes);
|
|
2696
|
-
|
|
3033
|
+
_chunkSTOXJZ7Zcjs.notifyException.call(void 0, error, { ...redacted, ...fingerprint, "autter.severity": severity });
|
|
2697
3034
|
const span = _api.trace.getActiveSpan();
|
|
2698
|
-
if (mode === "auto" && _optionalChain([span, 'optionalAccess',
|
|
3035
|
+
if (mode === "auto" && _optionalChain([span, 'optionalAccess', _168 => _168.isRecording, 'call', _169 => _169()])) {
|
|
2699
3036
|
span.addEvent("exception", {
|
|
2700
3037
|
...redacted,
|
|
2701
3038
|
"exception.type": isErrValue ? error.name : "Error",
|
|
2702
3039
|
"exception.message": redact.text(isErrValue ? error.message : String(error)),
|
|
2703
3040
|
...isErrValue && error.stack ? { "exception.stacktrace": redact.text(error.stack) } : {},
|
|
2704
3041
|
"autter.severity": severity,
|
|
2705
|
-
...
|
|
3042
|
+
..._chunkSTOXJZ7Zcjs.errorAttributes.call(void 0, error),
|
|
2706
3043
|
...fingerprint
|
|
2707
3044
|
});
|
|
2708
3045
|
return;
|
|
2709
3046
|
}
|
|
2710
|
-
|
|
3047
|
+
_chunkSTOXJZ7Zcjs.captureExceptionAsLog.call(void 0, error, { ...redacted, ...fingerprint }, severity);
|
|
2711
3048
|
}
|
|
2712
3049
|
const captured = /* @__PURE__ */ new WeakSet();
|
|
2713
|
-
|
|
3050
|
+
_chunkSTOXJZ7Zcjs.configureRuntimeLogger.call(void 0, {
|
|
2714
3051
|
endpoint,
|
|
2715
|
-
|
|
3052
|
+
// Normalised ("undefined"/empty is no key), no env fallback: without
|
|
3053
|
+
// an apiKey this mode logs locally only, by design.
|
|
3054
|
+
apiKey: _nullishCoalesce(_chunkS6WJ5YLPcjs.resolveIngestKey.call(void 0, options.apiKey, {}), () => ( "")),
|
|
2716
3055
|
service: options.service,
|
|
2717
3056
|
environment,
|
|
2718
3057
|
...options.release ? { release: options.release } : {},
|
|
2719
3058
|
...options.logging ? { options: options.logging } : {},
|
|
2720
3059
|
redact,
|
|
2721
3060
|
reportOutcome: (name, message, attributes) => {
|
|
2722
|
-
|
|
3061
|
+
_chunkSTOXJZ7Zcjs.runtimeLogger.error(message, {
|
|
2723
3062
|
...attributes,
|
|
2724
3063
|
"autter.outcome.name": name.slice(0, 200),
|
|
2725
3064
|
"autter.outcome.message": message.slice(0, 1e3)
|
|
@@ -2734,7 +3073,7 @@ function initAutterLogging(options) {
|
|
|
2734
3073
|
}
|
|
2735
3074
|
});
|
|
2736
3075
|
setLoggerOnlyCapture(captureException2, captureHandled);
|
|
2737
|
-
|
|
3076
|
+
_chunkSTOXJZ7Zcjs.startLoggedErrorCapture.call(void 0, options.captureLoggedErrors);
|
|
2738
3077
|
const onCrash = (error) => {
|
|
2739
3078
|
if (recordedAsRejection(error)) return;
|
|
2740
3079
|
captureException2(error, { "autter.unhandled": true });
|
|
@@ -2747,22 +3086,22 @@ function initAutterLogging(options) {
|
|
|
2747
3086
|
(reason) => captureException2(reason, { "autter.unhandled_rejection": true })
|
|
2748
3087
|
);
|
|
2749
3088
|
}
|
|
2750
|
-
|
|
2751
|
-
let autoFlushHandle = options.autoFlush === false ? null :
|
|
3089
|
+
_chunkS6WJ5YLPcjs.registerFlushTarget.call(void 0, "logging", { forceFlush: () => _chunkSTOXJZ7Zcjs.flushRuntimeLogs.call(void 0, ) });
|
|
3090
|
+
let autoFlushHandle = options.autoFlush === false ? null : _chunkS6WJ5YLPcjs.installAutterAutoFlush.call(void 0, );
|
|
2752
3091
|
const handle = {
|
|
2753
3092
|
captureException: captureException2,
|
|
2754
|
-
flush:
|
|
3093
|
+
flush: _chunkSTOXJZ7Zcjs.flushRuntimeLogs,
|
|
2755
3094
|
shutdown: async () => {
|
|
2756
|
-
if (L.active === handle)
|
|
3095
|
+
if (L.active === handle) _chunkSTOXJZ7Zcjs.stopLoggedErrorCapture.call(void 0, );
|
|
2757
3096
|
process.off("uncaughtExceptionMonitor", onCrash);
|
|
2758
|
-
_optionalChain([uninstallRejections, 'optionalCall',
|
|
3097
|
+
_optionalChain([uninstallRejections, 'optionalCall', _170 => _170()]);
|
|
2759
3098
|
uninstallRejections = null;
|
|
2760
3099
|
setLoggerOnlyCapture(null);
|
|
2761
|
-
_optionalChain([autoFlushHandle, 'optionalAccess',
|
|
3100
|
+
_optionalChain([autoFlushHandle, 'optionalAccess', _171 => _171.dispose, 'call', _172 => _172()]);
|
|
2762
3101
|
autoFlushHandle = null;
|
|
2763
|
-
|
|
3102
|
+
_chunkS6WJ5YLPcjs.unregisterFlushTargets.call(void 0, );
|
|
2764
3103
|
if (L.active === handle) L.active = null;
|
|
2765
|
-
await
|
|
3104
|
+
await _chunkSTOXJZ7Zcjs.shutdownRuntimeLogger.call(void 0, );
|
|
2766
3105
|
}
|
|
2767
3106
|
};
|
|
2768
3107
|
L.active = handle;
|
|
@@ -2771,7 +3110,7 @@ function initAutterLogging(options) {
|
|
|
2771
3110
|
|
|
2772
3111
|
// src/enrichers.ts
|
|
2773
3112
|
function headerOf(req, name) {
|
|
2774
|
-
const headers = _optionalChain([req, 'optionalAccess',
|
|
3113
|
+
const headers = _optionalChain([req, 'optionalAccess', _173 => _173.headers]);
|
|
2775
3114
|
if (!headers) return void 0;
|
|
2776
3115
|
if (typeof headers.get === "function") {
|
|
2777
3116
|
return _nullishCoalesce(headers.get(name), () => ( void 0));
|
|
@@ -2784,7 +3123,7 @@ function enrichUserAgent() {
|
|
|
2784
3123
|
return (event, { req }) => {
|
|
2785
3124
|
const ua = headerOf(req, "user-agent");
|
|
2786
3125
|
if (!ua) return;
|
|
2787
|
-
const info =
|
|
3126
|
+
const info = _chunkSTOXJZ7Zcjs.parseUserAgent.call(void 0, ua);
|
|
2788
3127
|
if (info.browser) event.attributes["user_agent.browser"] = info.browser;
|
|
2789
3128
|
if (info.os) event.attributes["user_agent.os"] = info.os;
|
|
2790
3129
|
event.attributes["user_agent.device"] = info.device;
|
|
@@ -2796,7 +3135,7 @@ function enrichRequestSize() {
|
|
|
2796
3135
|
const request = Number(headerOf(req, "content-length"));
|
|
2797
3136
|
if (Number.isFinite(request) && request >= 0)
|
|
2798
3137
|
event.attributes["http.request.body.size"] = request;
|
|
2799
|
-
const raw = _optionalChain([res, 'optionalAccess',
|
|
3138
|
+
const raw = _optionalChain([res, 'optionalAccess', _174 => _174.getHeader, 'optionalCall', _175 => _175(
|
|
2800
3139
|
"content-length"
|
|
2801
3140
|
)]);
|
|
2802
3141
|
const response = Number(raw);
|
|
@@ -2814,7 +3153,7 @@ var COUNTRY_HEADERS = [
|
|
|
2814
3153
|
function enrichEdgeGeo() {
|
|
2815
3154
|
return (event, { req }) => {
|
|
2816
3155
|
for (const name of COUNTRY_HEADERS) {
|
|
2817
|
-
const value = _optionalChain([headerOf, 'call',
|
|
3156
|
+
const value = _optionalChain([headerOf, 'call', _176 => _176(req, name), 'optionalAccess', _177 => _177.trim, 'call', _178 => _178(), 'access', _179 => _179.toUpperCase, 'call', _180 => _180()]);
|
|
2818
3157
|
if (value && /^[A-Z]{2}$/.test(value) && value !== "XX" && value !== "T1") {
|
|
2819
3158
|
event.attributes["geo.country.iso_code"] = value;
|
|
2820
3159
|
return;
|
|
@@ -2848,9 +3187,9 @@ var COMMIT_VARS = [
|
|
|
2848
3187
|
"SOURCE_VERSION"
|
|
2849
3188
|
];
|
|
2850
3189
|
function enrichDeployment(env = process.env) {
|
|
2851
|
-
const pick = (names) => names.map((name) => _optionalChain([env, 'access',
|
|
2852
|
-
const region = _optionalChain([pick, 'call',
|
|
2853
|
-
const commit = _optionalChain([pick, 'call',
|
|
3190
|
+
const pick = (names) => names.map((name) => _optionalChain([env, 'access', _181 => _181[name], 'optionalAccess', _182 => _182.trim, 'call', _183 => _183()])).find((value) => value);
|
|
3191
|
+
const region = _optionalChain([pick, 'call', _184 => _184(REGION_VARS), 'optionalAccess', _185 => _185.slice, 'call', _186 => _186(0, 64)]);
|
|
3192
|
+
const commit = _optionalChain([pick, 'call', _187 => _187(COMMIT_VARS), 'optionalAccess', _188 => _188.slice, 'call', _189 => _189(0, 64)]);
|
|
2854
3193
|
return (event) => {
|
|
2855
3194
|
if (region) event.attributes["deployment.region"] = region;
|
|
2856
3195
|
if (commit) event.attributes["deployment.commit"] = commit;
|
|
@@ -2911,4 +3250,6 @@ function enrichDeployment(env = process.env) {
|
|
|
2911
3250
|
|
|
2912
3251
|
|
|
2913
3252
|
|
|
2914
|
-
|
|
3253
|
+
|
|
3254
|
+
|
|
3255
|
+
exports.CODE_PATTERN = _chunkSTOXJZ7Zcjs.CODE_PATTERN; exports.COMPAT_MANIFEST = _chunkS6WJ5YLPcjs.COMPAT_MANIFEST; exports.INGESTER_VERSION_HEADER = _chunkS6WJ5YLPcjs.INGESTER_VERSION_HEADER; exports.RuntimeError = _chunkSTOXJZ7Zcjs.RuntimeError; exports.SDK_IDENTITY = _chunkS6WJ5YLPcjs.SDK_IDENTITY; exports.addBreadcrumb = _chunkSTOXJZ7Zcjs.addBreadcrumb; exports.autterErrorHandler = autterErrorHandler; exports.autterErrorResponse = autterErrorResponse; exports.autterFastify = autterFastify; exports.autterFastifyErrors = autterFastifyErrors; exports.autterKoa = autterKoa; exports.autterRequests = autterRequests; exports.captureException = captureException; exports.captureMessage = captureMessage; exports.captureRequestError = captureRequestError; exports.checkBrowserPayload = checkBrowserPayload; exports.consoleSink = _chunkSTOXJZ7Zcjs.consoleSink; exports.createBrowserRelayFetchHandler = createBrowserRelayFetchHandler; exports.createBrowserRelayHandler = createBrowserRelayHandler; exports.createRuntimeLogger = _chunkSTOXJZ7Zcjs.createRuntimeLogger; exports.defineRuntimeErrors = _chunkSTOXJZ7Zcjs.defineRuntimeErrors; exports.emitLlmSelftestTrace = emitLlmSelftestTrace; exports.enrichDeployment = enrichDeployment; exports.enrichEdgeGeo = enrichEdgeGeo; exports.enrichRequestSize = enrichRequestSize; exports.enrichUserAgent = enrichUserAgent; exports.errorAttributes = _chunkSTOXJZ7Zcjs.errorAttributes; exports.evaluateCompat = _chunkS6WJ5YLPcjs.evaluateCompat; exports.fetchIngesterCompat = _chunkS6WJ5YLPcjs.fetchIngesterCompat; exports.fileSink = _chunkSTOXJZ7Zcjs.fileSink; exports.flushRuntimeLogs = _chunkSTOXJZ7Zcjs.flushRuntimeLogs; exports.initAutterLogging = initAutterLogging; exports.initAutterServer = initAutterServer; exports.installAutterAutoFlush = _chunkS6WJ5YLPcjs.installAutterAutoFlush; exports.instrumentLlmClient = instrumentLlmClient; exports.isRuntimeErrorLike = _chunkSTOXJZ7Zcjs.isRuntimeErrorLike; exports.makeSafeCapture = makeSafeCapture; exports.otlpSink = _chunkSTOXJZ7Zcjs.otlpSink; exports.redactAttributes = _chunkSTOXJZ7Zcjs.redactAttributes; exports.redactText = _chunkSTOXJZ7Zcjs.redactText; exports.reportOutcome = reportOutcome; exports.runDoctor = _chunkHBH64LWQcjs.runDoctor; exports.runInBackground = _chunkSTOXJZ7Zcjs.runInBackground; exports.runVerify = _chunkHBH64LWQcjs.runVerify; exports.runtimeContext = _chunkSTOXJZ7Zcjs.runtimeContext; exports.runtimeLogStats = _chunkSTOXJZ7Zcjs.runtimeLogStats; exports.runtimeLogger = _chunkSTOXJZ7Zcjs.runtimeLogger; exports.sanitizeBrowserPayload = sanitizeBrowserPayload; exports.startCaughtExceptionSampler = startCaughtExceptionSampler; exports.toClientError = _chunkSTOXJZ7Zcjs.toClientError; exports.trackLlmCall = trackLlmCall; exports.unhandledRejectionsMode = unhandledRejectionsMode; exports.withLlmCall = withLlmCall; exports.withProcessSpan = withProcessSpan; exports.withRuntimeOperation = _chunkSTOXJZ7Zcjs.withRuntimeOperation; exports.withRuntimeRequest = withRuntimeRequest;
|