hobots 1.7.5 → 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 +26 -26
- 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 +26 -26
- 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,10 +719,10 @@ 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
728
|
function levelForStatus(status) {
|
|
@@ -749,14 +749,14 @@ function colorForStatus(status) {
|
|
|
749
749
|
return "green";
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
|
-
var
|
|
753
|
-
constructor(transaction,
|
|
752
|
+
var Step = class {
|
|
753
|
+
constructor(transaction, parentStepId, op, description) {
|
|
754
754
|
this.transaction = transaction;
|
|
755
|
-
this.
|
|
755
|
+
this.parentStepId = parentStepId;
|
|
756
756
|
this.op = op;
|
|
757
757
|
this.description = description;
|
|
758
758
|
}
|
|
759
|
-
|
|
759
|
+
stepId = stepId();
|
|
760
760
|
startTimestamp = nowISO();
|
|
761
761
|
status = "ok";
|
|
762
762
|
endTimestamp;
|
|
@@ -769,17 +769,17 @@ var Span = class {
|
|
|
769
769
|
this.data = { ...this.data, [key]: value };
|
|
770
770
|
return this;
|
|
771
771
|
}
|
|
772
|
-
/**
|
|
772
|
+
/** Step aninhada (filha desta step). */
|
|
773
773
|
startChild(op, description) {
|
|
774
|
-
return this.transaction.
|
|
774
|
+
return this.transaction.createStep(this.stepId, op, description);
|
|
775
775
|
}
|
|
776
776
|
finish() {
|
|
777
777
|
if (this.endTimestamp) return;
|
|
778
778
|
this.endTimestamp = nowISO();
|
|
779
779
|
this.transaction.emit(
|
|
780
|
-
"
|
|
780
|
+
"step",
|
|
781
781
|
"finish",
|
|
782
|
-
|
|
782
|
+
stepLabel(this.op, this.description),
|
|
783
783
|
this.startTimestamp,
|
|
784
784
|
this.endTimestamp,
|
|
785
785
|
this.status
|
|
@@ -787,8 +787,8 @@ var Span = class {
|
|
|
787
787
|
}
|
|
788
788
|
toJSON() {
|
|
789
789
|
return {
|
|
790
|
-
|
|
791
|
-
|
|
790
|
+
step_id: this.stepId,
|
|
791
|
+
parent_step_id: this.parentStepId,
|
|
792
792
|
op: this.op,
|
|
793
793
|
description: this.description,
|
|
794
794
|
status: this.status,
|
|
@@ -808,10 +808,10 @@ var Transaction = class {
|
|
|
808
808
|
this.emit("transaction", "start", op ? `${name} (${op})` : name);
|
|
809
809
|
}
|
|
810
810
|
eventId = uuid4();
|
|
811
|
-
|
|
811
|
+
stepId = stepId();
|
|
812
812
|
startTimestamp = nowISO();
|
|
813
813
|
status = "ok";
|
|
814
|
-
|
|
814
|
+
steps = [];
|
|
815
815
|
tags = {};
|
|
816
816
|
finished = false;
|
|
817
817
|
lifecycleSink;
|
|
@@ -819,7 +819,7 @@ var Transaction = class {
|
|
|
819
819
|
// antes do RunReporter conectar) — replay no setLifecycleSink
|
|
820
820
|
lifecycleBacklog = [];
|
|
821
821
|
/**
|
|
822
|
-
* Ecoa no terminal o início/fim de
|
|
822
|
+
* Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
|
|
823
823
|
* sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
|
|
824
824
|
* assim que os eventos de performance também aparecem nos logs da run no app.
|
|
825
825
|
*/
|
|
@@ -840,15 +840,15 @@ var Transaction = class {
|
|
|
840
840
|
this.lifecycleBacklog = [];
|
|
841
841
|
for (const [level, message] of backlog) sink(level, message);
|
|
842
842
|
}
|
|
843
|
-
|
|
844
|
-
const
|
|
845
|
-
this.
|
|
846
|
-
this.emit("
|
|
847
|
-
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;
|
|
848
848
|
}
|
|
849
|
-
/**
|
|
849
|
+
/** Step direta da transaction. */
|
|
850
850
|
startChild(op, description) {
|
|
851
|
-
return this.
|
|
851
|
+
return this.createStep(this.stepId, op, description);
|
|
852
852
|
}
|
|
853
853
|
setTag(key, value) {
|
|
854
854
|
this.tags[key] = value;
|
|
@@ -865,7 +865,7 @@ var Transaction = class {
|
|
|
865
865
|
finish() {
|
|
866
866
|
if (this.finished) return;
|
|
867
867
|
this.finished = true;
|
|
868
|
-
for (const
|
|
868
|
+
for (const step of this.steps) step.finish();
|
|
869
869
|
const endTimestamp = nowISO();
|
|
870
870
|
this.emit(
|
|
871
871
|
"transaction",
|
|
@@ -883,7 +883,7 @@ var Transaction = class {
|
|
|
883
883
|
status: this.status,
|
|
884
884
|
start_timestamp: this.startTimestamp,
|
|
885
885
|
timestamp: endTimestamp,
|
|
886
|
-
|
|
886
|
+
steps: this.steps.map((step) => step.toJSON()),
|
|
887
887
|
tags: Object.keys(this.tags).length > 0 ? this.tags : void 0,
|
|
888
888
|
run_id: this.runId
|
|
889
889
|
};
|