risicare 0.9.0 → 0.9.1
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/README.md +18 -0
- package/dist/frameworks/instructor.cjs +144 -2
- package/dist/frameworks/instructor.cjs.map +1 -1
- package/dist/frameworks/instructor.js +144 -2
- package/dist/frameworks/instructor.js.map +1 -1
- package/dist/frameworks/langchain.cjs +144 -2
- package/dist/frameworks/langchain.cjs.map +1 -1
- package/dist/frameworks/langchain.js +144 -2
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/frameworks/langgraph.cjs +144 -2
- package/dist/frameworks/langgraph.cjs.map +1 -1
- package/dist/frameworks/langgraph.js +144 -2
- package/dist/frameworks/langgraph.js.map +1 -1
- package/dist/frameworks/llamaindex.cjs +144 -2
- package/dist/frameworks/llamaindex.cjs.map +1 -1
- package/dist/frameworks/llamaindex.js +144 -2
- package/dist/frameworks/llamaindex.js.map +1 -1
- package/dist/index.cjs +199 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +199 -7
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/index.cjs +144 -2
- package/dist/providers/anthropic/index.cjs.map +1 -1
- package/dist/providers/anthropic/index.js +144 -2
- package/dist/providers/anthropic/index.js.map +1 -1
- package/dist/providers/bedrock/index.cjs +144 -2
- package/dist/providers/bedrock/index.cjs.map +1 -1
- package/dist/providers/bedrock/index.js +144 -2
- package/dist/providers/bedrock/index.js.map +1 -1
- package/dist/providers/cerebras/index.cjs +144 -2
- package/dist/providers/cerebras/index.cjs.map +1 -1
- package/dist/providers/cerebras/index.js +144 -2
- package/dist/providers/cerebras/index.js.map +1 -1
- package/dist/providers/cohere/index.cjs +144 -2
- package/dist/providers/cohere/index.cjs.map +1 -1
- package/dist/providers/cohere/index.js +144 -2
- package/dist/providers/cohere/index.js.map +1 -1
- package/dist/providers/google/index.cjs +144 -2
- package/dist/providers/google/index.cjs.map +1 -1
- package/dist/providers/google/index.js +144 -2
- package/dist/providers/google/index.js.map +1 -1
- package/dist/providers/groq/index.cjs +144 -2
- package/dist/providers/groq/index.cjs.map +1 -1
- package/dist/providers/groq/index.js +144 -2
- package/dist/providers/groq/index.js.map +1 -1
- package/dist/providers/huggingface/index.cjs +144 -2
- package/dist/providers/huggingface/index.cjs.map +1 -1
- package/dist/providers/huggingface/index.js +144 -2
- package/dist/providers/huggingface/index.js.map +1 -1
- package/dist/providers/mistral/index.cjs +144 -2
- package/dist/providers/mistral/index.cjs.map +1 -1
- package/dist/providers/mistral/index.js +144 -2
- package/dist/providers/mistral/index.js.map +1 -1
- package/dist/providers/ollama/index.cjs +144 -2
- package/dist/providers/ollama/index.cjs.map +1 -1
- package/dist/providers/ollama/index.js +144 -2
- package/dist/providers/ollama/index.js.map +1 -1
- package/dist/providers/openai/index.cjs +144 -2
- package/dist/providers/openai/index.cjs.map +1 -1
- package/dist/providers/openai/index.js +144 -2
- package/dist/providers/openai/index.js.map +1 -1
- package/dist/providers/together/index.cjs +144 -2
- package/dist/providers/together/index.cjs.map +1 -1
- package/dist/providers/together/index.js +144 -2
- package/dist/providers/together/index.js.map +1 -1
- package/dist/providers/vercel-ai/index.cjs +144 -2
- package/dist/providers/vercel-ai/index.cjs.map +1 -1
- package/dist/providers/vercel-ai/index.js +144 -2
- package/dist/providers/vercel-ai/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -566,7 +566,7 @@ declare function getTracer(): Tracer$1 | undefined;
|
|
|
566
566
|
declare function getTraceContent(): boolean;
|
|
567
567
|
/**
|
|
568
568
|
* Get SDK metrics: exported spans (accepted by the backend), `rejectedSpans`,
|
|
569
|
-
* dropped spans and their reasons (`unacknowledged` included), failed exports,
|
|
569
|
+
* dropped spans and their reasons (`unacknowledged` and `quota_exceeded` included; `droppedQuota` is the latter), failed exports,
|
|
570
570
|
* queue stats, and `failedScores` (`score()` requests that failed since
|
|
571
571
|
* `init()`).
|
|
572
572
|
*
|
|
@@ -602,7 +602,9 @@ declare function getMetrics(): {
|
|
|
602
602
|
transport_refused: number;
|
|
603
603
|
shutdown_residue: number;
|
|
604
604
|
unacknowledged: number;
|
|
605
|
+
quota_exceeded: number;
|
|
605
606
|
};
|
|
607
|
+
droppedQuota: number;
|
|
606
608
|
failedExports: number;
|
|
607
609
|
maskErrors: number;
|
|
608
610
|
queueSize: number;
|
|
@@ -615,11 +617,13 @@ declare function getMetrics(): {
|
|
|
615
617
|
transport_refused: number;
|
|
616
618
|
shutdown_residue: number;
|
|
617
619
|
unacknowledged: number;
|
|
620
|
+
quota_exceeded: number;
|
|
618
621
|
};
|
|
619
622
|
sdkState: "shutdown";
|
|
620
623
|
exportedSpans: number;
|
|
621
624
|
rejectedSpans: number;
|
|
622
625
|
droppedSpans: number;
|
|
626
|
+
droppedQuota: number;
|
|
623
627
|
failedExports: number;
|
|
624
628
|
maskErrors: number;
|
|
625
629
|
queueSize: number;
|
|
@@ -635,7 +639,9 @@ declare function getMetrics(): {
|
|
|
635
639
|
transport_refused: number;
|
|
636
640
|
shutdown_residue: number;
|
|
637
641
|
unacknowledged: number;
|
|
642
|
+
quota_exceeded: number;
|
|
638
643
|
};
|
|
644
|
+
droppedQuota: number;
|
|
639
645
|
failedExports: number;
|
|
640
646
|
queueSize: number;
|
|
641
647
|
queueCapacity: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -566,7 +566,7 @@ declare function getTracer(): Tracer$1 | undefined;
|
|
|
566
566
|
declare function getTraceContent(): boolean;
|
|
567
567
|
/**
|
|
568
568
|
* Get SDK metrics: exported spans (accepted by the backend), `rejectedSpans`,
|
|
569
|
-
* dropped spans and their reasons (`unacknowledged` included), failed exports,
|
|
569
|
+
* dropped spans and their reasons (`unacknowledged` and `quota_exceeded` included; `droppedQuota` is the latter), failed exports,
|
|
570
570
|
* queue stats, and `failedScores` (`score()` requests that failed since
|
|
571
571
|
* `init()`).
|
|
572
572
|
*
|
|
@@ -602,7 +602,9 @@ declare function getMetrics(): {
|
|
|
602
602
|
transport_refused: number;
|
|
603
603
|
shutdown_residue: number;
|
|
604
604
|
unacknowledged: number;
|
|
605
|
+
quota_exceeded: number;
|
|
605
606
|
};
|
|
607
|
+
droppedQuota: number;
|
|
606
608
|
failedExports: number;
|
|
607
609
|
maskErrors: number;
|
|
608
610
|
queueSize: number;
|
|
@@ -615,11 +617,13 @@ declare function getMetrics(): {
|
|
|
615
617
|
transport_refused: number;
|
|
616
618
|
shutdown_residue: number;
|
|
617
619
|
unacknowledged: number;
|
|
620
|
+
quota_exceeded: number;
|
|
618
621
|
};
|
|
619
622
|
sdkState: "shutdown";
|
|
620
623
|
exportedSpans: number;
|
|
621
624
|
rejectedSpans: number;
|
|
622
625
|
droppedSpans: number;
|
|
626
|
+
droppedQuota: number;
|
|
623
627
|
failedExports: number;
|
|
624
628
|
maskErrors: number;
|
|
625
629
|
queueSize: number;
|
|
@@ -635,7 +639,9 @@ declare function getMetrics(): {
|
|
|
635
639
|
transport_refused: number;
|
|
636
640
|
shutdown_residue: number;
|
|
637
641
|
unacknowledged: number;
|
|
642
|
+
quota_exceeded: number;
|
|
638
643
|
};
|
|
644
|
+
droppedQuota: number;
|
|
639
645
|
failedExports: number;
|
|
640
646
|
queueSize: number;
|
|
641
647
|
queueCapacity: number;
|
package/dist/index.js
CHANGED
|
@@ -86,6 +86,10 @@ function warn(msg) {
|
|
|
86
86
|
process.stderr.write(`[risicare] WARNING: ${msg}
|
|
87
87
|
`);
|
|
88
88
|
}
|
|
89
|
+
function info(msg) {
|
|
90
|
+
process.stderr.write(`[risicare] INFO: ${msg}
|
|
91
|
+
`);
|
|
92
|
+
}
|
|
89
93
|
|
|
90
94
|
// src/utils/text.ts
|
|
91
95
|
function cutCodePoints(text, max) {
|
|
@@ -586,7 +590,8 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
586
590
|
queue_full: 0,
|
|
587
591
|
transport_refused: 0,
|
|
588
592
|
shutdown_residue: 0,
|
|
589
|
-
unacknowledged: 0
|
|
593
|
+
unacknowledged: 0,
|
|
594
|
+
quota_exceeded: 0
|
|
590
595
|
};
|
|
591
596
|
exportedSpans = 0;
|
|
592
597
|
/**
|
|
@@ -755,9 +760,15 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
755
760
|
if (residue > 0) {
|
|
756
761
|
this._queue.length = 0;
|
|
757
762
|
this._recordDropped("shutdown_residue", residue);
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
763
|
+
if (this._quotaPaused()) {
|
|
764
|
+
warn(
|
|
765
|
+
`shutdown() gave up with ${residue} span(s) (reason=shutdown_residue): ${queued} still queued and ${inFlight} in an export that shutdown() stopped. The monthly event quota is used up and export is paused until the next probe, so these spans could not be sent. A longer shutdown timeout does not help. Upgrade the plan or wait for the quota to reset.`
|
|
766
|
+
);
|
|
767
|
+
} else {
|
|
768
|
+
warn(
|
|
769
|
+
`shutdown() gave up with ${residue} span(s) (reason=shutdown_residue): ${queued} still queued and ${inFlight} in an export that shutdown() stopped. ` + (inFlight > 0 ? `The server may have received the ${inFlight} span(s) of the stopped export. ` : "") + `All ${residue} were not confirmed as delivered, and are counted as dropped. The ${timeoutMs} ms shutdown budget expired or the transport stopped accepting. Pass a larger timeout to shutdown(timeoutMs), or raise your container's termination grace period, to lose less.`
|
|
770
|
+
);
|
|
771
|
+
}
|
|
761
772
|
}
|
|
762
773
|
for (const exporter of this._exporters) {
|
|
763
774
|
await shutdownExporter(exporter, Math.max(0, shutdownDeadline - Date.now()));
|
|
@@ -777,6 +788,19 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
777
788
|
}
|
|
778
789
|
_enqueue(span, exportAtBatchSize) {
|
|
779
790
|
if (this._queue.length >= this._maxQueueSize) {
|
|
791
|
+
if (this._quotaPaused()) {
|
|
792
|
+
const oldest = this._queue.shift();
|
|
793
|
+
if (oldest !== void 0) this._retryCounts.delete(oldest.spanId);
|
|
794
|
+
this._recordDropped("quota_exceeded");
|
|
795
|
+
for (const exporter of this._exporters) {
|
|
796
|
+
try {
|
|
797
|
+
exporter.noteQuotaDrop?.(1);
|
|
798
|
+
} catch {
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
this._queue.push(span);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
780
804
|
this._recordDropped("queue_full");
|
|
781
805
|
if (this.droppedSpans === 1 || this.droppedSpans % 1e3 === 0) {
|
|
782
806
|
warn(`Span queue full (${this._maxQueueSize}). ${this.droppedSpans} spans dropped so far.`);
|
|
@@ -788,6 +812,22 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
788
812
|
void this._exportBatch();
|
|
789
813
|
}
|
|
790
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* True when every exporter that delivers is paused for the monthly quota (S-1). An exporter
|
|
817
|
+
* says so with `quotaPaused()`. A custom exporter has none: not paused.
|
|
818
|
+
*/
|
|
819
|
+
_quotaPaused() {
|
|
820
|
+
const deciders = this._exporters.filter((e) => e.countsAsDelivery !== false);
|
|
821
|
+
if (deciders.length === 0) return false;
|
|
822
|
+
for (const exporter of deciders) {
|
|
823
|
+
try {
|
|
824
|
+
if (exporter.quotaPaused?.() !== true) return false;
|
|
825
|
+
} catch {
|
|
826
|
+
return false;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
791
831
|
/** A span that ended after the drain ended: counted, with one WARNING for the first. */
|
|
792
832
|
_lateSpan() {
|
|
793
833
|
this._recordDropped("shutdown_residue");
|
|
@@ -882,9 +922,11 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
882
922
|
while (this._queue.length > 0 || this._flushing) {
|
|
883
923
|
const remaining = deadline - Date.now();
|
|
884
924
|
if (remaining <= 0) return finish(false);
|
|
925
|
+
if (!this._flushing && this._queue.length > 0 && this._quotaPaused()) return finish(false);
|
|
885
926
|
if (!this._flushing && this._queue.length > 0) {
|
|
886
927
|
const outcome = await raceDeadline(this._exportBatch(), remaining);
|
|
887
928
|
if (outcome === DEADLINE) return finish(false);
|
|
929
|
+
if (outcome === 4 /* Paused */) await new Promise((r) => setTimeout(r, 20));
|
|
888
930
|
} else {
|
|
889
931
|
await new Promise((r) => setTimeout(r, 1));
|
|
890
932
|
}
|
|
@@ -897,6 +939,9 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
897
939
|
rejectedSpans: this.rejectedSpans,
|
|
898
940
|
droppedSpans: this.droppedSpans,
|
|
899
941
|
droppedSpansByReason: { ...this.droppedSpansByReason },
|
|
942
|
+
// Spans dropped because the monthly event quota is used up (S-1). The same number as
|
|
943
|
+
// `droppedSpansByReason.quota_exceeded`, for a reader that wants one key.
|
|
944
|
+
droppedQuota: this.droppedSpansByReason.quota_exceeded,
|
|
900
945
|
failedExports: this.failedExports,
|
|
901
946
|
maskErrors: this.maskErrors,
|
|
902
947
|
queueSize: this._queue.length,
|
|
@@ -918,6 +963,12 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
918
963
|
this.exportedSpans += n;
|
|
919
964
|
return;
|
|
920
965
|
}
|
|
966
|
+
const quota = Math.min(Math.max(ack.quotaDropped ?? 0, 0), n);
|
|
967
|
+
if (quota > 0) {
|
|
968
|
+
this._recordDropped("quota_exceeded", quota);
|
|
969
|
+
n -= quota;
|
|
970
|
+
if (n === 0) return;
|
|
971
|
+
}
|
|
921
972
|
const rejected = Math.min(ack.rejected, n);
|
|
922
973
|
const accepted = Math.min(ack.accepted, n - rejected);
|
|
923
974
|
const unacknowledged = n - accepted - rejected;
|
|
@@ -952,6 +1003,7 @@ var BatchSpanProcessor = class _BatchSpanProcessor {
|
|
|
952
1003
|
async _exportBatch() {
|
|
953
1004
|
if (this._flushing) return 3 /* Busy */;
|
|
954
1005
|
if (this._queue.length === 0) return 0 /* Empty */;
|
|
1006
|
+
if (this._quotaPaused()) return 4 /* Paused */;
|
|
955
1007
|
this._flushing = true;
|
|
956
1008
|
let flight = null;
|
|
957
1009
|
try {
|
|
@@ -2304,7 +2356,111 @@ function markCancel(span, error) {
|
|
|
2304
2356
|
}
|
|
2305
2357
|
|
|
2306
2358
|
// src/version.ts
|
|
2307
|
-
var SDK_VERSION = "0.9.
|
|
2359
|
+
var SDK_VERSION = "0.9.1";
|
|
2360
|
+
|
|
2361
|
+
// src/exporters/quota.ts
|
|
2362
|
+
var QUOTA_REASON = "monthly_quota_exceeded";
|
|
2363
|
+
var QUOTA_HEADER = "X-Risicare-Quota";
|
|
2364
|
+
var QUOTA_HEADER_VALUE = "exceeded";
|
|
2365
|
+
var DEFAULT_RETRY_AFTER_S = 300;
|
|
2366
|
+
var MIN_RETRY_AFTER_S = 1;
|
|
2367
|
+
var MAX_RETRY_AFTER_S = 3600;
|
|
2368
|
+
var QUOTA_WARN_WINDOW_MS = 36e5;
|
|
2369
|
+
var MAX_RESETS_AT_CHARS = 40;
|
|
2370
|
+
function asPositiveCount(v) {
|
|
2371
|
+
if (typeof v === "number") return Number.isFinite(v) && v > 0;
|
|
2372
|
+
if (typeof v === "string" && /^[0-9]+$/.test(v)) return Number(v) > 0;
|
|
2373
|
+
return false;
|
|
2374
|
+
}
|
|
2375
|
+
function boundedRetryAfter(value) {
|
|
2376
|
+
let n;
|
|
2377
|
+
if (typeof value === "number") n = value;
|
|
2378
|
+
else if (typeof value === "string" && value.trim() !== "") n = Number(value);
|
|
2379
|
+
else return DEFAULT_RETRY_AFTER_S;
|
|
2380
|
+
if (!Number.isFinite(n)) return DEFAULT_RETRY_AFTER_S;
|
|
2381
|
+
return Math.min(Math.max(n, MIN_RETRY_AFTER_S), MAX_RETRY_AFTER_S);
|
|
2382
|
+
}
|
|
2383
|
+
function boundedResetsAt(value) {
|
|
2384
|
+
if (typeof value !== "string" || value.length === 0) return null;
|
|
2385
|
+
const cut = value.slice(0, MAX_RESETS_AT_CHARS);
|
|
2386
|
+
return /^[ -~]*$/.test(cut) ? cut : null;
|
|
2387
|
+
}
|
|
2388
|
+
function headerSaysExceeded(headers) {
|
|
2389
|
+
try {
|
|
2390
|
+
const value = headers?.get?.(QUOTA_HEADER);
|
|
2391
|
+
return typeof value === "string" && value.trim().toLowerCase() === QUOTA_HEADER_VALUE;
|
|
2392
|
+
} catch {
|
|
2393
|
+
return false;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
function parseJsonDiscard(payload, headers) {
|
|
2397
|
+
const body = payload !== null && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
2398
|
+
const stored = (asPositiveCount(body.accepted) || asPositiveCount(body.spansAccepted)) === true;
|
|
2399
|
+
if (body.reason === QUOTA_REASON || headerSaysExceeded(headers) && !stored) {
|
|
2400
|
+
return {
|
|
2401
|
+
retryAfterS: boundedRetryAfter(body.retryAfterSeconds),
|
|
2402
|
+
resetsAt: boundedResetsAt(body.resetsAt)
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
return null;
|
|
2406
|
+
}
|
|
2407
|
+
var EPISODE_END_ACCEPTS = 3;
|
|
2408
|
+
var QuotaPause = class {
|
|
2409
|
+
constructor(now = () => performance.now()) {
|
|
2410
|
+
this.now = now;
|
|
2411
|
+
}
|
|
2412
|
+
_until = -Infinity;
|
|
2413
|
+
_inEpisode = false;
|
|
2414
|
+
_accepts = 0;
|
|
2415
|
+
_lastWarn = -Infinity;
|
|
2416
|
+
_lastInfo = -Infinity;
|
|
2417
|
+
/**
|
|
2418
|
+
* Spans dropped since the last WARNING: the full queue's (`addDrops`) and the batches that a
|
|
2419
|
+
* probe lost while the WARNING was held back. The WARNING carries the number.
|
|
2420
|
+
*/
|
|
2421
|
+
_drops = 0;
|
|
2422
|
+
addDrops(count) {
|
|
2423
|
+
this._drops += count;
|
|
2424
|
+
}
|
|
2425
|
+
paused() {
|
|
2426
|
+
return this.now() < this._until;
|
|
2427
|
+
}
|
|
2428
|
+
remainingS() {
|
|
2429
|
+
return Math.max(0, (this._until - this.now()) / 1e3);
|
|
2430
|
+
}
|
|
2431
|
+
enter(discard, where, dropped) {
|
|
2432
|
+
const t = this.now();
|
|
2433
|
+
this._until = t + discard.retryAfterS * 1e3;
|
|
2434
|
+
this._inEpisode = true;
|
|
2435
|
+
this._accepts = 0;
|
|
2436
|
+
if (t - this._lastWarn >= QUOTA_WARN_WINDOW_MS) {
|
|
2437
|
+
this._lastWarn = t;
|
|
2438
|
+
const since = this._drops;
|
|
2439
|
+
this._drops = 0;
|
|
2440
|
+
warn(
|
|
2441
|
+
`Risicare: the monthly event quota is used up (monthly_quota_exceeded). ${where} discarded ${dropped} span(s) and will discard new ones until the quota resets (resetsAt=${discard.resetsAt ?? "unknown"}) or the plan changes. The SDK pauses export and sends one batch again in ${Math.round(discard.retryAfterS)} s. Spans that end in the meantime wait in the queue. When it is full the oldest spans are dropped (the most recent are kept) and counted as quota_exceeded in droppedSpansByReason; a batch that is discarded again is dropped and counted the same way. This is not an error and the SDK does not retry the batch. At most one such WARNING an hour.` + (since > 0 ? ` Spans dropped for the quota since the last WARNING: ${since}.` : "")
|
|
2442
|
+
);
|
|
2443
|
+
} else {
|
|
2444
|
+
this._drops += dropped;
|
|
2445
|
+
debug(`Quota discard again: ${dropped} span(s); paused for ${Math.round(discard.retryAfterS)} s`);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
accepted(where) {
|
|
2449
|
+
if (!this._inEpisode) return;
|
|
2450
|
+
this._accepts++;
|
|
2451
|
+
if (this._accepts < EPISODE_END_ACCEPTS) return;
|
|
2452
|
+
this._inEpisode = false;
|
|
2453
|
+
this._accepts = 0;
|
|
2454
|
+
this._until = -Infinity;
|
|
2455
|
+
const t = this.now();
|
|
2456
|
+
if (t - this._lastInfo >= QUOTA_WARN_WINDOW_MS) {
|
|
2457
|
+
this._lastInfo = t;
|
|
2458
|
+
info(`Risicare: ${where} accepts spans again; the export pause for the quota has ended.`);
|
|
2459
|
+
} else {
|
|
2460
|
+
debug("Quota pause ended (INFO already written this hour)");
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
};
|
|
2308
2464
|
|
|
2309
2465
|
// src/exporters/http.ts
|
|
2310
2466
|
var CAPACITY_REFUSAL_STATUSES = /* @__PURE__ */ new Set([429, 503]);
|
|
@@ -2345,8 +2501,21 @@ var HttpExporter = class {
|
|
|
2345
2501
|
_calls = /* @__PURE__ */ new Map();
|
|
2346
2502
|
/** The ack of each finished call, by its batch. Read once by `takeAck(spans)`. */
|
|
2347
2503
|
_acks = /* @__PURE__ */ new WeakMap();
|
|
2504
|
+
/** The batch processor dropped span(s) from a full queue in the quota pause (S-1). */
|
|
2505
|
+
noteQuotaDrop(count = 1) {
|
|
2506
|
+
this._quota.addDrops(count);
|
|
2507
|
+
}
|
|
2508
|
+
/** True while the exporter is paused for the monthly event quota (S-1). */
|
|
2509
|
+
quotaPaused() {
|
|
2510
|
+
return this._quota.paused();
|
|
2511
|
+
}
|
|
2348
2512
|
/** The spans of each finished call that could not be serialized, by its batch. */
|
|
2349
2513
|
_unserializable = /* @__PURE__ */ new WeakMap();
|
|
2514
|
+
/**
|
|
2515
|
+
* S-1: the paused state after a monthly-quota discard (see `quota.ts`). A discard is not a
|
|
2516
|
+
* failure: it does not touch the circuit breaker.
|
|
2517
|
+
*/
|
|
2518
|
+
_quota = new QuotaPause();
|
|
2350
2519
|
_circuitOpenUntil = 0;
|
|
2351
2520
|
_circuitBreakerThreshold = 5;
|
|
2352
2521
|
_circuitBreakerCooldownMs = 6e4;
|
|
@@ -2438,6 +2607,13 @@ var HttpExporter = class {
|
|
|
2438
2607
|
}
|
|
2439
2608
|
async _export(spans, call) {
|
|
2440
2609
|
const cancelled = call.cancel.signal;
|
|
2610
|
+
if (this._quota.paused()) {
|
|
2611
|
+
debug(
|
|
2612
|
+
`Export skipped: monthly quota pause, ${Math.round(this._quota.remainingS())} s left; ${spans.length} span(s) dropped`
|
|
2613
|
+
);
|
|
2614
|
+
this._acks.set(spans, { accepted: 0, rejected: 0, quotaDropped: spans.length });
|
|
2615
|
+
return "success" /* SUCCESS */;
|
|
2616
|
+
}
|
|
2441
2617
|
const parts = [];
|
|
2442
2618
|
const bad = [];
|
|
2443
2619
|
let errorClass = "";
|
|
@@ -2646,6 +2822,11 @@ var HttpExporter = class {
|
|
|
2646
2822
|
`HTTP ${response.status} and a body that is not a Risicare ack (content-type: ${response.headers?.get?.("Content-Type") || "none"})`
|
|
2647
2823
|
);
|
|
2648
2824
|
}
|
|
2825
|
+
if (ack.quota !== void 0) {
|
|
2826
|
+
this._quota.enter(ack.quota, `The ingest endpoint ${this._safeEndpoint}`, spansSent);
|
|
2827
|
+
} else if (ack.result === "success" /* SUCCESS */) {
|
|
2828
|
+
this._quota.accepted(`the ingest endpoint ${this._safeEndpoint}`);
|
|
2829
|
+
}
|
|
2649
2830
|
if (ack.result === "success" /* SUCCESS */) this._acks.set(spans, ack.counts);
|
|
2650
2831
|
if (ack.final) call.noRetry = true;
|
|
2651
2832
|
return ack.result;
|
|
@@ -2712,7 +2893,16 @@ async function checkAck(response, spansSent, scrub) {
|
|
|
2712
2893
|
try {
|
|
2713
2894
|
payload = await response.json();
|
|
2714
2895
|
} catch {
|
|
2715
|
-
|
|
2896
|
+
payload = void 0;
|
|
2897
|
+
}
|
|
2898
|
+
const discard = parseJsonDiscard(payload, response.headers);
|
|
2899
|
+
if (discard !== null) {
|
|
2900
|
+
return {
|
|
2901
|
+
result: "success" /* SUCCESS */,
|
|
2902
|
+
counts: { accepted: 0, rejected: 0, quotaDropped: spansSent },
|
|
2903
|
+
final: false,
|
|
2904
|
+
quota: discard
|
|
2905
|
+
};
|
|
2716
2906
|
}
|
|
2717
2907
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2718
2908
|
return null;
|
|
@@ -4353,8 +4543,10 @@ function getMetrics() {
|
|
|
4353
4543
|
queue_full: 0,
|
|
4354
4544
|
transport_refused: 0,
|
|
4355
4545
|
shutdown_residue: 0,
|
|
4356
|
-
unacknowledged: 0
|
|
4546
|
+
unacknowledged: 0,
|
|
4547
|
+
quota_exceeded: 0
|
|
4357
4548
|
},
|
|
4549
|
+
droppedQuota: 0,
|
|
4358
4550
|
failedExports: 0,
|
|
4359
4551
|
queueSize: 0,
|
|
4360
4552
|
queueCapacity: 0,
|