hobots 1.7.4 → 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.cjs CHANGED
@@ -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.2" : "0.0.0-dev";
166
+ var SDK_VERSION = true ? "1.7.5" : "0.0.0-dev";
167
167
  function isNode() {
168
168
  return typeof process !== "undefined" && typeof process.versions?.node === "string";
169
169
  }
@@ -725,6 +725,30 @@ function spanId() {
725
725
  function spanLabel(op, description) {
726
726
  return [op, description].filter(Boolean).join(" \u2014 ") || "(sem nome)";
727
727
  }
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
+ }
728
752
  var Span = class {
729
753
  constructor(transaction, parentSpanId, op, description) {
730
754
  this.transaction = transaction;
@@ -752,7 +776,14 @@ var Span = class {
752
776
  finish() {
753
777
  if (this.endTimestamp) return;
754
778
  this.endTimestamp = nowISO();
755
- this.transaction.emit("span", "finish", spanLabel(this.op, this.description), this.startTimestamp, this.endTimestamp);
779
+ this.transaction.emit(
780
+ "span",
781
+ "finish",
782
+ spanLabel(this.op, this.description),
783
+ this.startTimestamp,
784
+ this.endTimestamp,
785
+ this.status
786
+ );
756
787
  }
757
788
  toJSON() {
758
789
  return {
@@ -792,12 +823,12 @@ var Transaction = class {
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" ? "green" : "cyan");
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" ? "success" : "info";
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]);
@@ -841,7 +872,8 @@ var Transaction = class {
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 = {