hobots 1.7.5 → 1.8.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 +14 -34
- package/dist/index.cjs +27 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -36
- package/dist/index.d.ts +19 -36
- package/dist/index.js +27 -80
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +9 -25
- package/dist/protocol.d.ts +9 -25
- package/docs/README.md +4 -4
- package/docs/api-reference.md +5 -27
- package/docs/concepts.md +27 -51
- package/docs/getting-started.md +1 -1
- package/docs/protocol.md +1 -2
- package/docs/tasks.md +6 -6
- package/docs/{monitor.md → telemetry.md} +13 -35
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload,
|
|
1
|
+
import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData } from './protocol.cjs';
|
|
2
2
|
export { AgentInfo, Envelope, EnvelopeItem, ExceptionData, PollRequest, PollResponse, RunDescriptor, RunError, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.cjs';
|
|
3
3
|
|
|
4
4
|
/** API oficial da Hobots — o SDK sempre fala com ela em produção. */
|
|
@@ -58,7 +58,6 @@ declare class Client {
|
|
|
58
58
|
captureEvent(event: EventPayload, hint: CaptureHint | undefined, scope: Scope): string;
|
|
59
59
|
private prepareEvent;
|
|
60
60
|
sendTransaction(payload: TransactionPayload): void;
|
|
61
|
-
sendCheckIn(payload: CheckInPayload): void;
|
|
62
61
|
sendHeartbeat(payload: HeartbeatPayload): void;
|
|
63
62
|
flush(timeoutMs?: number): Promise<boolean>;
|
|
64
63
|
close(timeoutMs?: number): Promise<boolean>;
|
|
@@ -66,27 +65,27 @@ declare class Client {
|
|
|
66
65
|
|
|
67
66
|
/** Recebe os eventos de lifecycle da transaction para espelhá-los nos logs da run. */
|
|
68
67
|
type LifecycleSink = (level: RunLogLevel, message: string) => void;
|
|
69
|
-
declare class
|
|
68
|
+
declare class Step {
|
|
70
69
|
private readonly transaction;
|
|
71
|
-
readonly
|
|
70
|
+
readonly parentStepId: string;
|
|
72
71
|
readonly op?: string | undefined;
|
|
73
72
|
readonly description?: string | undefined;
|
|
74
|
-
readonly
|
|
73
|
+
readonly stepId: string;
|
|
75
74
|
readonly startTimestamp: string;
|
|
76
|
-
status:
|
|
75
|
+
status: StepStatus;
|
|
77
76
|
endTimestamp?: string;
|
|
78
77
|
data?: Record<string, unknown>;
|
|
79
|
-
constructor(transaction: Transaction,
|
|
80
|
-
setStatus(status:
|
|
78
|
+
constructor(transaction: Transaction, parentStepId: string, op?: string | undefined, description?: string | undefined);
|
|
79
|
+
setStatus(status: StepStatus): this;
|
|
81
80
|
setData(key: string, value: unknown): this;
|
|
82
|
-
/**
|
|
83
|
-
startChild(op?: string, description?: string):
|
|
81
|
+
/** Step aninhada (filha desta step). */
|
|
82
|
+
startChild(op?: string, description?: string): Step;
|
|
84
83
|
finish(): void;
|
|
85
|
-
toJSON():
|
|
84
|
+
toJSON(): StepData;
|
|
86
85
|
}
|
|
87
86
|
/**
|
|
88
87
|
* Uma unidade de trabalho nomeada (ex.: uma execução de rotina, uma sincronização).
|
|
89
|
-
*
|
|
88
|
+
* Steps filhas medem as etapas internas (chamadas HTTP, queries, etc.).
|
|
90
89
|
*/
|
|
91
90
|
declare class Transaction {
|
|
92
91
|
private readonly client;
|
|
@@ -96,10 +95,10 @@ declare class Transaction {
|
|
|
96
95
|
/** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
|
|
97
96
|
private readonly runId?;
|
|
98
97
|
readonly eventId: string;
|
|
99
|
-
readonly
|
|
98
|
+
readonly stepId: string;
|
|
100
99
|
readonly startTimestamp: string;
|
|
101
100
|
status: string;
|
|
102
|
-
private readonly
|
|
101
|
+
private readonly steps;
|
|
103
102
|
private readonly tags;
|
|
104
103
|
private finished;
|
|
105
104
|
private lifecycleSink?;
|
|
@@ -108,16 +107,16 @@ declare class Transaction {
|
|
|
108
107
|
/** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
|
|
109
108
|
runId?: string | undefined);
|
|
110
109
|
/**
|
|
111
|
-
* Ecoa no terminal o início/fim de
|
|
110
|
+
* Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
|
|
112
111
|
* sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
|
|
113
112
|
* assim que os eventos de performance também aparecem nos logs da run no app.
|
|
114
113
|
*/
|
|
115
|
-
emit(kind: 'transaction' | '
|
|
114
|
+
emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
|
|
116
115
|
/** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
|
|
117
116
|
setLifecycleSink(sink: LifecycleSink): void;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
startChild(op?: string, description?: string):
|
|
117
|
+
createStep(parentStepId: string, op?: string, description?: string): Step;
|
|
118
|
+
/** Step direta da transaction. */
|
|
119
|
+
startChild(op?: string, description?: string): Step;
|
|
121
120
|
setTag(key: string, value: string): this;
|
|
122
121
|
setStatus(status: string): this;
|
|
123
122
|
setName(name: string): this;
|
|
@@ -232,18 +231,6 @@ interface CaptureHint {
|
|
|
232
231
|
fingerprint?: string[];
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
interface CheckInOptions {
|
|
236
|
-
monitorSlug: string;
|
|
237
|
-
status: CheckInStatus;
|
|
238
|
-
/** Reutilize o id retornado pelo check-in 'in_progress' para fechar a execução */
|
|
239
|
-
checkInId?: string;
|
|
240
|
-
durationMs?: number;
|
|
241
|
-
/** Expressão cron — cria/atualiza o monitor automaticamente no servidor */
|
|
242
|
-
schedule?: string;
|
|
243
|
-
timezone?: string;
|
|
244
|
-
}
|
|
245
|
-
type WithMonitorOptions = Pick<CheckInOptions, 'schedule' | 'timezone'>;
|
|
246
|
-
|
|
247
234
|
/** Inicializa o SDK. Chame uma vez, o mais cedo possível no programa. */
|
|
248
235
|
declare function init(options: InitOptions): void;
|
|
249
236
|
declare function getClient(): Client | undefined;
|
|
@@ -261,10 +248,6 @@ declare function setExtra(key: string, value: unknown): void;
|
|
|
261
248
|
declare function withScope<T>(callback: (scope: Scope) => T): T;
|
|
262
249
|
/** Inicia uma transaction de performance. Chame .finish() para enviá-la. */
|
|
263
250
|
declare function startTransaction(name: string, op?: string): Transaction;
|
|
264
|
-
/** Check-in manual de um monitor cron. Retorna o check_in_id para fechar a execução depois. */
|
|
265
|
-
declare function checkIn(options: CheckInOptions): string | undefined;
|
|
266
|
-
/** Envolve um job monitorado: envia in_progress → ok/error com duração e captura a exceção em caso de falha. */
|
|
267
|
-
declare function withMonitor<T>(monitorSlug: string, fn: () => T | Promise<T>, options?: WithMonitorOptions): Promise<T>;
|
|
268
251
|
/** Aguarda o envio de tudo que está na fila (até timeoutMs). */
|
|
269
252
|
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
270
253
|
/** Registra o handler de uma task (o task_slug configurado no formulário do app, em Configurações → Formulários). */
|
|
@@ -284,4 +267,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
|
|
|
284
267
|
|
|
285
268
|
declare function scrubSecrets(text: string): string;
|
|
286
269
|
|
|
287
|
-
export { Breadcrumb, type BreadcrumbInput, type CaptureHint,
|
|
270
|
+
export { Breadcrumb, type BreadcrumbInput, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload,
|
|
1
|
+
import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData } from './protocol.js';
|
|
2
2
|
export { AgentInfo, Envelope, EnvelopeItem, ExceptionData, PollRequest, PollResponse, RunDescriptor, RunError, RunLogEntry, RunStatus, RunUpdateRequest, RunUpdateResponse, RunUpdateStatus, StackFrame } from './protocol.js';
|
|
3
3
|
|
|
4
4
|
/** API oficial da Hobots — o SDK sempre fala com ela em produção. */
|
|
@@ -58,7 +58,6 @@ declare class Client {
|
|
|
58
58
|
captureEvent(event: EventPayload, hint: CaptureHint | undefined, scope: Scope): string;
|
|
59
59
|
private prepareEvent;
|
|
60
60
|
sendTransaction(payload: TransactionPayload): void;
|
|
61
|
-
sendCheckIn(payload: CheckInPayload): void;
|
|
62
61
|
sendHeartbeat(payload: HeartbeatPayload): void;
|
|
63
62
|
flush(timeoutMs?: number): Promise<boolean>;
|
|
64
63
|
close(timeoutMs?: number): Promise<boolean>;
|
|
@@ -66,27 +65,27 @@ declare class Client {
|
|
|
66
65
|
|
|
67
66
|
/** Recebe os eventos de lifecycle da transaction para espelhá-los nos logs da run. */
|
|
68
67
|
type LifecycleSink = (level: RunLogLevel, message: string) => void;
|
|
69
|
-
declare class
|
|
68
|
+
declare class Step {
|
|
70
69
|
private readonly transaction;
|
|
71
|
-
readonly
|
|
70
|
+
readonly parentStepId: string;
|
|
72
71
|
readonly op?: string | undefined;
|
|
73
72
|
readonly description?: string | undefined;
|
|
74
|
-
readonly
|
|
73
|
+
readonly stepId: string;
|
|
75
74
|
readonly startTimestamp: string;
|
|
76
|
-
status:
|
|
75
|
+
status: StepStatus;
|
|
77
76
|
endTimestamp?: string;
|
|
78
77
|
data?: Record<string, unknown>;
|
|
79
|
-
constructor(transaction: Transaction,
|
|
80
|
-
setStatus(status:
|
|
78
|
+
constructor(transaction: Transaction, parentStepId: string, op?: string | undefined, description?: string | undefined);
|
|
79
|
+
setStatus(status: StepStatus): this;
|
|
81
80
|
setData(key: string, value: unknown): this;
|
|
82
|
-
/**
|
|
83
|
-
startChild(op?: string, description?: string):
|
|
81
|
+
/** Step aninhada (filha desta step). */
|
|
82
|
+
startChild(op?: string, description?: string): Step;
|
|
84
83
|
finish(): void;
|
|
85
|
-
toJSON():
|
|
84
|
+
toJSON(): StepData;
|
|
86
85
|
}
|
|
87
86
|
/**
|
|
88
87
|
* Uma unidade de trabalho nomeada (ex.: uma execução de rotina, uma sincronização).
|
|
89
|
-
*
|
|
88
|
+
* Steps filhas medem as etapas internas (chamadas HTTP, queries, etc.).
|
|
90
89
|
*/
|
|
91
90
|
declare class Transaction {
|
|
92
91
|
private readonly client;
|
|
@@ -96,10 +95,10 @@ declare class Transaction {
|
|
|
96
95
|
/** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
|
|
97
96
|
private readonly runId?;
|
|
98
97
|
readonly eventId: string;
|
|
99
|
-
readonly
|
|
98
|
+
readonly stepId: string;
|
|
100
99
|
readonly startTimestamp: string;
|
|
101
100
|
status: string;
|
|
102
|
-
private readonly
|
|
101
|
+
private readonly steps;
|
|
103
102
|
private readonly tags;
|
|
104
103
|
private finished;
|
|
105
104
|
private lifecycleSink?;
|
|
@@ -108,16 +107,16 @@ declare class Transaction {
|
|
|
108
107
|
/** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
|
|
109
108
|
runId?: string | undefined);
|
|
110
109
|
/**
|
|
111
|
-
* Ecoa no terminal o início/fim de
|
|
110
|
+
* Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
|
|
112
111
|
* sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
|
|
113
112
|
* assim que os eventos de performance também aparecem nos logs da run no app.
|
|
114
113
|
*/
|
|
115
|
-
emit(kind: 'transaction' | '
|
|
114
|
+
emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
|
|
116
115
|
/** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
|
|
117
116
|
setLifecycleSink(sink: LifecycleSink): void;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
startChild(op?: string, description?: string):
|
|
117
|
+
createStep(parentStepId: string, op?: string, description?: string): Step;
|
|
118
|
+
/** Step direta da transaction. */
|
|
119
|
+
startChild(op?: string, description?: string): Step;
|
|
121
120
|
setTag(key: string, value: string): this;
|
|
122
121
|
setStatus(status: string): this;
|
|
123
122
|
setName(name: string): this;
|
|
@@ -232,18 +231,6 @@ interface CaptureHint {
|
|
|
232
231
|
fingerprint?: string[];
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
interface CheckInOptions {
|
|
236
|
-
monitorSlug: string;
|
|
237
|
-
status: CheckInStatus;
|
|
238
|
-
/** Reutilize o id retornado pelo check-in 'in_progress' para fechar a execução */
|
|
239
|
-
checkInId?: string;
|
|
240
|
-
durationMs?: number;
|
|
241
|
-
/** Expressão cron — cria/atualiza o monitor automaticamente no servidor */
|
|
242
|
-
schedule?: string;
|
|
243
|
-
timezone?: string;
|
|
244
|
-
}
|
|
245
|
-
type WithMonitorOptions = Pick<CheckInOptions, 'schedule' | 'timezone'>;
|
|
246
|
-
|
|
247
234
|
/** Inicializa o SDK. Chame uma vez, o mais cedo possível no programa. */
|
|
248
235
|
declare function init(options: InitOptions): void;
|
|
249
236
|
declare function getClient(): Client | undefined;
|
|
@@ -261,10 +248,6 @@ declare function setExtra(key: string, value: unknown): void;
|
|
|
261
248
|
declare function withScope<T>(callback: (scope: Scope) => T): T;
|
|
262
249
|
/** Inicia uma transaction de performance. Chame .finish() para enviá-la. */
|
|
263
250
|
declare function startTransaction(name: string, op?: string): Transaction;
|
|
264
|
-
/** Check-in manual de um monitor cron. Retorna o check_in_id para fechar a execução depois. */
|
|
265
|
-
declare function checkIn(options: CheckInOptions): string | undefined;
|
|
266
|
-
/** Envolve um job monitorado: envia in_progress → ok/error com duração e captura a exceção em caso de falha. */
|
|
267
|
-
declare function withMonitor<T>(monitorSlug: string, fn: () => T | Promise<T>, options?: WithMonitorOptions): Promise<T>;
|
|
268
251
|
/** Aguarda o envio de tudo que está na fila (até timeoutMs). */
|
|
269
252
|
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
270
253
|
/** Registra o handler de uma task (o task_slug configurado no formulário do app, em Configurações → Formulários). */
|
|
@@ -284,4 +267,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
|
|
|
284
267
|
|
|
285
268
|
declare function scrubSecrets(text: string): string;
|
|
286
269
|
|
|
287
|
-
export { Breadcrumb, type BreadcrumbInput, type CaptureHint,
|
|
270
|
+
export { Breadcrumb, type BreadcrumbInput, type CaptureHint, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, addBreadcrumb, captureException, captureMessage, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withScope };
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ function scrubSecrets(text) {
|
|
|
103
103
|
|
|
104
104
|
// src/utils.ts
|
|
105
105
|
var SDK_NAME = "hobots";
|
|
106
|
-
var SDK_VERSION = true ? "1.
|
|
106
|
+
var SDK_VERSION = true ? "1.8.0" : "0.0.0-dev";
|
|
107
107
|
function isNode() {
|
|
108
108
|
return typeof process !== "undefined" && typeof process.versions?.node === "string";
|
|
109
109
|
}
|
|
@@ -457,16 +457,6 @@ var Client = class {
|
|
|
457
457
|
}
|
|
458
458
|
});
|
|
459
459
|
}
|
|
460
|
-
sendCheckIn(payload) {
|
|
461
|
-
this.transport.enqueue({
|
|
462
|
-
type: "check_in",
|
|
463
|
-
payload: {
|
|
464
|
-
...payload,
|
|
465
|
-
release: payload.release ?? this.options.release,
|
|
466
|
-
environment: payload.environment ?? this.options.environment ?? "production"
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
460
|
sendHeartbeat(payload) {
|
|
471
461
|
this.transport.enqueue({
|
|
472
462
|
type: "heartbeat",
|
|
@@ -659,10 +649,10 @@ var Scope = class _Scope {
|
|
|
659
649
|
};
|
|
660
650
|
|
|
661
651
|
// src/transaction.ts
|
|
662
|
-
function
|
|
652
|
+
function stepId() {
|
|
663
653
|
return uuid4().slice(0, 16);
|
|
664
654
|
}
|
|
665
|
-
function
|
|
655
|
+
function stepLabel(op, description) {
|
|
666
656
|
return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
|
|
667
657
|
}
|
|
668
658
|
function levelForStatus(status) {
|
|
@@ -689,14 +679,14 @@ function colorForStatus(status) {
|
|
|
689
679
|
return "green";
|
|
690
680
|
}
|
|
691
681
|
}
|
|
692
|
-
var
|
|
693
|
-
constructor(transaction,
|
|
682
|
+
var Step = class {
|
|
683
|
+
constructor(transaction, parentStepId, op, description) {
|
|
694
684
|
this.transaction = transaction;
|
|
695
|
-
this.
|
|
685
|
+
this.parentStepId = parentStepId;
|
|
696
686
|
this.op = op;
|
|
697
687
|
this.description = description;
|
|
698
688
|
}
|
|
699
|
-
|
|
689
|
+
stepId = stepId();
|
|
700
690
|
startTimestamp = nowISO();
|
|
701
691
|
status = "ok";
|
|
702
692
|
endTimestamp;
|
|
@@ -709,17 +699,17 @@ var Span = class {
|
|
|
709
699
|
this.data = { ...this.data, [key]: value };
|
|
710
700
|
return this;
|
|
711
701
|
}
|
|
712
|
-
/**
|
|
702
|
+
/** Step aninhada (filha desta step). */
|
|
713
703
|
startChild(op, description) {
|
|
714
|
-
return this.transaction.
|
|
704
|
+
return this.transaction.createStep(this.stepId, op, description);
|
|
715
705
|
}
|
|
716
706
|
finish() {
|
|
717
707
|
if (this.endTimestamp) return;
|
|
718
708
|
this.endTimestamp = nowISO();
|
|
719
709
|
this.transaction.emit(
|
|
720
|
-
"
|
|
710
|
+
"step",
|
|
721
711
|
"finish",
|
|
722
|
-
|
|
712
|
+
stepLabel(this.op, this.description),
|
|
723
713
|
this.startTimestamp,
|
|
724
714
|
this.endTimestamp,
|
|
725
715
|
this.status
|
|
@@ -727,8 +717,8 @@ var Span = class {
|
|
|
727
717
|
}
|
|
728
718
|
toJSON() {
|
|
729
719
|
return {
|
|
730
|
-
|
|
731
|
-
|
|
720
|
+
step_id: this.stepId,
|
|
721
|
+
parent_step_id: this.parentStepId,
|
|
732
722
|
op: this.op,
|
|
733
723
|
description: this.description,
|
|
734
724
|
status: this.status,
|
|
@@ -748,10 +738,10 @@ var Transaction = class {
|
|
|
748
738
|
this.emit("transaction", "start", op ? `${name} (${op})` : name);
|
|
749
739
|
}
|
|
750
740
|
eventId = uuid4();
|
|
751
|
-
|
|
741
|
+
stepId = stepId();
|
|
752
742
|
startTimestamp = nowISO();
|
|
753
743
|
status = "ok";
|
|
754
|
-
|
|
744
|
+
steps = [];
|
|
755
745
|
tags = {};
|
|
756
746
|
finished = false;
|
|
757
747
|
lifecycleSink;
|
|
@@ -759,7 +749,7 @@ var Transaction = class {
|
|
|
759
749
|
// antes do RunReporter conectar) — replay no setLifecycleSink
|
|
760
750
|
lifecycleBacklog = [];
|
|
761
751
|
/**
|
|
762
|
-
* Ecoa no terminal o início/fim de
|
|
752
|
+
* Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
|
|
763
753
|
* sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
|
|
764
754
|
* assim que os eventos de performance também aparecem nos logs da run no app.
|
|
765
755
|
*/
|
|
@@ -780,15 +770,15 @@ var Transaction = class {
|
|
|
780
770
|
this.lifecycleBacklog = [];
|
|
781
771
|
for (const [level, message] of backlog) sink(level, message);
|
|
782
772
|
}
|
|
783
|
-
|
|
784
|
-
const
|
|
785
|
-
this.
|
|
786
|
-
this.emit("
|
|
787
|
-
return
|
|
773
|
+
createStep(parentStepId, op, description) {
|
|
774
|
+
const step = new Step(this, parentStepId, op, description);
|
|
775
|
+
this.steps.push(step);
|
|
776
|
+
this.emit("step", "start", stepLabel(op, description));
|
|
777
|
+
return step;
|
|
788
778
|
}
|
|
789
|
-
/**
|
|
779
|
+
/** Step direta da transaction. */
|
|
790
780
|
startChild(op, description) {
|
|
791
|
-
return this.
|
|
781
|
+
return this.createStep(this.stepId, op, description);
|
|
792
782
|
}
|
|
793
783
|
setTag(key, value) {
|
|
794
784
|
this.tags[key] = value;
|
|
@@ -805,7 +795,7 @@ var Transaction = class {
|
|
|
805
795
|
finish() {
|
|
806
796
|
if (this.finished) return;
|
|
807
797
|
this.finished = true;
|
|
808
|
-
for (const
|
|
798
|
+
for (const step of this.steps) step.finish();
|
|
809
799
|
const endTimestamp = nowISO();
|
|
810
800
|
this.emit(
|
|
811
801
|
"transaction",
|
|
@@ -823,7 +813,7 @@ var Transaction = class {
|
|
|
823
813
|
status: this.status,
|
|
824
814
|
start_timestamp: this.startTimestamp,
|
|
825
815
|
timestamp: endTimestamp,
|
|
826
|
-
|
|
816
|
+
steps: this.steps.map((step) => step.toJSON()),
|
|
827
817
|
tags: Object.keys(this.tags).length > 0 ? this.tags : void 0,
|
|
828
818
|
run_id: this.runId
|
|
829
819
|
};
|
|
@@ -831,34 +821,6 @@ var Transaction = class {
|
|
|
831
821
|
}
|
|
832
822
|
};
|
|
833
823
|
|
|
834
|
-
// src/checkin.ts
|
|
835
|
-
function sendCheckIn(client2, options) {
|
|
836
|
-
const checkInId = options.checkInId ?? uuid4();
|
|
837
|
-
client2.sendCheckIn({
|
|
838
|
-
check_in_id: checkInId,
|
|
839
|
-
monitor_slug: options.monitorSlug,
|
|
840
|
-
status: options.status,
|
|
841
|
-
duration_ms: options.durationMs,
|
|
842
|
-
schedule: options.schedule,
|
|
843
|
-
timezone: options.timezone
|
|
844
|
-
});
|
|
845
|
-
return checkInId;
|
|
846
|
-
}
|
|
847
|
-
async function withMonitorImpl(client2, captureError, monitorSlug, fn, options) {
|
|
848
|
-
const base = { monitorSlug, schedule: options?.schedule, timezone: options?.timezone };
|
|
849
|
-
const checkInId = sendCheckIn(client2, { ...base, status: "in_progress" });
|
|
850
|
-
const startedAt = Date.now();
|
|
851
|
-
try {
|
|
852
|
-
const result = await fn();
|
|
853
|
-
sendCheckIn(client2, { ...base, status: "ok", checkInId, durationMs: Date.now() - startedAt });
|
|
854
|
-
return result;
|
|
855
|
-
} catch (error) {
|
|
856
|
-
sendCheckIn(client2, { ...base, status: "error", checkInId, durationMs: Date.now() - startedAt });
|
|
857
|
-
captureError(error);
|
|
858
|
-
throw error;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
824
|
// src/tasks/api.ts
|
|
863
825
|
var POLL_TIMEOUT_MS = 3e4;
|
|
864
826
|
var UPDATE_TIMEOUT_MS = 1e4;
|
|
@@ -1404,7 +1366,7 @@ var TaskAgent = class {
|
|
|
1404
1366
|
{
|
|
1405
1367
|
agent: {
|
|
1406
1368
|
// identidade canônica do agente no painel — o mesmo instanceId do
|
|
1407
|
-
// heartbeat
|
|
1369
|
+
// heartbeat da Telemetria, então os dois canais convergem em um agente
|
|
1408
1370
|
instance_id: this.instanceId,
|
|
1409
1371
|
version: SDK_VERSION,
|
|
1410
1372
|
host: hostname(),
|
|
@@ -1606,19 +1568,6 @@ function startTransaction(name, op) {
|
|
|
1606
1568
|
const sampled = rate >= 1 || Math.random() < rate;
|
|
1607
1569
|
return new Transaction(client, name, op, sampled);
|
|
1608
1570
|
}
|
|
1609
|
-
function checkIn(options) {
|
|
1610
|
-
return client ? sendCheckIn(client, options) : void 0;
|
|
1611
|
-
}
|
|
1612
|
-
async function withMonitor(monitorSlug, fn, options) {
|
|
1613
|
-
if (!client) return fn();
|
|
1614
|
-
return withMonitorImpl(
|
|
1615
|
-
client,
|
|
1616
|
-
(error) => captureException(error, { tags: { monitor: monitorSlug } }),
|
|
1617
|
-
monitorSlug,
|
|
1618
|
-
fn,
|
|
1619
|
-
options
|
|
1620
|
-
);
|
|
1621
|
-
}
|
|
1622
1571
|
function flush(timeoutMs) {
|
|
1623
1572
|
return client ? client.flush(timeoutMs) : Promise.resolve(true);
|
|
1624
1573
|
}
|
|
@@ -1654,12 +1603,11 @@ export {
|
|
|
1654
1603
|
Client,
|
|
1655
1604
|
DEFAULT_BASE_URL,
|
|
1656
1605
|
Scope,
|
|
1657
|
-
|
|
1606
|
+
Step,
|
|
1658
1607
|
Transaction,
|
|
1659
1608
|
addBreadcrumb,
|
|
1660
1609
|
captureException,
|
|
1661
1610
|
captureMessage,
|
|
1662
|
-
checkIn,
|
|
1663
1611
|
close,
|
|
1664
1612
|
flush,
|
|
1665
1613
|
getClient,
|
|
@@ -1674,7 +1622,6 @@ export {
|
|
|
1674
1622
|
start,
|
|
1675
1623
|
startTransaction,
|
|
1676
1624
|
stop,
|
|
1677
|
-
withMonitor,
|
|
1678
1625
|
withScope
|
|
1679
1626
|
};
|
|
1680
1627
|
//# sourceMappingURL=index.js.map
|