hobots 1.3.6 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +61 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +51 -9
- package/dist/index.js.map +1 -1
- package/dist/manager/protocol.cjs.map +1 -1
- package/dist/manager/protocol.d.cts +2 -2
- package/dist/manager/protocol.d.ts +2 -2
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +4 -2
- package/dist/protocol.d.ts +4 -2
- package/docs/concepts.md +1 -0
- package/docs/manager.md +1 -0
- package/docs/monitor.md +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -111,7 +121,7 @@ function parseStacktrace(stack) {
|
|
|
111
121
|
|
|
112
122
|
// src/utils.ts
|
|
113
123
|
var SDK_NAME = "hobots";
|
|
114
|
-
var SDK_VERSION = true ? "1.
|
|
124
|
+
var SDK_VERSION = true ? "1.5.0" : "0.0.0-dev";
|
|
115
125
|
function isNode() {
|
|
116
126
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
117
127
|
}
|
|
@@ -151,7 +161,8 @@ var ANSI = {
|
|
|
151
161
|
gray: "\x1B[90m",
|
|
152
162
|
cyan: "\x1B[36m",
|
|
153
163
|
yellow: "\x1B[33m",
|
|
154
|
-
red: "\x1B[31m"
|
|
164
|
+
red: "\x1B[31m",
|
|
165
|
+
green: "\x1B[32m"
|
|
155
166
|
};
|
|
156
167
|
function colorEnabled() {
|
|
157
168
|
if (!isNode()) return false;
|
|
@@ -591,6 +602,15 @@ var Scope = class _Scope {
|
|
|
591
602
|
function spanId() {
|
|
592
603
|
return uuid4().slice(0, 16);
|
|
593
604
|
}
|
|
605
|
+
function printSpanLog(kind, phase, label, startTs, endTs) {
|
|
606
|
+
const durationMs = startTs && endTs ? new Date(endTs).getTime() - new Date(startTs).getTime() : void 0;
|
|
607
|
+
const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? "green" : "cyan");
|
|
608
|
+
const suffix = durationMs != null ? ` (${durationMs}ms)` : "";
|
|
609
|
+
console.log(`${tag} ${label}${suffix}`);
|
|
610
|
+
}
|
|
611
|
+
function spanLabel(op, description) {
|
|
612
|
+
return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
|
|
613
|
+
}
|
|
594
614
|
var Span = class {
|
|
595
615
|
constructor(transaction, parentSpanId, op, description) {
|
|
596
616
|
this.transaction = transaction;
|
|
@@ -616,7 +636,9 @@ var Span = class {
|
|
|
616
636
|
return this.transaction.createSpan(this.spanId, op, description);
|
|
617
637
|
}
|
|
618
638
|
finish() {
|
|
619
|
-
if (
|
|
639
|
+
if (this.endTimestamp) return;
|
|
640
|
+
this.endTimestamp = nowISO();
|
|
641
|
+
printSpanLog("span", "finish", spanLabel(this.op, this.description), this.startTimestamp, this.endTimestamp);
|
|
620
642
|
}
|
|
621
643
|
toJSON() {
|
|
622
644
|
return {
|
|
@@ -638,6 +660,7 @@ var Transaction = class {
|
|
|
638
660
|
this.op = op;
|
|
639
661
|
this.sampled = sampled;
|
|
640
662
|
this.runId = runId;
|
|
663
|
+
printSpanLog("transaction", "start", op ? `${name} (${op})` : name);
|
|
641
664
|
}
|
|
642
665
|
eventId = uuid4();
|
|
643
666
|
spanId = spanId();
|
|
@@ -649,6 +672,7 @@ var Transaction = class {
|
|
|
649
672
|
createSpan(parentSpanId, op, description) {
|
|
650
673
|
const span = new Span(this, parentSpanId, op, description);
|
|
651
674
|
this.spans.push(span);
|
|
675
|
+
printSpanLog("span", "start", spanLabel(op, description));
|
|
652
676
|
return span;
|
|
653
677
|
}
|
|
654
678
|
/** Span direto da transaction. */
|
|
@@ -671,6 +695,14 @@ var Transaction = class {
|
|
|
671
695
|
if (this.finished) return;
|
|
672
696
|
this.finished = true;
|
|
673
697
|
for (const span of this.spans) span.finish();
|
|
698
|
+
const endTimestamp = nowISO();
|
|
699
|
+
printSpanLog(
|
|
700
|
+
"transaction",
|
|
701
|
+
"finish",
|
|
702
|
+
this.op ? `${this.name} (${this.op})` : this.name,
|
|
703
|
+
this.startTimestamp,
|
|
704
|
+
endTimestamp
|
|
705
|
+
);
|
|
674
706
|
if (!this.sampled || !this.client) return;
|
|
675
707
|
const payload = {
|
|
676
708
|
event_id: this.eventId,
|
|
@@ -678,7 +710,7 @@ var Transaction = class {
|
|
|
678
710
|
op: this.op,
|
|
679
711
|
status: this.status,
|
|
680
712
|
start_timestamp: this.startTimestamp,
|
|
681
|
-
timestamp:
|
|
713
|
+
timestamp: endTimestamp,
|
|
682
714
|
spans: this.spans.map((span) => span.toJSON()),
|
|
683
715
|
tags: Object.keys(this.tags).length > 0 ? this.tags : void 0,
|
|
684
716
|
run_id: this.runId
|
|
@@ -820,11 +852,12 @@ var LOG_LEVEL_COLOR = {
|
|
|
820
852
|
debug: "gray",
|
|
821
853
|
info: "cyan",
|
|
822
854
|
warning: "yellow",
|
|
823
|
-
error: "red"
|
|
855
|
+
error: "red",
|
|
856
|
+
success: "green"
|
|
824
857
|
};
|
|
825
858
|
function printRunLog(task, level, message) {
|
|
826
859
|
const line = colorize(`[hobots:${task}] ${level.toUpperCase()}`, LOG_LEVEL_COLOR[level]);
|
|
827
|
-
const method = level === "warning" ? "warn" : level;
|
|
860
|
+
const method = level === "warning" ? "warn" : level === "success" ? "info" : level;
|
|
828
861
|
console[method](line, message);
|
|
829
862
|
}
|
|
830
863
|
function runCanceledError() {
|
|
@@ -869,7 +902,8 @@ var RunReporter = class {
|
|
|
869
902
|
debug: (message) => this.log("debug", message),
|
|
870
903
|
info: (message) => this.log("info", message),
|
|
871
904
|
warn: (message) => this.log("warning", message),
|
|
872
|
-
error: (message) => this.log("error", message)
|
|
905
|
+
error: (message) => this.log("error", message),
|
|
906
|
+
success: (message) => this.log("success", message)
|
|
873
907
|
};
|
|
874
908
|
const signal = this.abortController.signal;
|
|
875
909
|
this.context = {
|
|
@@ -1031,6 +1065,24 @@ var RunReporter = class {
|
|
|
1031
1065
|
}
|
|
1032
1066
|
};
|
|
1033
1067
|
|
|
1068
|
+
// src/manager/run-context-store.ts
|
|
1069
|
+
var storage;
|
|
1070
|
+
var initPromise;
|
|
1071
|
+
async function ensureStorage() {
|
|
1072
|
+
if (storage || !isNode()) return;
|
|
1073
|
+
initPromise ??= import("async_hooks").then(({ AsyncLocalStorage: ALS }) => {
|
|
1074
|
+
storage = new ALS();
|
|
1075
|
+
});
|
|
1076
|
+
await initPromise;
|
|
1077
|
+
}
|
|
1078
|
+
async function runWithRunId(runId, fn) {
|
|
1079
|
+
await ensureStorage();
|
|
1080
|
+
return storage ? storage.run({ runId }, fn) : fn();
|
|
1081
|
+
}
|
|
1082
|
+
function currentRunId() {
|
|
1083
|
+
return storage?.getStore()?.runId;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1034
1086
|
// src/manager/shutdown.ts
|
|
1035
1087
|
var WATCHED_SIGNALS = ["SIGINT", "SIGTERM"];
|
|
1036
1088
|
function installShutdownHandlers(agent2) {
|
|
@@ -1265,7 +1317,7 @@ var ManagerAgent = class {
|
|
|
1265
1317
|
}
|
|
1266
1318
|
this.logger.debug(`executando run ${run.id} (${run.task})`);
|
|
1267
1319
|
try {
|
|
1268
|
-
await this.invokeWithTimeout(handler, run, reporter);
|
|
1320
|
+
await runWithRunId(run.id, () => this.invokeWithTimeout(handler, run, reporter));
|
|
1269
1321
|
reporter.reportSuccess();
|
|
1270
1322
|
tx.setStatus("ok");
|
|
1271
1323
|
this.logger.debug(`run ${run.id} conclu\xEDda`);
|
|
@@ -1390,7 +1442,7 @@ function withScope(callback) {
|
|
|
1390
1442
|
function startTransaction(name, op) {
|
|
1391
1443
|
const rate = client?.options.tracesSampleRate ?? 1;
|
|
1392
1444
|
const sampled = rate >= 1 || Math.random() < rate;
|
|
1393
|
-
return new Transaction(client, name, op, sampled);
|
|
1445
|
+
return new Transaction(client, name, op, sampled, currentRunId());
|
|
1394
1446
|
}
|
|
1395
1447
|
function checkIn(options) {
|
|
1396
1448
|
return client ? sendCheckIn(client, options) : void 0;
|