@refactorlabs/recount 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.
- package/dist/index.cjs +81 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +63 -25
- package/dist/index.js.map +1 -1
- package/llms.md +2 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -243,6 +243,12 @@ type RecountOptions = {
|
|
|
243
243
|
apiUrl?: string;
|
|
244
244
|
environment?: string;
|
|
245
245
|
debug?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Max time an ingest upload may take, including 429 retries. Defaults to
|
|
248
|
+
* 30000. Invalid values fall back to the default; very large values
|
|
249
|
+
* (including Infinity) are capped at ~24.8 days.
|
|
250
|
+
*/
|
|
251
|
+
timeoutMs?: number;
|
|
246
252
|
};
|
|
247
253
|
type IngestResult = {
|
|
248
254
|
traceId: string;
|
|
@@ -395,6 +401,10 @@ declare function chartFromRecords<T extends Record<string, unknown>>({ type, tit
|
|
|
395
401
|
seriesKeys: (keyof T)[];
|
|
396
402
|
}): ChartData;
|
|
397
403
|
|
|
404
|
+
declare const REDACTED: {
|
|
405
|
+
readonly __redacted: true;
|
|
406
|
+
};
|
|
407
|
+
|
|
398
408
|
declare function init(options?: RecountOptions): void;
|
|
399
409
|
declare function startTrace<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
400
410
|
declare function startTrace<T>(name: string, options: TraceOptions, fn: () => Promise<T>): Promise<T>;
|
|
@@ -442,4 +452,4 @@ declare const recount: {
|
|
|
442
452
|
};
|
|
443
453
|
};
|
|
444
454
|
|
|
445
|
-
export { type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type JsonObject, type JsonSpanOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, Recount, RecountError, type RecountOptions, type RetentionPeriod, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableSection, type TableSpanOptions, type TableSummaryStat, type TraceOptions, recount as default };
|
|
455
|
+
export { type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type JsonObject, type JsonSpanOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, REDACTED, Recount, RecountError, type RecountOptions, type RetentionPeriod, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableSection, type TableSpanOptions, type TableSummaryStat, type TraceOptions, addAlert, addGroup, addMessage, addMetadata, addSpan, chart, chartFromRecords, recount as default, fetch, init, named, spanCell, startTrace, table, tableFromObject, tableFromRecords, tableSections };
|
package/dist/index.d.ts
CHANGED
|
@@ -243,6 +243,12 @@ type RecountOptions = {
|
|
|
243
243
|
apiUrl?: string;
|
|
244
244
|
environment?: string;
|
|
245
245
|
debug?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Max time an ingest upload may take, including 429 retries. Defaults to
|
|
248
|
+
* 30000. Invalid values fall back to the default; very large values
|
|
249
|
+
* (including Infinity) are capped at ~24.8 days.
|
|
250
|
+
*/
|
|
251
|
+
timeoutMs?: number;
|
|
246
252
|
};
|
|
247
253
|
type IngestResult = {
|
|
248
254
|
traceId: string;
|
|
@@ -395,6 +401,10 @@ declare function chartFromRecords<T extends Record<string, unknown>>({ type, tit
|
|
|
395
401
|
seriesKeys: (keyof T)[];
|
|
396
402
|
}): ChartData;
|
|
397
403
|
|
|
404
|
+
declare const REDACTED: {
|
|
405
|
+
readonly __redacted: true;
|
|
406
|
+
};
|
|
407
|
+
|
|
398
408
|
declare function init(options?: RecountOptions): void;
|
|
399
409
|
declare function startTrace<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
400
410
|
declare function startTrace<T>(name: string, options: TraceOptions, fn: () => Promise<T>): Promise<T>;
|
|
@@ -442,4 +452,4 @@ declare const recount: {
|
|
|
442
452
|
};
|
|
443
453
|
};
|
|
444
454
|
|
|
445
|
-
export { type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type JsonObject, type JsonSpanOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, Recount, RecountError, type RecountOptions, type RetentionPeriod, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableSection, type TableSpanOptions, type TableSummaryStat, type TraceOptions, recount as default };
|
|
455
|
+
export { type ChartData, type ChartReferenceLine, type ChartSeries, type ChartSpanOptions, type ChartType, type DbParamValue, type DbSpanMetadata, type DbSpanOptions, type GroupSpanOptions, type HttpContentType, type HttpMethod, type HttpRequestInput, type HttpResponseOutput, type HttpSpanOptions, type ImageSpanData, type ImageSpanOptions, type IngestPayload, type IngestResult, type JsonObject, type JsonSpanOptions, type LlmMessage, type LlmSpanInput, type LlmSpanOptions, type LlmSpanOutput, type MessageSpanLevel, type MessageSpanOptions, type Metadata, REDACTED, Recount, RecountError, type RecountOptions, type RetentionPeriod, type Span, type SpanAlert, type SpanAlertCheck, type SpanAlertLevel, type SpanAlertOptions, type SpanBaseOptions, SpanGroup, type SpanOptions, type SpanType, type TableCellSpan, type TableColumn, type TableData, type TableDataFlat, type TableHighlight, type TableSection, type TableSpanOptions, type TableSummaryStat, type TraceOptions, addAlert, addGroup, addMessage, addMetadata, addSpan, chart, chartFromRecords, recount as default, fetch, init, named, spanCell, startTrace, table, tableFromObject, tableFromRecords, tableSections };
|
package/dist/index.js
CHANGED
|
@@ -549,6 +549,13 @@ var NOOP_RESULT2 = { traceId: "" };
|
|
|
549
549
|
var MAX_RETRIES = 2;
|
|
550
550
|
var BASE_RETRY_MS = 1e3;
|
|
551
551
|
var MAX_RETRY_DELAY_MS = 6e4;
|
|
552
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
553
|
+
var MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
554
|
+
function resolveTimeoutMs(value) {
|
|
555
|
+
if (typeof value !== "number" || isNaN(value) || value <= 0)
|
|
556
|
+
return DEFAULT_TIMEOUT_MS;
|
|
557
|
+
return Math.min(value, MAX_TIMEOUT_MS);
|
|
558
|
+
}
|
|
552
559
|
function retryDelayMs(res, attempt) {
|
|
553
560
|
const header = res.headers.get("retry-after");
|
|
554
561
|
if (header) {
|
|
@@ -561,17 +568,19 @@ function retryDelayMs(res, attempt) {
|
|
|
561
568
|
}
|
|
562
569
|
return BASE_RETRY_MS * 2 ** (attempt - 1);
|
|
563
570
|
}
|
|
564
|
-
var _apiKey, _apiUrl, _environment2, _disabled2, _log2;
|
|
571
|
+
var _apiKey, _apiUrl, _environment2, _disabled2, _timeoutMs, _log2;
|
|
565
572
|
var Recount = class {
|
|
566
573
|
constructor(options = {}) {
|
|
567
574
|
__privateAdd(this, _apiKey);
|
|
568
575
|
__privateAdd(this, _apiUrl);
|
|
569
576
|
__privateAdd(this, _environment2);
|
|
570
577
|
__privateAdd(this, _disabled2);
|
|
578
|
+
__privateAdd(this, _timeoutMs);
|
|
571
579
|
__privateAdd(this, _log2);
|
|
572
580
|
const debug = options.debug ?? !!process.env.RECOUNT_DEBUG;
|
|
573
581
|
__privateSet(this, _log2, debug ? (msg) => console.log(`[recount] ${msg}`) : () => {
|
|
574
582
|
});
|
|
583
|
+
__privateSet(this, _timeoutMs, resolveTimeoutMs(options.timeoutMs));
|
|
575
584
|
const apiKey = options.apiKey ?? process.env.RECOUNT_API_KEY;
|
|
576
585
|
if (!apiKey) {
|
|
577
586
|
console.warn("Recount: no API key found - tracing disabled.");
|
|
@@ -613,33 +622,61 @@ var Recount = class {
|
|
|
613
622
|
"Content-Type": "application/json",
|
|
614
623
|
"x-api-key": __privateGet(this, _apiKey)
|
|
615
624
|
};
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
625
|
+
const deadline = Date.now() + __privateGet(this, _timeoutMs);
|
|
626
|
+
const controller = new AbortController();
|
|
627
|
+
const timer = setTimeout(() => controller.abort(), __privateGet(this, _timeoutMs));
|
|
628
|
+
try {
|
|
629
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
630
|
+
try {
|
|
631
|
+
const res = await globalThis.fetch(`${__privateGet(this, _apiUrl)}/ingest`, {
|
|
632
|
+
method: "POST",
|
|
633
|
+
headers,
|
|
634
|
+
body,
|
|
635
|
+
signal: controller.signal
|
|
627
636
|
});
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
637
|
+
if (res.status === 429 && attempt < MAX_RETRIES) {
|
|
638
|
+
const delay = retryDelayMs(res, attempt + 1);
|
|
639
|
+
await res.body?.cancel().catch(() => {
|
|
640
|
+
});
|
|
641
|
+
if (Date.now() + delay >= deadline) {
|
|
642
|
+
__privateGet(this, _log2).call(this, `429 rate limited attempt=${attempt + 1}/${MAX_RETRIES + 1} retry in ${delay}ms would exceed timeout=${__privateGet(this, _timeoutMs)}ms, dropping trace`);
|
|
643
|
+
return NOOP_RESULT2;
|
|
644
|
+
}
|
|
645
|
+
__privateGet(this, _log2).call(this, `429 rate limited attempt=${attempt + 1}/${MAX_RETRIES + 1} retrying in ${delay}ms`);
|
|
646
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
if (!res.ok) {
|
|
650
|
+
const text = await res.text().catch(() => res.statusText);
|
|
651
|
+
__privateGet(this, _log2).call(this, `ingest error status=${res.status} message=${text}`);
|
|
652
|
+
return NOOP_RESULT2;
|
|
653
|
+
}
|
|
654
|
+
let json;
|
|
655
|
+
try {
|
|
656
|
+
json = await res.json();
|
|
657
|
+
} catch (err) {
|
|
658
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
659
|
+
__privateGet(this, _log2).call(this, `ingest error: invalid JSON response (${err.message})`);
|
|
660
|
+
return NOOP_RESULT2;
|
|
661
|
+
}
|
|
662
|
+
const traceId = json?.data?.trace?.id;
|
|
663
|
+
if (typeof traceId !== "string") {
|
|
664
|
+
__privateGet(this, _log2).call(this, `ingest error: unexpected response ${JSON.stringify(json)?.slice(0, 200)}`);
|
|
665
|
+
return NOOP_RESULT2;
|
|
666
|
+
}
|
|
667
|
+
__privateGet(this, _log2).call(this, `ingested traceId=${traceId}`);
|
|
668
|
+
return { traceId };
|
|
669
|
+
} catch (err) {
|
|
670
|
+
if (controller.signal.aborted) {
|
|
671
|
+
__privateGet(this, _log2).call(this, `ingest timed out after ${__privateGet(this, _timeoutMs)}ms`);
|
|
672
|
+
} else {
|
|
673
|
+
__privateGet(this, _log2).call(this, `ingest failed (network error): ${err instanceof Error ? err.message : String(err)}`);
|
|
674
|
+
}
|
|
634
675
|
return NOOP_RESULT2;
|
|
635
676
|
}
|
|
636
|
-
const json = await res.json();
|
|
637
|
-
__privateGet(this, _log2).call(this, `ingested traceId=${json.data.trace.id}`);
|
|
638
|
-
return { traceId: json.data.trace.id };
|
|
639
|
-
} catch (err) {
|
|
640
|
-
__privateGet(this, _log2).call(this, `ingest failed (network error): ${err instanceof Error ? err.message : String(err)}`);
|
|
641
|
-
return NOOP_RESULT2;
|
|
642
677
|
}
|
|
678
|
+
} finally {
|
|
679
|
+
clearTimeout(timer);
|
|
643
680
|
}
|
|
644
681
|
return NOOP_RESULT2;
|
|
645
682
|
}
|
|
@@ -648,6 +685,7 @@ _apiKey = new WeakMap();
|
|
|
648
685
|
_apiUrl = new WeakMap();
|
|
649
686
|
_environment2 = new WeakMap();
|
|
650
687
|
_disabled2 = new WeakMap();
|
|
688
|
+
_timeoutMs = new WeakMap();
|
|
651
689
|
_log2 = new WeakMap();
|
|
652
690
|
|
|
653
691
|
// src/lib/table.ts
|
|
@@ -1107,6 +1145,6 @@ var recount = {
|
|
|
1107
1145
|
};
|
|
1108
1146
|
var index_default = recount;
|
|
1109
1147
|
|
|
1110
|
-
export { SpanGroup, index_default as default };
|
|
1148
|
+
export { REDACTED, Recount, RecountError, SpanGroup, addAlert, addGroup, addMessage, addMetadata, addSpan, chart, chartFromRecords, index_default as default, fetch, init, named, spanCell, startTrace, table, tableFromObject, tableFromRecords, tableSections };
|
|
1111
1149
|
//# sourceMappingURL=index.js.map
|
|
1112
1150
|
//# sourceMappingURL=index.js.map
|