hobots 1.7.4 → 1.7.6
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 +12 -12
- package/dist/index.cjs +61 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -19
- package/dist/index.d.ts +19 -19
- package/dist/index.js +61 -29
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +9 -9
- package/dist/protocol.d.ts +9 -9
- package/docs/README.md +3 -3
- package/docs/api-reference.md +5 -5
- package/docs/concepts.md +19 -19
- package/docs/monitor.md +10 -10
- package/docs/tasks.md +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SDK JavaScript/TypeScript da **Hobots** para instrumentar funcionários digitais (RPAs) e integrações.
|
|
4
4
|
|
|
5
|
-
- **Telemetria** — o que o programa **emite** sozinho: erros com stack trace (módulo **Issues** do app), performance (transactions/
|
|
5
|
+
- **Telemetria** — o que o programa **emite** sozinho: erros com stack trace (módulo **Issues** do app), performance (transactions/etapas) e heartbeats de uptime (módulo **Agentes**), check-ins de cron (módulo **Monitores**).
|
|
6
6
|
- **Tasks** — execução **sob demanda**: o agente faz polling no app da Hobots, executa handlers registrados e reporta status e logs (módulo **Solicitações**).
|
|
7
7
|
|
|
8
8
|
**Um único import e um único `init()`** cobrem as duas capabilities. Cliente HTTP puro, **sem dependências de runtime**. Requer **Node 18+** (usa o `fetch` global); a telemetria também roda no browser para captura de erros.
|
|
@@ -30,7 +30,7 @@ O SDK expõe **duas capabilities** autenticadas pelo **mesmo Client Secret do ag
|
|
|
30
30
|
|
|
31
31
|
| Capability | Como habilita | Para quê | Ciclo de vida |
|
|
32
32
|
| --- | --- | --- | --- |
|
|
33
|
-
| **Telemetria** | sempre ativa no `init()` | O que o programa emite sozinho: erros, transactions/
|
|
33
|
+
| **Telemetria** | sempre ativa no `init()` | O que o programa emite sozinho: erros, transactions/etapas, crons, heartbeat. | Timers `unref`'d — **não** segura o processo. Chame `close()` no fim. |
|
|
34
34
|
| **Tasks** | `tasks: true` (ou opções) no `init()` | Execução remota sob demanda via polling. | `start()` **segura o processo vivo** até `stop()`/`close()`. |
|
|
35
35
|
|
|
36
36
|
Você usa **uma, outra ou as duas**:
|
|
@@ -158,16 +158,16 @@ Hobots.withScope((scope) => {
|
|
|
158
158
|
});
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
### Performance: transactions e
|
|
161
|
+
### Performance: transactions e etapas
|
|
162
162
|
|
|
163
163
|
```js
|
|
164
164
|
const tx = Hobots.startTransaction('processar-lote', 'rpa.job');
|
|
165
165
|
|
|
166
|
-
const
|
|
166
|
+
const step = tx.startChild('http.client', 'GET /api/notas');
|
|
167
167
|
await api.buscarNotas();
|
|
168
|
-
|
|
168
|
+
step.setData('notas', 42).finish();
|
|
169
169
|
|
|
170
|
-
const filho =
|
|
170
|
+
const filho = step.startChild('db.query', 'INSERT INTO notas'); // etapas aninham
|
|
171
171
|
await gravar();
|
|
172
172
|
filho.finish();
|
|
173
173
|
|
|
@@ -175,11 +175,11 @@ tx.setStatus('ok'); // ou 'error'
|
|
|
175
175
|
tx.finish(); // só aqui a transaction é enviada (respeitando tracesSampleRate)
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
- `startChild(op?, description?)` existe em `Transaction` **e** `
|
|
179
|
-
- Métodos encadeáveis: `setStatus`, `setData` (
|
|
180
|
-
- `finish()` na transaction fecha
|
|
178
|
+
- `startChild(op?, description?)` existe em `Transaction` **e** `Step` (aninhamento arbitrário).
|
|
179
|
+
- Métodos encadeáveis: `setStatus`, `setData` (step), `setTag`/`setName` (transaction).
|
|
180
|
+
- `finish()` na transaction fecha as etapas abertas e envia o payload; nada é enviado se ela não foi amostrada. A amostragem é decidida no `startTransaction()`.
|
|
181
181
|
|
|
182
|
-
Dentro de um handler de task, `startTransaction()` **retorna a transaction da própria run** (`ctx.tx`) em vez de criar uma segunda — cada execução tem exatamente **uma** transaction. Conceitos: [Transaction](./docs/concepts.md#transaction) · [
|
|
182
|
+
Dentro de um handler de task, `startTransaction()` **retorna a transaction da própria run** (`ctx.tx`) em vez de criar uma segunda — cada execução tem exatamente **uma** transaction. Conceitos: [Transaction](./docs/concepts.md#transaction) · [Step](./docs/concepts.md#step).
|
|
183
183
|
|
|
184
184
|
### Crons (check-ins)
|
|
185
185
|
|
|
@@ -364,11 +364,11 @@ Empacotado em **ESM e CommonJS** com **definições de tipos** (`.d.ts`) para to
|
|
|
364
364
|
|
|
365
365
|
Guias detalhados acompanham o pacote em [`docs/`](./docs/README.md).
|
|
366
366
|
|
|
367
|
-
Novo no vocabulário de observabilidade (transaction,
|
|
367
|
+
Novo no vocabulário de observabilidade (transaction, step, breadcrumb, tag, context, extra, flush, close)? Comece por [Conceitos](./docs/concepts.md) — as outras páginas assumem esses termos.
|
|
368
368
|
|
|
369
369
|
- [Conceitos](./docs/concepts.md) — o que cada coisa é, por que existe e quando escolher uma em vez da outra.
|
|
370
370
|
- [Getting started](./docs/getting-started.md) — instalação, Client Secret, primeiro `init`, telemetria e tasks.
|
|
371
|
-
- [Telemetria](./docs/monitor.md) — erros, breadcrumbs, escopo, transactions/
|
|
371
|
+
- [Telemetria](./docs/monitor.md) — erros, breadcrumbs, escopo, transactions/etapas, crons, heartbeat.
|
|
372
372
|
- [Tasks](./docs/tasks.md) — handlers, `RunContext`, cancelamento, concorrência, idempotência.
|
|
373
373
|
- [Referência de API](./docs/api-reference.md) — todas as funções e tabelas de opções com defaults.
|
|
374
374
|
- [Protocolo & transporte](./docs/protocol.md) — o Client Secret, endpoints, envelope, retries.
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
Client: () => Client,
|
|
34
34
|
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
35
35
|
Scope: () => Scope,
|
|
36
|
-
|
|
36
|
+
Step: () => Step,
|
|
37
37
|
Transaction: () => Transaction,
|
|
38
38
|
addBreadcrumb: () => addBreadcrumb,
|
|
39
39
|
captureException: () => captureException,
|
|
@@ -163,7 +163,7 @@ function scrubSecrets(text) {
|
|
|
163
163
|
|
|
164
164
|
// src/utils.ts
|
|
165
165
|
var SDK_NAME = "hobots";
|
|
166
|
-
var SDK_VERSION = true ? "1.7.
|
|
166
|
+
var SDK_VERSION = true ? "1.7.6" : "0.0.0-dev";
|
|
167
167
|
function isNode() {
|
|
168
168
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
169
169
|
}
|
|
@@ -719,20 +719,44 @@ var Scope = class _Scope {
|
|
|
719
719
|
};
|
|
720
720
|
|
|
721
721
|
// src/transaction.ts
|
|
722
|
-
function
|
|
722
|
+
function stepId() {
|
|
723
723
|
return uuid4().slice(0, 16);
|
|
724
724
|
}
|
|
725
|
-
function
|
|
725
|
+
function stepLabel(op, description) {
|
|
726
726
|
return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
|
|
727
727
|
}
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
function levelForStatus(status) {
|
|
729
|
+
switch (status) {
|
|
730
|
+
case "warning":
|
|
731
|
+
return "warning";
|
|
732
|
+
case "error":
|
|
733
|
+
return "error";
|
|
734
|
+
case "cancelled":
|
|
735
|
+
return "warning";
|
|
736
|
+
default:
|
|
737
|
+
return "success";
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
function colorForStatus(status) {
|
|
741
|
+
switch (status) {
|
|
742
|
+
case "warning":
|
|
743
|
+
return "yellow";
|
|
744
|
+
case "error":
|
|
745
|
+
return "red";
|
|
746
|
+
case "cancelled":
|
|
747
|
+
return "gray";
|
|
748
|
+
default:
|
|
749
|
+
return "green";
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
var Step = class {
|
|
753
|
+
constructor(transaction, parentStepId, op, description) {
|
|
730
754
|
this.transaction = transaction;
|
|
731
|
-
this.
|
|
755
|
+
this.parentStepId = parentStepId;
|
|
732
756
|
this.op = op;
|
|
733
757
|
this.description = description;
|
|
734
758
|
}
|
|
735
|
-
|
|
759
|
+
stepId = stepId();
|
|
736
760
|
startTimestamp = nowISO();
|
|
737
761
|
status = "ok";
|
|
738
762
|
endTimestamp;
|
|
@@ -745,19 +769,26 @@ var Span = class {
|
|
|
745
769
|
this.data = { ...this.data, [key]: value };
|
|
746
770
|
return this;
|
|
747
771
|
}
|
|
748
|
-
/**
|
|
772
|
+
/** Step aninhada (filha desta step). */
|
|
749
773
|
startChild(op, description) {
|
|
750
|
-
return this.transaction.
|
|
774
|
+
return this.transaction.createStep(this.stepId, op, description);
|
|
751
775
|
}
|
|
752
776
|
finish() {
|
|
753
777
|
if (this.endTimestamp) return;
|
|
754
778
|
this.endTimestamp = nowISO();
|
|
755
|
-
this.transaction.emit(
|
|
779
|
+
this.transaction.emit(
|
|
780
|
+
"step",
|
|
781
|
+
"finish",
|
|
782
|
+
stepLabel(this.op, this.description),
|
|
783
|
+
this.startTimestamp,
|
|
784
|
+
this.endTimestamp,
|
|
785
|
+
this.status
|
|
786
|
+
);
|
|
756
787
|
}
|
|
757
788
|
toJSON() {
|
|
758
789
|
return {
|
|
759
|
-
|
|
760
|
-
|
|
790
|
+
step_id: this.stepId,
|
|
791
|
+
parent_step_id: this.parentStepId,
|
|
761
792
|
op: this.op,
|
|
762
793
|
description: this.description,
|
|
763
794
|
status: this.status,
|
|
@@ -777,10 +808,10 @@ var Transaction = class {
|
|
|
777
808
|
this.emit("transaction", "start", op ? `${name} (${op})` : name);
|
|
778
809
|
}
|
|
779
810
|
eventId = uuid4();
|
|
780
|
-
|
|
811
|
+
stepId = stepId();
|
|
781
812
|
startTimestamp = nowISO();
|
|
782
813
|
status = "ok";
|
|
783
|
-
|
|
814
|
+
steps = [];
|
|
784
815
|
tags = {};
|
|
785
816
|
finished = false;
|
|
786
817
|
lifecycleSink;
|
|
@@ -788,16 +819,16 @@ var Transaction = class {
|
|
|
788
819
|
// antes do RunReporter conectar) — replay no setLifecycleSink
|
|
789
820
|
lifecycleBacklog = [];
|
|
790
821
|
/**
|
|
791
|
-
* Ecoa no terminal o início/fim de
|
|
822
|
+
* Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
|
|
792
823
|
* sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
|
|
793
824
|
* assim que os eventos de performance também aparecem nos logs da run no app.
|
|
794
825
|
*/
|
|
795
|
-
emit(kind, phase, label, startTs, endTs) {
|
|
826
|
+
emit(kind, phase, label, startTs, endTs, status) {
|
|
796
827
|
const durationMs = startTs && endTs ? new Date(endTs).getTime() - new Date(startTs).getTime() : void 0;
|
|
797
|
-
const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? "
|
|
828
|
+
const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? colorForStatus(status ?? "ok") : "cyan");
|
|
798
829
|
const suffix = durationMs != null ? ` (${durationMs}ms)` : "";
|
|
799
830
|
console.log(`${tag} ${label}${suffix}`);
|
|
800
|
-
const level = phase === "finish" ? "
|
|
831
|
+
const level = phase === "finish" ? levelForStatus(status ?? "ok") : "info";
|
|
801
832
|
const message = `[${kind}] ${phase.toUpperCase()} ${label}${suffix}`;
|
|
802
833
|
if (this.lifecycleSink) this.lifecycleSink(level, message);
|
|
803
834
|
else if (this.lifecycleBacklog.length < 100) this.lifecycleBacklog.push([level, message]);
|
|
@@ -809,15 +840,15 @@ var Transaction = class {
|
|
|
809
840
|
this.lifecycleBacklog = [];
|
|
810
841
|
for (const [level, message] of backlog) sink(level, message);
|
|
811
842
|
}
|
|
812
|
-
|
|
813
|
-
const
|
|
814
|
-
this.
|
|
815
|
-
this.emit("
|
|
816
|
-
return
|
|
843
|
+
createStep(parentStepId, op, description) {
|
|
844
|
+
const step = new Step(this, parentStepId, op, description);
|
|
845
|
+
this.steps.push(step);
|
|
846
|
+
this.emit("step", "start", stepLabel(op, description));
|
|
847
|
+
return step;
|
|
817
848
|
}
|
|
818
|
-
/**
|
|
849
|
+
/** Step direta da transaction. */
|
|
819
850
|
startChild(op, description) {
|
|
820
|
-
return this.
|
|
851
|
+
return this.createStep(this.stepId, op, description);
|
|
821
852
|
}
|
|
822
853
|
setTag(key, value) {
|
|
823
854
|
this.tags[key] = value;
|
|
@@ -834,14 +865,15 @@ var Transaction = class {
|
|
|
834
865
|
finish() {
|
|
835
866
|
if (this.finished) return;
|
|
836
867
|
this.finished = true;
|
|
837
|
-
for (const
|
|
868
|
+
for (const step of this.steps) step.finish();
|
|
838
869
|
const endTimestamp = nowISO();
|
|
839
870
|
this.emit(
|
|
840
871
|
"transaction",
|
|
841
872
|
"finish",
|
|
842
873
|
this.op ? `${this.name} (${this.op})` : this.name,
|
|
843
874
|
this.startTimestamp,
|
|
844
|
-
endTimestamp
|
|
875
|
+
endTimestamp,
|
|
876
|
+
this.status
|
|
845
877
|
);
|
|
846
878
|
if (!this.sampled || !this.client) return;
|
|
847
879
|
const payload = {
|
|
@@ -851,7 +883,7 @@ var Transaction = class {
|
|
|
851
883
|
status: this.status,
|
|
852
884
|
start_timestamp: this.startTimestamp,
|
|
853
885
|
timestamp: endTimestamp,
|
|
854
|
-
|
|
886
|
+
steps: this.steps.map((step) => step.toJSON()),
|
|
855
887
|
tags: Object.keys(this.tags).length > 0 ? this.tags : void 0,
|
|
856
888
|
run_id: this.runId
|
|
857
889
|
};
|