File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
python/langsmith/_internal Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 1515
1616from langsmith import schemas as ls_schemas
1717from langsmith import utils as ls_utils
18- from langsmith ._internal ._compressed_traces import CompressedTraces
18+ from langsmith ._internal ._compressed_traces import ZSTD_AVAILABLE , CompressedTraces
1919from 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 (
Original file line number Diff line number Diff line change 22import threading
33from typing import Optional
44
5- from zstandard import ZstdCompressor # type: ignore[import]
6-
75from 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+
914compression_level = int (ls_utils .get_env_var ("RUN_COMPRESSION_LEVEL" ) or 1 )
1015compression_threads = int (ls_utils .get_env_var ("RUN_COMPRESSION_THREADS" ) or - 1 )
1116
1419
1520class 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" )
You can’t perform that action at this time.
0 commit comments