langsmith 0.3.13 → 0.3.14
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/client.cjs +30 -10
- package/dist/client.d.ts +2 -0
- package/dist/client.js +30 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -57,8 +57,9 @@ function mergeRuntimeEnvIntoRunCreate(run) {
|
|
|
57
57
|
return run;
|
|
58
58
|
}
|
|
59
59
|
exports.mergeRuntimeEnvIntoRunCreate = mergeRuntimeEnvIntoRunCreate;
|
|
60
|
-
const getTracingSamplingRate = () => {
|
|
61
|
-
const samplingRateStr = (
|
|
60
|
+
const getTracingSamplingRate = (configRate) => {
|
|
61
|
+
const samplingRateStr = configRate?.toString() ??
|
|
62
|
+
(0, env_js_1.getLangSmithEnvironmentVariable)("TRACING_SAMPLING_RATE");
|
|
62
63
|
if (samplingRateStr === undefined) {
|
|
63
64
|
return undefined;
|
|
64
65
|
}
|
|
@@ -322,7 +323,7 @@ class Client {
|
|
|
322
323
|
value: false
|
|
323
324
|
});
|
|
324
325
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
325
|
-
this.tracingSampleRate = getTracingSamplingRate();
|
|
326
|
+
this.tracingSampleRate = getTracingSamplingRate(config.tracingSamplingRate);
|
|
326
327
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
327
328
|
if (this.apiUrl.endsWith("/")) {
|
|
328
329
|
this.apiUrl = this.apiUrl.slice(0, -1);
|
|
@@ -518,6 +519,13 @@ class Client {
|
|
|
518
519
|
bodyParams.cursor = cursors.next;
|
|
519
520
|
}
|
|
520
521
|
}
|
|
522
|
+
// Allows mocking for tests
|
|
523
|
+
_shouldSample() {
|
|
524
|
+
if (this.tracingSampleRate === undefined) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
return Math.random() < this.tracingSampleRate;
|
|
528
|
+
}
|
|
521
529
|
_filterForSampling(runs, patch = false) {
|
|
522
530
|
if (this.tracingSampleRate === undefined) {
|
|
523
531
|
return runs;
|
|
@@ -535,15 +543,26 @@ class Client {
|
|
|
535
543
|
return sampled;
|
|
536
544
|
}
|
|
537
545
|
else {
|
|
546
|
+
// For new runs, sample at trace level to maintain consistency
|
|
538
547
|
const sampled = [];
|
|
539
548
|
for (const run of runs) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
549
|
+
const traceId = run.trace_id ?? run.id;
|
|
550
|
+
// If we've already made a decision about this trace, follow it
|
|
551
|
+
if (this.filteredPostUuids.has(traceId)) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
// For new traces, apply sampling
|
|
555
|
+
if (run.id === traceId) {
|
|
556
|
+
if (this._shouldSample()) {
|
|
557
|
+
sampled.push(run);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
this.filteredPostUuids.add(traceId);
|
|
561
|
+
}
|
|
544
562
|
}
|
|
545
563
|
else {
|
|
546
|
-
|
|
564
|
+
// Child runs follow their trace's sampling decision
|
|
565
|
+
sampled.push(run);
|
|
547
566
|
}
|
|
548
567
|
}
|
|
549
568
|
return sampled;
|
|
@@ -730,8 +749,8 @@ class Client {
|
|
|
730
749
|
preparedUpdateParams = standaloneUpdates;
|
|
731
750
|
}
|
|
732
751
|
const rawBatch = {
|
|
733
|
-
post:
|
|
734
|
-
patch:
|
|
752
|
+
post: preparedCreateParams,
|
|
753
|
+
patch: preparedUpdateParams,
|
|
735
754
|
};
|
|
736
755
|
if (!rawBatch.post.length && !rawBatch.patch.length) {
|
|
737
756
|
return;
|
|
@@ -745,6 +764,7 @@ class Client {
|
|
|
745
764
|
const batchItems = rawBatch[key].reverse();
|
|
746
765
|
let batchItem = batchItems.pop();
|
|
747
766
|
while (batchItem !== undefined) {
|
|
767
|
+
// Type is wrong but this is a deprecated code path anyway
|
|
748
768
|
batchChunks[key].push(batchItem);
|
|
749
769
|
batchItem = batchItems.pop();
|
|
750
770
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface ClientConfig {
|
|
|
20
20
|
* Useful if encountering network rate limits at trace high volumes.
|
|
21
21
|
*/
|
|
22
22
|
manualFlushMode?: boolean;
|
|
23
|
+
tracingSamplingRate?: number;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Represents the parameters for listing runs (spans) from the Langsmith server.
|
|
@@ -244,6 +245,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
244
245
|
private _get;
|
|
245
246
|
private _getPaginated;
|
|
246
247
|
private _getCursorPaginatedList;
|
|
248
|
+
private _shouldSample;
|
|
247
249
|
private _filterForSampling;
|
|
248
250
|
private _getBatchSizeLimitBytes;
|
|
249
251
|
private _getMultiPartSupport;
|
package/dist/client.js
CHANGED
|
@@ -30,8 +30,9 @@ export function mergeRuntimeEnvIntoRunCreate(run) {
|
|
|
30
30
|
};
|
|
31
31
|
return run;
|
|
32
32
|
}
|
|
33
|
-
const getTracingSamplingRate = () => {
|
|
34
|
-
const samplingRateStr =
|
|
33
|
+
const getTracingSamplingRate = (configRate) => {
|
|
34
|
+
const samplingRateStr = configRate?.toString() ??
|
|
35
|
+
getLangSmithEnvironmentVariable("TRACING_SAMPLING_RATE");
|
|
35
36
|
if (samplingRateStr === undefined) {
|
|
36
37
|
return undefined;
|
|
37
38
|
}
|
|
@@ -294,7 +295,7 @@ export class Client {
|
|
|
294
295
|
value: false
|
|
295
296
|
});
|
|
296
297
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
297
|
-
this.tracingSampleRate = getTracingSamplingRate();
|
|
298
|
+
this.tracingSampleRate = getTracingSamplingRate(config.tracingSamplingRate);
|
|
298
299
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
299
300
|
if (this.apiUrl.endsWith("/")) {
|
|
300
301
|
this.apiUrl = this.apiUrl.slice(0, -1);
|
|
@@ -490,6 +491,13 @@ export class Client {
|
|
|
490
491
|
bodyParams.cursor = cursors.next;
|
|
491
492
|
}
|
|
492
493
|
}
|
|
494
|
+
// Allows mocking for tests
|
|
495
|
+
_shouldSample() {
|
|
496
|
+
if (this.tracingSampleRate === undefined) {
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
return Math.random() < this.tracingSampleRate;
|
|
500
|
+
}
|
|
493
501
|
_filterForSampling(runs, patch = false) {
|
|
494
502
|
if (this.tracingSampleRate === undefined) {
|
|
495
503
|
return runs;
|
|
@@ -507,15 +515,26 @@ export class Client {
|
|
|
507
515
|
return sampled;
|
|
508
516
|
}
|
|
509
517
|
else {
|
|
518
|
+
// For new runs, sample at trace level to maintain consistency
|
|
510
519
|
const sampled = [];
|
|
511
520
|
for (const run of runs) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
521
|
+
const traceId = run.trace_id ?? run.id;
|
|
522
|
+
// If we've already made a decision about this trace, follow it
|
|
523
|
+
if (this.filteredPostUuids.has(traceId)) {
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
// For new traces, apply sampling
|
|
527
|
+
if (run.id === traceId) {
|
|
528
|
+
if (this._shouldSample()) {
|
|
529
|
+
sampled.push(run);
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
this.filteredPostUuids.add(traceId);
|
|
533
|
+
}
|
|
516
534
|
}
|
|
517
535
|
else {
|
|
518
|
-
|
|
536
|
+
// Child runs follow their trace's sampling decision
|
|
537
|
+
sampled.push(run);
|
|
519
538
|
}
|
|
520
539
|
}
|
|
521
540
|
return sampled;
|
|
@@ -702,8 +721,8 @@ export class Client {
|
|
|
702
721
|
preparedUpdateParams = standaloneUpdates;
|
|
703
722
|
}
|
|
704
723
|
const rawBatch = {
|
|
705
|
-
post:
|
|
706
|
-
patch:
|
|
724
|
+
post: preparedCreateParams,
|
|
725
|
+
patch: preparedUpdateParams,
|
|
707
726
|
};
|
|
708
727
|
if (!rawBatch.post.length && !rawBatch.patch.length) {
|
|
709
728
|
return;
|
|
@@ -717,6 +736,7 @@ export class Client {
|
|
|
717
736
|
const batchItems = rawBatch[key].reverse();
|
|
718
737
|
let batchItem = batchItems.pop();
|
|
719
738
|
while (batchItem !== undefined) {
|
|
739
|
+
// Type is wrong but this is a deprecated code path anyway
|
|
720
740
|
batchChunks[key].push(batchItem);
|
|
721
741
|
batchItem = batchItems.pop();
|
|
722
742
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
|
|
|
8
8
|
var fetch_js_1 = require("./singletons/fetch.cjs");
|
|
9
9
|
Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
|
|
10
10
|
// Update using yarn bump-version
|
|
11
|
-
exports.__version__ = "0.3.
|
|
11
|
+
exports.__version__ = "0.3.14";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { Client, type ClientConfig, type LangSmithTracingClientInterface, } from
|
|
|
2
2
|
export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
4
|
export { overrideFetchImplementation } from "./singletons/fetch.js";
|
|
5
|
-
export declare const __version__ = "0.3.
|
|
5
|
+
export declare const __version__ = "0.3.14";
|
package/dist/index.js
CHANGED