Skip to content

Commit 31d1828

Browse files
make zstandard optional (#2453)
Resolves #2452
1 parent 78c2639 commit 31d1828

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

python/langsmith/_internal/_background_thread.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from langsmith import schemas as ls_schemas
1717
from langsmith import utils as ls_utils
18-
from langsmith._internal._compressed_traces import CompressedTraces
18+
from langsmith._internal._compressed_traces import ZSTD_AVAILABLE, CompressedTraces
1919
from langsmith._internal._constants import (
2020
_AUTO_SCALE_DOWN_NEMPTY_TRIGGER,
2121
_AUTO_SCALE_UP_NTHREADS_LIMIT,
@@ -612,10 +612,16 @@ def tracing_control_thread_func(client_ref: weakref.ref[Client]) -> None:
612612
# 1 for this func, 1 for getrefcount, 1 for _get_data_type_cached
613613
num_known_refs = 3
614614

615-
# Disable compression if explicitly set or if using OpenTelemetry
615+
# Disable compression if explicitly set, using OpenTelemetry, or zstd unavailable
616+
if not ZSTD_AVAILABLE:
617+
logger.debug(
618+
"zstandard package is not installed. "
619+
"Falling back to uncompressed multipart ingestion."
620+
)
616621
disable_compression = (
617622
ls_utils.is_env_var_truish("DISABLE_RUN_COMPRESSION")
618623
or client.otel_exporter is not None
624+
or not ZSTD_AVAILABLE
619625
)
620626
if not disable_compression and use_multipart:
621627
if not (client.info.instance_flags or {}).get(

python/langsmith/_internal/_compressed_traces.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
import threading
33
from typing import Optional
44

5-
from zstandard import ZstdCompressor # type: ignore[import]
6-
75
from langsmith import utils as ls_utils
86

7+
try:
8+
from zstandard import ZstdCompressor # type: ignore[import]
9+
10+
ZSTD_AVAILABLE = True
11+
except ImportError:
12+
ZSTD_AVAILABLE = False
13+
914
compression_level = int(ls_utils.get_env_var("RUN_COMPRESSION_LEVEL") or 1)
1015
compression_threads = int(ls_utils.get_env_var("RUN_COMPRESSION_THREADS") or -1)
1116

@@ -14,6 +19,13 @@
1419

1520
class CompressedTraces:
1621
def __init__(self, max_uncompressed_size_bytes: Optional[int] = None) -> None:
22+
if not ZSTD_AVAILABLE:
23+
raise ImportError(
24+
"zstandard is required for compressed trace ingestion. "
25+
"Install it with `pip install zstandard` or set the environment "
26+
"variable LANGSMITH_DISABLE_RUN_COMPRESSION=true to disable "
27+
"compression."
28+
)
1729
# Configure the maximum total uncompressed size for the in-memory queue.
1830
if max_uncompressed_size_bytes is None:
1931
max_bytes_str = ls_utils.get_env_var("MAX_INGEST_MEMORY_BYTES")

0 commit comments

Comments
 (0)