risicare 0.8.0 → 0.9.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.
Files changed (72) hide show
  1. package/README.md +80 -21
  2. package/dist/frameworks/instructor.cjs +1 -1
  3. package/dist/frameworks/instructor.cjs.map +1 -1
  4. package/dist/frameworks/instructor.js +1 -1
  5. package/dist/frameworks/instructor.js.map +1 -1
  6. package/dist/frameworks/langchain.cjs +1 -1
  7. package/dist/frameworks/langchain.cjs.map +1 -1
  8. package/dist/frameworks/langchain.js +1 -1
  9. package/dist/frameworks/langchain.js.map +1 -1
  10. package/dist/frameworks/langgraph.cjs +1 -1
  11. package/dist/frameworks/langgraph.cjs.map +1 -1
  12. package/dist/frameworks/langgraph.js +1 -1
  13. package/dist/frameworks/langgraph.js.map +1 -1
  14. package/dist/frameworks/llamaindex.cjs +1 -1
  15. package/dist/frameworks/llamaindex.cjs.map +1 -1
  16. package/dist/frameworks/llamaindex.js +1 -1
  17. package/dist/frameworks/llamaindex.js.map +1 -1
  18. package/dist/index.cjs +131 -61
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +22 -8
  21. package/dist/index.d.ts +22 -8
  22. package/dist/index.js +131 -61
  23. package/dist/index.js.map +1 -1
  24. package/dist/providers/anthropic/index.cjs +1 -1
  25. package/dist/providers/anthropic/index.cjs.map +1 -1
  26. package/dist/providers/anthropic/index.js +1 -1
  27. package/dist/providers/anthropic/index.js.map +1 -1
  28. package/dist/providers/bedrock/index.cjs +1 -1
  29. package/dist/providers/bedrock/index.cjs.map +1 -1
  30. package/dist/providers/bedrock/index.js +1 -1
  31. package/dist/providers/bedrock/index.js.map +1 -1
  32. package/dist/providers/cerebras/index.cjs +1 -1
  33. package/dist/providers/cerebras/index.cjs.map +1 -1
  34. package/dist/providers/cerebras/index.js +1 -1
  35. package/dist/providers/cerebras/index.js.map +1 -1
  36. package/dist/providers/cohere/index.cjs +1 -1
  37. package/dist/providers/cohere/index.cjs.map +1 -1
  38. package/dist/providers/cohere/index.js +1 -1
  39. package/dist/providers/cohere/index.js.map +1 -1
  40. package/dist/providers/google/index.cjs +1 -1
  41. package/dist/providers/google/index.cjs.map +1 -1
  42. package/dist/providers/google/index.js +1 -1
  43. package/dist/providers/google/index.js.map +1 -1
  44. package/dist/providers/groq/index.cjs +1 -1
  45. package/dist/providers/groq/index.cjs.map +1 -1
  46. package/dist/providers/groq/index.js +1 -1
  47. package/dist/providers/groq/index.js.map +1 -1
  48. package/dist/providers/huggingface/index.cjs +1 -1
  49. package/dist/providers/huggingface/index.cjs.map +1 -1
  50. package/dist/providers/huggingface/index.js +1 -1
  51. package/dist/providers/huggingface/index.js.map +1 -1
  52. package/dist/providers/mistral/index.cjs +1 -1
  53. package/dist/providers/mistral/index.cjs.map +1 -1
  54. package/dist/providers/mistral/index.js +1 -1
  55. package/dist/providers/mistral/index.js.map +1 -1
  56. package/dist/providers/ollama/index.cjs +1 -1
  57. package/dist/providers/ollama/index.cjs.map +1 -1
  58. package/dist/providers/ollama/index.js +1 -1
  59. package/dist/providers/ollama/index.js.map +1 -1
  60. package/dist/providers/openai/index.cjs +1 -1
  61. package/dist/providers/openai/index.cjs.map +1 -1
  62. package/dist/providers/openai/index.js +1 -1
  63. package/dist/providers/openai/index.js.map +1 -1
  64. package/dist/providers/together/index.cjs +1 -1
  65. package/dist/providers/together/index.cjs.map +1 -1
  66. package/dist/providers/together/index.js +1 -1
  67. package/dist/providers/together/index.js.map +1 -1
  68. package/dist/providers/vercel-ai/index.cjs +1 -1
  69. package/dist/providers/vercel-ai/index.cjs.map +1 -1
  70. package/dist/providers/vercel-ai/index.js +1 -1
  71. package/dist/providers/vercel-ai/index.js.map +1 -1
  72. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -627,6 +627,18 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
627
627
  _started = false;
628
628
  _flushing = false;
629
629
  _inFlight = null;
630
+ /**
631
+ * The `shutdown()` that runs, or ran. A second `shutdown()` returns it, and a
632
+ * `flush()` that comes while it runs waits for it (inside its own deadline).
633
+ */
634
+ _closing = null;
635
+ /**
636
+ * True from the start of the drain of `shutdown()` until its loop ends and the
637
+ * residue is counted (no `await` between those two points). A span that ends
638
+ * in this time joins the drain. After it, the processor can take no span.
639
+ */
640
+ _drainOpen = false;
641
+ _lateSpanWarned = false;
630
642
  _beforeExitHandler = null;
631
643
  // Retry tracking for failed batches (Audit #5)
632
644
  _retryCounts = /* @__PURE__ */ new Map();
@@ -772,13 +784,21 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
772
784
  * Limit: the abort does not stop a TLS handshake that stalls. Measured, such a
773
785
  * handshake kept the process alive about 10 s after `shutdown()` returned.
774
786
  *
787
+ * A second call, while the first runs or after it ended, returns the promise
788
+ * of the first one. It does not return before the first drain ends.
789
+ *
775
790
  * @param timeoutMs - The budget (default 5000). See `normalizeTimeoutMs` for
776
791
  * the values that are not a finite number.
777
792
  */
778
- async shutdown(timeoutMs = SHUTDOWN_BUDGET_MS) {
779
- if (!this._started) return;
793
+ shutdown(timeoutMs = SHUTDOWN_BUDGET_MS) {
794
+ if (!this._started) return this._closing ?? Promise.resolve();
795
+ this._closing = this._shutdown(timeoutMs);
796
+ return this._closing;
797
+ }
798
+ async _shutdown(timeoutMs) {
780
799
  timeoutMs = normalizeTimeoutMs(timeoutMs);
781
800
  this._started = false;
801
+ this._drainOpen = true;
782
802
  if (this._timer) {
783
803
  clearInterval(this._timer);
784
804
  this._timer = null;
@@ -803,6 +823,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
803
823
  break;
804
824
  }
805
825
  }
826
+ this._drainOpen = false;
806
827
  const queued = this._queue.length;
807
828
  const flight = this._inFlight;
808
829
  const inFlight = flight !== null && !flight.abandoned ? flight.size : 0;
@@ -833,7 +854,14 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
833
854
  );
834
855
  }
835
856
  onSpanEnd(span) {
836
- if (!this._started) return;
857
+ if (!this._started) {
858
+ if (this._drainOpen) this._enqueue(span, false);
859
+ else if (this._closing !== null) this._lateSpan();
860
+ return;
861
+ }
862
+ this._enqueue(span, true);
863
+ }
864
+ _enqueue(span, exportAtBatchSize) {
837
865
  if (this._queue.length >= this._maxQueueSize) {
838
866
  this._recordDropped("queue_full");
839
867
  if (this.droppedSpans === 1 || this.droppedSpans % 1e3 === 0) {
@@ -842,10 +870,19 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
842
870
  return;
843
871
  }
844
872
  this._queue.push(span);
845
- if (this._queue.length >= this._batchSize) {
873
+ if (exportAtBatchSize && this._queue.length >= this._batchSize) {
846
874
  void this._exportBatch();
847
875
  }
848
876
  }
877
+ /** A span that ended after the drain ended: counted, with one WARNING for the first. */
878
+ _lateSpan() {
879
+ this._recordDropped("shutdown_residue");
880
+ if (this._lateSpanWarned) return;
881
+ this._lateSpanWarned = true;
882
+ warn(
883
+ "a span ended after shutdown() had stopped taking spans (reason=shutdown_residue). It was not delivered, and it is counted as dropped. Later spans of this kind are counted without a WARNING."
884
+ );
885
+ }
849
886
  /**
850
887
  * Flush pending spans.
851
888
  *
@@ -875,12 +912,22 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
875
912
  * loss. The flush after that answers `true` when nothing new was lost.
876
913
  *
877
914
  * Returns `false` in these cases:
878
- * (a) the deadline expires with spans still queued or in flight;
915
+ * (a) the deadline expires with spans still queued or in flight, or while a
916
+ * `shutdown()` that it waits for still runs;
879
917
  * (b) a span was discarded since the previous flush returned: queue full,
880
- * breaker refusal, retry exhaustion, or an ack that did not account
881
- * for it or a span that could not be serialized (`unacknowledged`);
882
- * (c) the backend rejected a span since the previous flush returned;
883
- * (d) it is called after `shutdown()`, and the shutdown residue was not 0.
918
+ * breaker refusal, retry exhaustion, spans that `shutdown()` left
919
+ * (`shutdown_residue`), or an ack that did not account for it or a span
920
+ * that could not be serialized (`unacknowledged`);
921
+ * (c) the backend rejected a span since the previous flush returned.
922
+ *
923
+ * A `flush()` that comes while a `shutdown()` runs (the SDK's own drain at
924
+ * SIGTERM or SIGINT, or a `shutdown()` that nobody awaited) waits for that
925
+ * shutdown, inside its OWN deadline, and then answers from the final tally with
926
+ * the same loss mark. After `shutdown()` it answers from the final tally in the
927
+ * same way. Through 0.8.0 both answered from the empty queue: true in 0 ms,
928
+ * with the batch in flight, and true after a rejection or a `transport_refused`
929
+ * drop. A loss that `shutdown()` counts (also `shutdown_residue`) makes ONE
930
+ * `flush()` false, as every other loss does.
884
931
  *
885
932
  * The deadline is a hard wall-clock bound on the WAIT. At the deadline
886
933
  * `flush()` returns `false`. Through 0.7.1 the deadline was checked only
@@ -903,9 +950,6 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
903
950
  */
904
951
  async flush(timeoutMs = SHUTDOWN_BUDGET_MS) {
905
952
  timeoutMs = normalizeTimeoutMs(timeoutMs);
906
- if (!this._started) {
907
- return this._queue.length === 0 && this.droppedSpansByReason.shutdown_residue === 0;
908
- }
909
953
  const deadline = Date.now() + timeoutMs;
910
954
  const mark = this._lossMark;
911
955
  const finish = (settled) => {
@@ -913,6 +957,14 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
913
957
  this._lossMark = Math.max(this._lossMark, lost);
914
958
  return settled && lost === mark;
915
959
  };
960
+ if (!this._started) {
961
+ if (this._closing !== null) {
962
+ const closed = await raceDeadline(this._closing.catch(() => void 0), timeoutMs);
963
+ if (closed === DEADLINE) return finish(false);
964
+ }
965
+ const held = this._inFlight !== null && !this._inFlight.abandoned;
966
+ return finish(this._queue.length === 0 && !held);
967
+ }
916
968
  while (this._queue.length > 0 || this._flushing) {
917
969
  const remaining = deadline - Date.now();
918
970
  if (remaining <= 0) return finish(false);
@@ -1117,7 +1169,7 @@ function resolveEndpoints(endpointOption, apiEndpointOption, envEndpoint, envApi
1117
1169
  }
1118
1170
  function resolveConfig(config) {
1119
1171
  const env = process.env;
1120
- const apiKey = config?.apiKey ?? env.RISICARE_API_KEY;
1172
+ const apiKey = keyText(config?.apiKey) || keyText(env.RISICARE_API_KEY) || void 0;
1121
1173
  const { endpoint, apiEndpoint } = resolveEndpoints(
1122
1174
  config?.endpoint,
1123
1175
  config?.apiEndpoint,
@@ -1159,6 +1211,7 @@ function resolveConfig(config) {
1159
1211
  } else {
1160
1212
  enabled = !!apiKey;
1161
1213
  }
1214
+ if (!apiKey) enabled = false;
1162
1215
  return hideKeyFromInspect({
1163
1216
  apiKey: apiKey ?? "",
1164
1217
  endpoint,
@@ -1209,6 +1262,14 @@ function tracingFromEnv(value) {
1209
1262
  );
1210
1263
  return false;
1211
1264
  }
1265
+ function keyText(value) {
1266
+ return typeof value === "string" ? value.trim() : "";
1267
+ }
1268
+ function tracingTurnedOff(config) {
1269
+ if (config?.enabled !== void 0) return config.enabled === false;
1270
+ const v = (process.env.RISICARE_TRACING ?? "").trim().toLowerCase();
1271
+ return v !== "" && !TRACING_ON.has(v);
1272
+ }
1212
1273
  function parseNumericEnv(value, defaultValue) {
1213
1274
  if (value === void 0) return defaultValue;
1214
1275
  const n = Number(value);
@@ -2329,7 +2390,7 @@ function markCancel(span, error) {
2329
2390
  }
2330
2391
 
2331
2392
  // src/version.ts
2332
- var SDK_VERSION = "0.8.0";
2393
+ var SDK_VERSION = "0.9.0";
2333
2394
 
2334
2395
  // src/exporters/http.ts
2335
2396
  var CAPACITY_REFUSAL_STATUSES = /* @__PURE__ */ new Set([429, 503]);
@@ -2767,27 +2828,6 @@ async function checkAck(response, spansSent, scrub) {
2767
2828
  return { result: "success" /* SUCCESS */, counts, final: false };
2768
2829
  }
2769
2830
 
2770
- // src/exporters/console.ts
2771
- var ConsoleExporter = class {
2772
- name = "console";
2773
- /**
2774
- * It only shows spans locally, so its success is not a delivery. When another
2775
- * exporter is present, the batch processor ignores this exporter's result.
2776
- */
2777
- countsAsDelivery = false;
2778
- export(spans) {
2779
- for (const span of spans) {
2780
- const payload = span.toPayload();
2781
- const line = JSON.stringify(payload);
2782
- process.stderr.write(`[risicare] ${line}
2783
- `);
2784
- }
2785
- return "success" /* SUCCESS */;
2786
- }
2787
- shutdown() {
2788
- }
2789
- };
2790
-
2791
2831
  // src/utils/stream-proxy.ts
2792
2832
  function endOpenProviderSpans() {
2793
2833
  let open;
@@ -3980,6 +4020,8 @@ var TERMINATING_SIGNALS = [
3980
4020
  ];
3981
4021
  var BACKSTOP_MARGIN_MS = 500;
3982
4022
  var _finalMetrics;
4023
+ var _finalProcessor;
4024
+ var _finalActive = false;
3983
4025
  var SCORE_TIMEOUT_MS = 2e3;
3984
4026
  var _pendingScores = /* @__PURE__ */ new Set();
3985
4027
  var _failedScores = 0;
@@ -4060,6 +4102,13 @@ var RisicareClient = class {
4060
4102
  * this flag `getMetrics()` would keep reporting `"running"` over a processor
4061
4103
  * that has already been torn down. */
4062
4104
  isShutdown = false;
4105
+ /**
4106
+ * Tracing was on at `init()` or since `enable()`. A client that never was
4107
+ * (no key, or tracing off) accepted nothing, and delivered nothing: its
4108
+ * `flush()` is false. `disable()` does not clear it: spans that were accepted
4109
+ * before keep their answer.
4110
+ */
4111
+ _activated = false;
4063
4112
  _shutdownPromise;
4064
4113
  _shutdownHandlers = [];
4065
4114
  constructor(config) {
@@ -4070,16 +4119,13 @@ var RisicareClient = class {
4070
4119
  'the API key does not look like a Risicare key: it should start with "rsk-", "rski_" or "rsks_". Tracing continues with this key.'
4071
4120
  );
4072
4121
  }
4073
- const tracingSetExplicitly = config?.enabled !== void 0 || (process.env.RISICARE_TRACING ?? "").trim() !== "";
4074
- if (!this.config.apiKey && !this.config.enabled && !tracingSetExplicitly) {
4122
+ if (!this.config.apiKey && !tracingTurnedOff(config)) {
4075
4123
  warn(
4076
- "Risicare found no API key. Tracing is off and the SDK sends no span. Pass apiKey to init() or set RISICARE_API_KEY."
4124
+ "Risicare found no API key. Nothing is sent to Risicare: tracing is off, no span is created, and flush() returns false. Set the RISICARE_API_KEY environment variable, or pass apiKey to init()."
4077
4125
  );
4078
4126
  }
4079
4127
  let exporter;
4080
- if (this.config.debug && !this.config.apiKey) {
4081
- exporter = new ConsoleExporter();
4082
- } else if (this.config.apiKey) {
4128
+ if (this.config.apiKey) {
4083
4129
  exporter = new HttpExporter({
4084
4130
  endpoint: this.config.endpoint,
4085
4131
  apiKey: this.config.apiKey,
@@ -4087,16 +4133,6 @@ var RisicareClient = class {
4087
4133
  environment: this.config.environment || void 0,
4088
4134
  compress: this.config.compress
4089
4135
  });
4090
- } else {
4091
- exporter = void 0;
4092
- if (this.config.enabled) {
4093
- try {
4094
- console.warn(
4095
- `[risicare] tracing is enabled but NO API key is configured \u2014 spans are created and then DROPPED, not sent to ${this.config.endpoint}. Pass apiKey to init() (or set the RISICARE_API_KEY env var). Span data is NOT written to the console: it would be unredacted. Pass debug:true if you want console output for local development.`
4096
- );
4097
- } catch {
4098
- }
4099
- }
4100
4136
  }
4101
4137
  this.processor = new BatchSpanProcessor({
4102
4138
  exporters: exporter ? [exporter] : [],
@@ -4127,6 +4163,7 @@ var RisicareClient = class {
4127
4163
  serviceName: this.config.serviceName,
4128
4164
  serviceVersion: this.config.serviceVersion
4129
4165
  });
4166
+ this._activated = this.tracer.enabled;
4130
4167
  this.processor.start();
4131
4168
  if (this.config.apiKey && this.config.enabled && this.config.fixRuntime) {
4132
4169
  try {
@@ -4165,7 +4202,12 @@ var RisicareClient = class {
4165
4202
  return this.tracer.enabled;
4166
4203
  }
4167
4204
  set enabled(value) {
4205
+ if (value && !this.config.apiKey) {
4206
+ debug("enable() ignored: no API key is configured, so tracing stays off");
4207
+ return;
4208
+ }
4168
4209
  this.tracer.enabled = value;
4210
+ if (value) this._activated = true;
4169
4211
  }
4170
4212
  // Audit #6: Promise-based shutdown dedup (fixes TOCTOU race condition)
4171
4213
  async shutdown(timeoutMs) {
@@ -4184,6 +4226,8 @@ var RisicareClient = class {
4184
4226
  _failWaitingScores(SCORE_DEADLINE_REASON);
4185
4227
  this.isShutdown = true;
4186
4228
  _finalMetrics = this.processor.getMetrics();
4229
+ _finalProcessor = this.processor;
4230
+ _finalActive = this._activated;
4187
4231
  }
4188
4232
  /**
4189
4233
  * Flush pending spans.
@@ -4197,6 +4241,7 @@ var RisicareClient = class {
4197
4241
  * *discarded*.
4198
4242
  */
4199
4243
  async flush(timeoutMs) {
4244
+ if (!this._activated) return false;
4200
4245
  return this.processor.flush(timeoutMs);
4201
4246
  }
4202
4247
  /**
@@ -4223,6 +4268,19 @@ var RisicareClient = class {
4223
4268
  * * **A prior listener exists.** The application took ownership before the
4224
4269
  * SDK loaded. We drain and RETURN; termination was never ours to decide,
4225
4270
  * and forcing it would cut off the app's own graceful shutdown.
4271
+ * * **A listener that the application adds after `init()`.** Node calls ours
4272
+ * first. The question is asked when OUR listener starts, at signal time:
4273
+ * is there another listener for this signal? If there is, it owns
4274
+ * termination as well: when the drain ends we do not raise the signal
4275
+ * again, and we do not arm the fail-safe exit. Its listener runs once and
4276
+ * decides the exit, in the same way as when it was registered before
4277
+ * `init()`. Through 0.8.0 the re-raise ran it a second time, and the
4278
+ * fail-safe ended the process with code 143, 100 ms later.
4279
+ * * **A listener that the application adds DURING the drain.** There was none
4280
+ * at signal time, so the 0.8.0 rule holds: after the drain we raise the
4281
+ * signal again, and that listener runs on it, and the process ends (fail-safe
4282
+ * after 100 ms if it does not). A count taken after the drain would have
4283
+ * counted that listener, and nothing would have run or ended the process.
4226
4284
  *
4227
4285
  * ⚠ `beforeExit` is deliberately NOT in that logic. It is not a signal and
4228
4286
  * carries no termination the SDK could displace — the loop has already
@@ -4238,6 +4296,7 @@ var RisicareClient = class {
4238
4296
  for (const [signal, signum] of TERMINATING_SIGNALS) {
4239
4297
  const weDisplacedDefault = process.listenerCount(signal) === 0;
4240
4298
  const handler = () => {
4299
+ const othersAtSignal = process.listeners(signal).filter((l) => l !== handler).length;
4241
4300
  const backstop = setTimeout(
4242
4301
  () => process.exit(128 + signum),
4243
4302
  SHUTDOWN_BUDGET_MS + BACKSTOP_MARGIN_MS
@@ -4247,6 +4306,7 @@ var RisicareClient = class {
4247
4306
  }).finally(() => {
4248
4307
  clearTimeout(backstop);
4249
4308
  if (!weDisplacedDefault) return;
4309
+ if (othersAtSignal > 0) return;
4250
4310
  try {
4251
4311
  process.kill(process.pid, signal);
4252
4312
  } catch {
@@ -4295,6 +4355,8 @@ function init(config) {
4295
4355
  return;
4296
4356
  }
4297
4357
  _finalMetrics = void 0;
4358
+ _finalProcessor = void 0;
4359
+ _finalActive = false;
4298
4360
  _resetScoreFailures();
4299
4361
  const client = new RisicareClient(config);
4300
4362
  setClient(client);
@@ -4317,10 +4379,12 @@ async function flush(timeoutMs) {
4317
4379
  const scoreMark = _failedScoresFlushMark;
4318
4380
  const client = getClient();
4319
4381
  let spansOk;
4320
- if (!client) {
4321
- spansOk = (_finalMetrics?.droppedSpansByReason.shutdown_residue ?? 0) === 0;
4322
- } else {
4382
+ if (client) {
4323
4383
  spansOk = await client.flush(timeoutMs);
4384
+ } else if (_finalProcessor) {
4385
+ spansOk = _finalActive && await _finalProcessor.flush(timeoutMs);
4386
+ } else {
4387
+ spansOk = false;
4324
4388
  }
4325
4389
  const scoresDone = await _waitForPendingScores(deadline - Date.now());
4326
4390
  if (!scoresDone) _failWaitingScores(SCORE_DEADLINE_REASON);
@@ -4339,7 +4403,7 @@ function disable() {
4339
4403
  }
4340
4404
  function isEnabled() {
4341
4405
  const client = getClient();
4342
- return client?.enabled ?? false;
4406
+ return client !== void 0 && !client.isShutdown && client.enabled;
4343
4407
  }
4344
4408
  function getTracer2() {
4345
4409
  return getTracer();
@@ -4358,10 +4422,11 @@ function getMetrics() {
4358
4422
  };
4359
4423
  }
4360
4424
  if (_finalMetrics) {
4425
+ const tally = _finalProcessor?.getMetrics() ?? _finalMetrics;
4361
4426
  return {
4362
- ..._finalMetrics,
4427
+ ...tally,
4363
4428
  failedScores: _failedScores,
4364
- droppedSpansByReason: { ..._finalMetrics.droppedSpansByReason },
4429
+ droppedSpansByReason: { ...tally.droppedSpansByReason },
4365
4430
  sdkState: "shutdown"
4366
4431
  };
4367
4432
  }
@@ -4433,24 +4498,29 @@ function reportError(error, options) {
4433
4498
  debug("reportError failed");
4434
4499
  }
4435
4500
  }
4501
+ function refuseScore(message) {
4502
+ warn(message);
4503
+ const client = getClient();
4504
+ if (client && !client.isShutdown && client.enabled && client.config.apiKey) _failedScores += 1;
4505
+ }
4436
4506
  function score(traceId, name, value, options) {
4437
4507
  try {
4438
4508
  const raw = value;
4439
4509
  if (typeof raw === "boolean") value = raw ? 1 : 0;
4440
4510
  if (typeof value !== "number") {
4441
- warn(`score: the value must be a number, not ${typeof raw}. The SDK does not send this score.`);
4511
+ refuseScore(`score: the value must be a number, not ${typeof raw}. The SDK does not send this score.`);
4442
4512
  return;
4443
4513
  }
4444
4514
  if (!Number.isFinite(value) || value < 0 || value > 1) {
4445
- warn(`score: the value must be in [0.0, 1.0], not ${value}. The SDK does not send this score.`);
4515
+ refuseScore(`score: the value must be in [0.0, 1.0], not ${value}. The SDK does not send this score.`);
4446
4516
  return;
4447
4517
  }
4448
4518
  if (typeof traceId !== "string" || given(traceId) === void 0) {
4449
- warn("score: traceId must be a non-empty string. The SDK does not send this score.");
4519
+ refuseScore("score: traceId must be a non-empty string. The SDK does not send this score.");
4450
4520
  return;
4451
4521
  }
4452
4522
  if (typeof name !== "string" || given(name) === void 0) {
4453
- warn("score: name must be a non-empty string. The SDK does not send this score.");
4523
+ refuseScore("score: name must be a non-empty string. The SDK does not send this score.");
4454
4524
  return;
4455
4525
  }
4456
4526
  const client = getClient();