hobots 2.3.0 → 2.4.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/dist/index.cjs CHANGED
@@ -161,7 +161,7 @@ function scrubSecrets(text) {
161
161
 
162
162
  // src/utils.ts
163
163
  var SDK_NAME = "hobots";
164
- var SDK_VERSION = true ? "2.3.0" : "0.0.0-dev";
164
+ var SDK_VERSION = true ? "2.4.0" : "0.0.0-dev";
165
165
  function isNode() {
166
166
  return typeof process !== "undefined" && typeof process.versions?.node === "string";
167
167
  }
@@ -515,7 +515,7 @@ var Client = class {
515
515
  ...event,
516
516
  type: hint?.type ?? event.type ?? scope2.type ?? "error",
517
517
  release: event.release ?? this.options.release,
518
- environment: event.environment ?? this.options.environment ?? "production",
518
+ environment: this.resolveEnvironment(event.environment),
519
519
  tags: Object.keys(tags).length > 0 ? tags : void 0,
520
520
  extra: Object.keys(extra).length > 0 ? extra : void 0,
521
521
  user: event.user ?? scope2.user,
@@ -530,7 +530,7 @@ var Client = class {
530
530
  payload: {
531
531
  ...payload,
532
532
  release: payload.release ?? this.options.release,
533
- environment: payload.environment ?? this.options.environment ?? "production",
533
+ environment: this.resolveEnvironment(payload.environment),
534
534
  tags: { ...this.options.tags, ...payload.tags }
535
535
  }
536
536
  });
@@ -538,9 +538,22 @@ var Client = class {
538
538
  sendHeartbeat(payload) {
539
539
  this.transport.enqueue({
540
540
  type: "heartbeat",
541
- payload: { ...payload, release: payload.release ?? this.options.release }
541
+ payload: {
542
+ ...payload,
543
+ release: payload.release ?? this.options.release,
544
+ // o ambiente viaja no beat: é assim que a instância se classifica no app
545
+ environment: this.resolveEnvironment(payload.environment)
546
+ }
542
547
  });
543
548
  }
549
+ /**
550
+ * Ambiente do item: o dele, senão o do init(), senão produção. Centralizado
551
+ * porque evento, transaction e heartbeat precisam responder igual — o servidor
552
+ * normaliza apelidos legados, então aqui basta repassar.
553
+ */
554
+ resolveEnvironment(value) {
555
+ return value ?? this.options.environment ?? "production";
556
+ }
544
557
  flush(timeoutMs) {
545
558
  return this.transport.flush(timeoutMs);
546
559
  }
@@ -1989,7 +2002,7 @@ function installShutdownHandlers(agent2) {
1989
2002
  }
1990
2003
 
1991
2004
  // src/tasks/agent.ts
1992
- var DEFAULT_POLL_INTERVAL_MS = 5e3;
2005
+ var DEFAULT_POLL_INTERVAL_MS = 2e3;
1993
2006
  var MIN_POLL_INTERVAL_MS = 1e3;
1994
2007
  var MAX_CONCURRENCY = 5;
1995
2008
  var POLL_RETRY_DELAYS_MS = [1e3, 4e3, 16e3];
@@ -2120,6 +2133,9 @@ var TaskAgent = class {
2120
2133
  instance_id: this.instanceId,
2121
2134
  version: SDK_VERSION,
2122
2135
  host: hostname(),
2136
+ // ambiente da instância: em agentes poll-only (sem heartbeat) este é o
2137
+ // único canal por onde o servidor descobre onde o robô está rodando
2138
+ environment: this.options.environment,
2123
2139
  tasks: [...this.registry.keys()],
2124
2140
  // o servidor calcula a tolerância de offline (3×) a partir disto em
2125
2141
  // agentes poll-only — sem o campo, um poll lento flaparia offline/online.
@@ -2309,7 +2325,7 @@ function init(options) {
2309
2325
  if (options.tasks) {
2310
2326
  const tasksOptions = options.tasks === true ? {} : options.tasks;
2311
2327
  agent = new TaskAgent(
2312
- { ...tasksOptions, config, instanceId: options.instanceId, debug: options.debug, client, machineSampler },
2328
+ { ...tasksOptions, config, instanceId: options.instanceId, environment: options.environment, debug: options.debug, client, machineSampler },
2313
2329
  registry
2314
2330
  );
2315
2331
  }