hobots 1.7.3 → 1.7.5

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.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, SpanStatus, RunLogLevel, SpanData, 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. */
@@ -112,7 +112,7 @@ declare class Transaction {
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' | 'span', phase: 'start' | 'finish', label: string, startTs?: string, endTs?: string, status?: SpanStatus | string): void;
116
116
  /** Conecta o espelho de lifecycle (RunReporter) e faz replay do backlog em ordem. */
117
117
  setLifecycleSink(sink: LifecycleSink): void;
118
118
  createSpan(parentSpanId: string, op?: string, description?: string): Span;
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.5" : "0.0.0-dev";
107
107
  function isNode() {
108
108
  return typeof process !== "undefined" && typeof process.versions?.node === "string";
109
109
  }
@@ -665,6 +665,30 @@ function spanId() {
665
665
  function spanLabel(op, description) {
666
666
  return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
667
667
  }
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
+ }
668
692
  var Span = class {
669
693
  constructor(transaction, parentSpanId, op, description) {
670
694
  this.transaction = transaction;
@@ -692,7 +716,14 @@ var Span = class {
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
+ "span",
721
+ "finish",
722
+ spanLabel(this.op, this.description),
723
+ this.startTimestamp,
724
+ this.endTimestamp,
725
+ this.status
726
+ );
696
727
  }
697
728
  toJSON() {
698
729
  return {
@@ -732,12 +763,12 @@ var Transaction = class {
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]);
@@ -781,7 +812,8 @@ var Transaction = class {
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 = {