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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, CheckInPayload, HeartbeatPayload, RunLogLevel, SpanStatus, SpanData, CheckInStatus } from './protocol.cjs';
1
+ import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, CheckInPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, CheckInStatus } 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. */
@@ -66,27 +66,27 @@ declare class Client {
66
66
 
67
67
  /** Recebe os eventos de lifecycle da transaction para espelhá-los nos logs da run. */
68
68
  type LifecycleSink = (level: RunLogLevel, message: string) => void;
69
- declare class Span {
69
+ declare class Step {
70
70
  private readonly transaction;
71
- readonly parentSpanId: string;
71
+ readonly parentStepId: string;
72
72
  readonly op?: string | undefined;
73
73
  readonly description?: string | undefined;
74
- readonly spanId: string;
74
+ readonly stepId: string;
75
75
  readonly startTimestamp: string;
76
- status: SpanStatus;
76
+ status: StepStatus;
77
77
  endTimestamp?: string;
78
78
  data?: Record<string, unknown>;
79
- constructor(transaction: Transaction, parentSpanId: string, op?: string | undefined, description?: string | undefined);
80
- setStatus(status: SpanStatus): this;
79
+ constructor(transaction: Transaction, parentStepId: string, op?: string | undefined, description?: string | undefined);
80
+ setStatus(status: StepStatus): this;
81
81
  setData(key: string, value: unknown): this;
82
- /** Span aninhado (filho deste span). */
83
- startChild(op?: string, description?: string): Span;
82
+ /** Step aninhada (filha desta step). */
83
+ startChild(op?: string, description?: string): Step;
84
84
  finish(): void;
85
- toJSON(): SpanData;
85
+ toJSON(): StepData;
86
86
  }
87
87
  /**
88
88
  * Uma unidade de trabalho nomeada (ex.: uma execução de rotina, uma sincronização).
89
- * Spans filhos medem as etapas internas (chamadas HTTP, queries, etc.).
89
+ * Steps filhas medem as etapas internas (chamadas HTTP, queries, etc.).
90
90
  */
91
91
  declare class Transaction {
92
92
  private readonly client;
@@ -96,10 +96,10 @@ declare class Transaction {
96
96
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
97
97
  private readonly runId?;
98
98
  readonly eventId: string;
99
- readonly spanId: string;
99
+ readonly stepId: string;
100
100
  readonly startTimestamp: string;
101
101
  status: string;
102
- private readonly spans;
102
+ private readonly steps;
103
103
  private readonly tags;
104
104
  private finished;
105
105
  private lifecycleSink?;
@@ -108,16 +108,16 @@ declare class Transaction {
108
108
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
109
109
  runId?: string | undefined);
110
110
  /**
111
- * Ecoa no terminal o início/fim de um span ou transaction (sempre, independente de
111
+ * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
112
112
  * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
113
113
  * assim que os eventos de performance também aparecem nos logs da run no app.
114
114
  */
115
- emit(kind: 'transaction' | 'span', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string): void;
115
+ emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
116
116
  /** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
117
117
  setLifecycleSink(sink: LifecycleSink): void;
118
- createSpan(parentSpanId: string, op?: string, description?: string): Span;
119
- /** Span direto da transaction. */
120
- startChild(op?: string, description?: string): Span;
118
+ createStep(parentStepId: string, op?: string, description?: string): Step;
119
+ /** Step direta da transaction. */
120
+ startChild(op?: string, description?: string): Step;
121
121
  setTag(key: string, value: string): this;
122
122
  setStatus(status: string): this;
123
123
  setName(name: string): this;
@@ -284,4 +284,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
284
284
 
285
285
  declare function scrubSecrets(text: string): string;
286
286
 
287
- export { Breadcrumb, type BreadcrumbInput, type CaptureHint, type CheckInOptions, CheckInPayload, CheckInStatus, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Span, SpanData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, type WithMonitorOptions, addBreadcrumb, captureException, captureMessage, checkIn, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withMonitor, withScope };
287
+ export { Breadcrumb, type BreadcrumbInput, type CaptureHint, type CheckInOptions, CheckInPayload, CheckInStatus, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, type WithMonitorOptions, addBreadcrumb, captureException, captureMessage, checkIn, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withMonitor, withScope };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, CheckInPayload, HeartbeatPayload, RunLogLevel, SpanStatus, SpanData, CheckInStatus } from './protocol.js';
1
+ import { Breadcrumb, EventUser, Severity, EventPayload, TransactionPayload, CheckInPayload, HeartbeatPayload, StepStatus, RunLogLevel, StepData, CheckInStatus } 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. */
@@ -66,27 +66,27 @@ declare class Client {
66
66
 
67
67
  /** Recebe os eventos de lifecycle da transaction para espelhá-los nos logs da run. */
68
68
  type LifecycleSink = (level: RunLogLevel, message: string) => void;
69
- declare class Span {
69
+ declare class Step {
70
70
  private readonly transaction;
71
- readonly parentSpanId: string;
71
+ readonly parentStepId: string;
72
72
  readonly op?: string | undefined;
73
73
  readonly description?: string | undefined;
74
- readonly spanId: string;
74
+ readonly stepId: string;
75
75
  readonly startTimestamp: string;
76
- status: SpanStatus;
76
+ status: StepStatus;
77
77
  endTimestamp?: string;
78
78
  data?: Record<string, unknown>;
79
- constructor(transaction: Transaction, parentSpanId: string, op?: string | undefined, description?: string | undefined);
80
- setStatus(status: SpanStatus): this;
79
+ constructor(transaction: Transaction, parentStepId: string, op?: string | undefined, description?: string | undefined);
80
+ setStatus(status: StepStatus): this;
81
81
  setData(key: string, value: unknown): this;
82
- /** Span aninhado (filho deste span). */
83
- startChild(op?: string, description?: string): Span;
82
+ /** Step aninhada (filha desta step). */
83
+ startChild(op?: string, description?: string): Step;
84
84
  finish(): void;
85
- toJSON(): SpanData;
85
+ toJSON(): StepData;
86
86
  }
87
87
  /**
88
88
  * Uma unidade de trabalho nomeada (ex.: uma execução de rotina, uma sincronização).
89
- * Spans filhos medem as etapas internas (chamadas HTTP, queries, etc.).
89
+ * Steps filhas medem as etapas internas (chamadas HTTP, queries, etc.).
90
90
  */
91
91
  declare class Transaction {
92
92
  private readonly client;
@@ -96,10 +96,10 @@ declare class Transaction {
96
96
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
97
97
  private readonly runId?;
98
98
  readonly eventId: string;
99
- readonly spanId: string;
99
+ readonly stepId: string;
100
100
  readonly startTimestamp: string;
101
101
  status: string;
102
- private readonly spans;
102
+ private readonly steps;
103
103
  private readonly tags;
104
104
  private finished;
105
105
  private lifecycleSink?;
@@ -108,16 +108,16 @@ declare class Transaction {
108
108
  /** Correlaciona a uma execução de task — preenchido automaticamente em ctx.tx */
109
109
  runId?: string | undefined);
110
110
  /**
111
- * Ecoa no terminal o início/fim de um span ou transaction (sempre, independente de
111
+ * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
112
112
  * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
113
113
  * assim que os eventos de performance também aparecem nos logs da run no app.
114
114
  */
115
- emit(kind: 'transaction' | 'span', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string): void;
115
+ emit(kind: 'transaction' | 'step', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: StepStatus | string): void;
116
116
  /** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
117
117
  setLifecycleSink(sink: LifecycleSink): void;
118
- createSpan(parentSpanId: string, op?: string, description?: string): Span;
119
- /** Span direto da transaction. */
120
- startChild(op?: string, description?: string): Span;
118
+ createStep(parentStepId: string, op?: string, description?: string): Step;
119
+ /** Step direta da transaction. */
120
+ startChild(op?: string, description?: string): Step;
121
121
  setTag(key: string, value: string): this;
122
122
  setStatus(status: string): this;
123
123
  setName(name: string): this;
@@ -284,4 +284,4 @@ declare function close(timeoutMs?: number): Promise<boolean>;
284
284
 
285
285
  declare function scrubSecrets(text: string): string;
286
286
 
287
- export { Breadcrumb, type BreadcrumbInput, type CaptureHint, type CheckInOptions, CheckInPayload, CheckInStatus, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Span, SpanData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, type WithMonitorOptions, addBreadcrumb, captureException, captureMessage, checkIn, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withMonitor, withScope };
287
+ export { Breadcrumb, type BreadcrumbInput, type CaptureHint, type CheckInOptions, CheckInPayload, CheckInStatus, Client, DEFAULT_BASE_URL, EventPayload, EventUser, type HeartbeatOptions, HeartbeatPayload, type InitOptions, type RunContext, RunLogLevel, Scope, Severity, Step, StepData, type TaskHandler, type TasksOptions, Transaction, TransactionPayload, type WithMonitorOptions, addBreadcrumb, captureException, captureMessage, checkIn, close, flush, getClient, init, register, scrubSecrets, setContext, setExtra, setTag, setTags, setUser, start, startTransaction, stop, withMonitor, 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.7.2" : "0.0.0-dev";
106
+ var SDK_VERSION = true ? "1.7.6" : "0.0.0-dev";
107
107
  function isNode() {
108
108
  return typeof process !== "undefined" && typeof process.versions?.node === "string";
109
109
  }
@@ -659,20 +659,44 @@ var Scope = class _Scope {
659
659
  };
660
660
 
661
661
  // src/transaction.ts
662
- function spanId() {
662
+ function stepId() {
663
663
  return uuid4().slice(0, 16);
664
664
  }
665
- function spanLabel(op, description) {
665
+ function stepLabel(op, description) {
666
666
  return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
667
667
  }
668
- var Span = class {
669
- constructor(transaction, parentSpanId, op, description) {
668
+ function levelForStatus(status) {
669
+ switch (status) {
670
+ case "warning":
671
+ return "warning";
672
+ case "error":
673
+ return "error";
674
+ case "cancelled":
675
+ return "warning";
676
+ default:
677
+ return "success";
678
+ }
679
+ }
680
+ function colorForStatus(status) {
681
+ switch (status) {
682
+ case "warning":
683
+ return "yellow";
684
+ case "error":
685
+ return "red";
686
+ case "cancelled":
687
+ return "gray";
688
+ default:
689
+ return "green";
690
+ }
691
+ }
692
+ var Step = class {
693
+ constructor(transaction, parentStepId, op, description) {
670
694
  this.transaction = transaction;
671
- this.parentSpanId = parentSpanId;
695
+ this.parentStepId = parentStepId;
672
696
  this.op = op;
673
697
  this.description = description;
674
698
  }
675
- spanId = spanId();
699
+ stepId = stepId();
676
700
  startTimestamp = nowISO();
677
701
  status = "ok";
678
702
  endTimestamp;
@@ -685,19 +709,26 @@ var Span = class {
685
709
  this.data = { ...this.data, [key]: value };
686
710
  return this;
687
711
  }
688
- /** Span aninhado (filho deste span). */
712
+ /** Step aninhada (filha desta step). */
689
713
  startChild(op, description) {
690
- return this.transaction.createSpan(this.spanId, op, description);
714
+ return this.transaction.createStep(this.stepId, op, description);
691
715
  }
692
716
  finish() {
693
717
  if (this.endTimestamp) return;
694
718
  this.endTimestamp = nowISO();
695
- this.transaction.emit("span", "finish", spanLabel(this.op, this.description), this.startTimestamp, this.endTimestamp);
719
+ this.transaction.emit(
720
+ "step",
721
+ "finish",
722
+ stepLabel(this.op, this.description),
723
+ this.startTimestamp,
724
+ this.endTimestamp,
725
+ this.status
726
+ );
696
727
  }
697
728
  toJSON() {
698
729
  return {
699
- span_id: this.spanId,
700
- parent_span_id: this.parentSpanId,
730
+ step_id: this.stepId,
731
+ parent_step_id: this.parentStepId,
701
732
  op: this.op,
702
733
  description: this.description,
703
734
  status: this.status,
@@ -717,10 +748,10 @@ var Transaction = class {
717
748
  this.emit("transaction", "start", op ? `${name} (${op})` : name);
718
749
  }
719
750
  eventId = uuid4();
720
- spanId = spanId();
751
+ stepId = stepId();
721
752
  startTimestamp = nowISO();
722
753
  status = "ok";
723
- spans = [];
754
+ steps = [];
724
755
  tags = {};
725
756
  finished = false;
726
757
  lifecycleSink;
@@ -728,16 +759,16 @@ var Transaction = class {
728
759
  // antes do RunReporter conectar) — replay no setLifecycleSink
729
760
  lifecycleBacklog = [];
730
761
  /**
731
- * Ecoa no terminal o início/fim de um span ou transaction (sempre, independente de
762
+ * Ecoa no terminal o início/fim de uma step ou transaction (sempre, independente de
732
763
  * sampling ou do debug) e espelha a linha no sink de lifecycle, se conectado — é
733
764
  * assim que os eventos de performance também aparecem nos logs da run no app.
734
765
  */
735
- emit(kind, phase, label, startTs, endTs) {
766
+ emit(kind, phase, label, startTs, endTs, status) {
736
767
  const durationMs = startTs && endTs ? new Date(endTs).getTime() - new Date(startTs).getTime() : void 0;
737
- const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? "green" : "cyan");
768
+ const tag = colorize(`[hobots:${kind}] ${phase.toUpperCase()}`, phase === "finish" ? colorForStatus(status ?? "ok") : "cyan");
738
769
  const suffix = durationMs != null ? ` (${durationMs}ms)` : "";
739
770
  console.log(`${tag} ${label}${suffix}`);
740
- const level = phase === "finish" ? "success" : "info";
771
+ const level = phase === "finish" ? levelForStatus(status ?? "ok") : "info";
741
772
  const message = `[${kind}] ${phase.toUpperCase()} ${label}${suffix}`;
742
773
  if (this.lifecycleSink) this.lifecycleSink(level, message);
743
774
  else if (this.lifecycleBacklog.length < 100) this.lifecycleBacklog.push([level, message]);
@@ -749,15 +780,15 @@ var Transaction = class {
749
780
  this.lifecycleBacklog = [];
750
781
  for (const [level, message] of backlog) sink(level, message);
751
782
  }
752
- createSpan(parentSpanId, op, description) {
753
- const span = new Span(this, parentSpanId, op, description);
754
- this.spans.push(span);
755
- this.emit("span", "start", spanLabel(op, description));
756
- return span;
783
+ createStep(parentStepId, op, description) {
784
+ const step = new Step(this, parentStepId, op, description);
785
+ this.steps.push(step);
786
+ this.emit("step", "start", stepLabel(op, description));
787
+ return step;
757
788
  }
758
- /** Span direto da transaction. */
789
+ /** Step direta da transaction. */
759
790
  startChild(op, description) {
760
- return this.createSpan(this.spanId, op, description);
791
+ return this.createStep(this.stepId, op, description);
761
792
  }
762
793
  setTag(key, value) {
763
794
  this.tags[key] = value;
@@ -774,14 +805,15 @@ var Transaction = class {
774
805
  finish() {
775
806
  if (this.finished) return;
776
807
  this.finished = true;
777
- for (const span of this.spans) span.finish();
808
+ for (const step of this.steps) step.finish();
778
809
  const endTimestamp = nowISO();
779
810
  this.emit(
780
811
  "transaction",
781
812
  "finish",
782
813
  this.op ? `${this.name} (${this.op})` : this.name,
783
814
  this.startTimestamp,
784
- endTimestamp
815
+ endTimestamp,
816
+ this.status
785
817
  );
786
818
  if (!this.sampled || !this.client) return;
787
819
  const payload = {
@@ -791,7 +823,7 @@ var Transaction = class {
791
823
  status: this.status,
792
824
  start_timestamp: this.startTimestamp,
793
825
  timestamp: endTimestamp,
794
- spans: this.spans.map((span) => span.toJSON()),
826
+ steps: this.steps.map((step) => step.toJSON()),
795
827
  tags: Object.keys(this.tags).length > 0 ? this.tags : void 0,
796
828
  run_id: this.runId
797
829
  };
@@ -1622,7 +1654,7 @@ export {
1622
1654
  Client,
1623
1655
  DEFAULT_BASE_URL,
1624
1656
  Scope,
1625
- Span,
1657
+ Step,
1626
1658
  Transaction,
1627
1659
  addBreadcrumb,
1628
1660
  captureException,