Skip to content

Commit

Permalink
Filter child runs where trace has been filtered (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Sep 3, 2024
1 parent cb7fcf0 commit 988217b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.1.49",
"version": "0.1.50",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down
21 changes: 11 additions & 10 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class Client {

private tracingSampleRate?: number;

private sampledPostUuids = new Set();
private filteredPostUuids = new Set();

private autoBatchTracing = true;

Expand Down Expand Up @@ -648,23 +648,24 @@ export class Client {
if (patch) {
const sampled = [];
for (const run of runs) {
if (this.sampledPostUuids.has(run.id)) {
if (!this.filteredPostUuids.has(run.id)) {
sampled.push(run);
this.sampledPostUuids.delete(run.id);
} else {
this.filteredPostUuids.delete(run.id);
}
}
return sampled;
} else {
const sampled = [];
for (const run of runs) {
if (run.id !== run.trace_id) {
sampled.push(run);
this.sampledPostUuids.add(run.id);
continue;
}
if (Math.random() < this.tracingSampleRate) {
if (
(run.id !== run.trace_id &&
!this.filteredPostUuids.has(run.trace_id)) ||
Math.random() < this.tracingSampleRate
) {
sampled.push(run);
this.sampledPostUuids.add(run.id);
} else {
this.filteredPostUuids.add(run.id);
}
}
return sampled;
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export type {
export { RunTree, type RunTreeConfig } from "./run_trees.js";

// Update using yarn bump-version
export const __version__ = "0.1.49";
export const __version__ = "0.1.50";
19 changes: 12 additions & 7 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class Client:
"_web_url",
"_tenant_id",
"tracing_sample_rate",
"_sampled_post_uuids",
"_filtered_post_uuids",
"tracing_queue",
"_anonymizer",
"_hide_inputs",
Expand Down Expand Up @@ -524,7 +524,7 @@ def __init__(
)

self.tracing_sample_rate = _get_tracing_sampling_rate()
self._sampled_post_uuids: set[uuid.UUID] = set()
self._filtered_post_uuids: set[uuid.UUID] = set()
self._write_api_urls: Mapping[str, Optional[str]] = _get_write_api_urls(
api_urls
)
Expand Down Expand Up @@ -1175,19 +1175,24 @@ def _filter_for_sampling(
sampled = []
for run in runs:
run_id = _as_uuid(run["id"])
if run_id in self._sampled_post_uuids:
if run_id not in self._filtered_post_uuids:
sampled.append(run)
self._sampled_post_uuids.remove(run_id)
else:
self._filtered_post_uuids.remove(run_id)
return sampled
else:
sampled = []
for run in runs:
if (
# Child run
run["id"] != run.get("trace_id")
or random.random() < self.tracing_sample_rate
):
# Whose trace is included
and run.get("trace_id") not in self._filtered_post_uuids
# Or a root that's randomly sampled
) or random.random() < self.tracing_sample_rate:
sampled.append(run)
self._sampled_post_uuids.add(_as_uuid(run["id"]))
else:
self._filtered_post_uuids.add(_as_uuid(run["id"]))
return sampled

def create_run(
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langsmith"
version = "0.1.108"
version = "0.1.109"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 988217b

Please sign in to comment.