langwatch 0.2.14__py3-none-any.whl → 0.2.16__py3-none-any.whl

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.
langwatch/__version__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Version information for LangWatch."""
2
2
 
3
- __version__ = "0.2.14"
3
+ __version__ = "0.2.16"
langwatch/client.py CHANGED
@@ -42,6 +42,7 @@ class Client(LangWatchClientProtocol):
42
42
  _flush_on_exit: bool = True
43
43
  _span_exclude_rules: List[SpanProcessingExcludeRule] = []
44
44
  _ignore_global_tracer_provider_override_warning: bool = False
45
+ _skip_open_telemetry_setup: bool = False
45
46
  _rest_api_client: LangWatchApiClient
46
47
 
47
48
  def __init__(
@@ -56,6 +57,7 @@ class Client(LangWatchClientProtocol):
56
57
  flush_on_exit: bool = True,
57
58
  span_exclude_rules: Optional[List[SpanProcessingExcludeRule]] = None,
58
59
  ignore_global_tracer_provider_override_warning: bool = False,
60
+ skip_open_telemetry_setup: bool = False,
59
61
  ):
60
62
  """
61
63
  Initialize the LangWatch tracing client.
@@ -70,6 +72,7 @@ class Client(LangWatchClientProtocol):
70
72
  flush_on_exit: Optional. If True, the tracer provider will flush all spans when the program exits.
71
73
  span_exclude_rules: Optional. The rules to exclude from the span exporter.
72
74
  ignore_global_tracer_provider_override_warning: Optional. If True, the warning about the global tracer provider being overridden will be ignored.
75
+ skip_open_telemetry_setup: Optional. If True, OpenTelemetry setup will be skipped entirely. This is useful when you want to handle OpenTelemetry setup yourself.
73
76
  """
74
77
 
75
78
  self._api_key = api_key or os.getenv("LANGWATCH_API_KEY", "")
@@ -85,6 +88,7 @@ class Client(LangWatchClientProtocol):
85
88
  self._ignore_global_tracer_provider_override_warning = (
86
89
  ignore_global_tracer_provider_override_warning
87
90
  )
91
+ self._skip_open_telemetry_setup = skip_open_telemetry_setup
88
92
  self.base_attributes = base_attributes or {}
89
93
  self.base_attributes[AttributeKey.LangWatchSDKName] = (
90
94
  "langwatch-observability-sdk"
@@ -92,11 +96,17 @@ class Client(LangWatchClientProtocol):
92
96
  self.base_attributes[AttributeKey.LangWatchSDKVersion] = str(__version__)
93
97
  self.base_attributes[AttributeKey.LangWatchSDKLanguage] = "python"
94
98
 
95
- self.tracer_provider = self.__ensure_otel_setup(tracer_provider)
99
+ if not self._skip_open_telemetry_setup:
100
+ self.tracer_provider = self.__ensure_otel_setup(tracer_provider)
96
101
 
97
- self.instrumentors = instrumentors or []
98
- for instrumentor in self.instrumentors:
99
- instrumentor.instrument(tracer_provider=self.tracer_provider)
102
+ self.instrumentors = instrumentors or []
103
+ for instrumentor in self.instrumentors:
104
+ instrumentor.instrument(tracer_provider=self.tracer_provider)
105
+ else:
106
+ self.tracer_provider = tracer_provider
107
+ self.instrumentors = instrumentors or []
108
+ if self._debug:
109
+ logger.debug("Skipping OpenTelemetry setup as requested")
100
110
 
101
111
  self._setup_rest_api_client()
102
112
 
@@ -135,7 +145,7 @@ class Client(LangWatchClientProtocol):
135
145
 
136
146
  self._api_key = value
137
147
 
138
- if api_key_has_changed:
148
+ if api_key_has_changed and not self._skip_open_telemetry_setup:
139
149
  # Shut down any existing tracer provider, as API key change requires re-initialization.
140
150
  self.__shutdown_tracer_provider()
141
151
 
@@ -160,6 +170,11 @@ class Client(LangWatchClientProtocol):
160
170
  """Get the REST API client for the client."""
161
171
  return self._rest_api_client
162
172
 
173
+ @property
174
+ def skip_open_telemetry_setup(self) -> bool:
175
+ """Get whether OpenTelemetry setup is skipped."""
176
+ return self._skip_open_telemetry_setup
177
+
163
178
  @disable_sending.setter
164
179
  def disable_sending(self, value: bool) -> None:
165
180
  """Set whether sending is disabled. If enabling, this will create a new global tracer provider."""
@@ -167,7 +182,7 @@ class Client(LangWatchClientProtocol):
167
182
  return
168
183
 
169
184
  # force flush the tracer provider before changing the disable_sending flag
170
- if self.tracer_provider:
185
+ if self.tracer_provider and not self._skip_open_telemetry_setup:
171
186
  self.tracer_provider.force_flush()
172
187
 
173
188
  self._disable_sending = value
@@ -196,6 +211,11 @@ class Client(LangWatchClientProtocol):
196
211
 
197
212
  def __setup_tracer_provider(self) -> None:
198
213
  """Sets up the tracer provider if not already active."""
214
+ if self._skip_open_telemetry_setup:
215
+ if self._debug:
216
+ logger.debug("Skipping tracer provider setup as requested.")
217
+ return
218
+
199
219
  if not self.tracer_provider:
200
220
  if self._debug:
201
221
  logger.debug("Setting up new tracer provider.")
@@ -1,5 +1,6 @@
1
- from typing import Any, Dict, List
1
+ from typing import Any, Dict, List, Optional
2
2
  from opentelemetry import trace
3
+ from opentelemetry.trace import NoOpTracer
3
4
  from langwatch.generated.langwatch_rest_api_client.api.default import (
4
5
  get_api_dataset_by_slug_or_id,
5
6
  )
@@ -14,6 +15,7 @@ from langwatch.generated.langwatch_rest_api_client.models import (
14
15
  )
15
16
  from langwatch.state import get_instance
16
17
  import pandas as pd
18
+ from pydantic import BaseModel
17
19
 
18
20
  from langwatch.utils.initialization import ensure_setup
19
21
 
@@ -37,10 +39,20 @@ class Dataset:
37
39
  return pd.DataFrame([entry.entry for entry in self.entries])
38
40
 
39
41
 
40
- def get_dataset(slug_or_id: str) -> Dataset:
42
+ class GetDatasetOptions(BaseModel):
43
+ ignore_tracing: Optional[bool] = False
44
+
45
+
46
+ def get_dataset(
47
+ slug_or_id: str, options: Optional[GetDatasetOptions] = None
48
+ ) -> Dataset:
41
49
  ensure_setup()
42
50
 
43
- with _tracer.start_as_current_span("get_dataset") as span:
51
+ tracer = NoOpTracer() if options and options.ignore_tracing is True else _tracer
52
+
53
+ with tracer.start_as_current_span(
54
+ "get_dataset",
55
+ ) as span:
44
56
  span.set_attribute("inputs.slug_or_id", slug_or_id)
45
57
 
46
58
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langwatch
3
- Version: 0.2.14
3
+ Version: 0.2.16
4
4
  Summary: LangWatch Python SDK, for monitoring your LLMs
5
5
  Author-email: Langwatch Engineers <engineering@langwatch.ai>
6
6
  License: MIT
@@ -15,11 +15,10 @@ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
17
  Requires-Python: <3.14,>=3.10
18
+ Requires-Dist: attrs>=24
18
19
  Requires-Dist: coolname>=2.2.0
19
20
  Requires-Dist: deprecated>=1.2.18
20
- Requires-Dist: dspy-ai<3.0.0,>=2.5.2
21
21
  Requires-Dist: httpx>=0.27.0
22
- Requires-Dist: litellm>=1.52.1
23
22
  Requires-Dist: nanoid<3.0.0,>=2.0.0
24
23
  Requires-Dist: openinference-instrumentation-haystack>=0.1.20
25
24
  Requires-Dist: openinference-instrumentation-langchain>=0.1.24
@@ -29,6 +28,7 @@ Requires-Dist: opentelemetry-api>=1.32.1
29
28
  Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.32.1
30
29
  Requires-Dist: opentelemetry-instrumentation-crewai>=0.45.0
31
30
  Requires-Dist: opentelemetry-sdk>=1.32.1
31
+ Requires-Dist: pydantic>=2
32
32
  Requires-Dist: python-liquid>=2.0.2
33
33
  Requires-Dist: retry>=0.9.2
34
34
  Requires-Dist: termcolor>=3.0.1
@@ -36,6 +36,8 @@ Provides-Extra: dev
36
36
  Requires-Dist: ruff>=0.11.1; extra == 'dev'
37
37
  Provides-Extra: dspy
38
38
  Requires-Dist: dspy-ai<3.0.0,>=2.5.2; extra == 'dspy'
39
+ Provides-Extra: litellm
40
+ Requires-Dist: litellm>=1.52.1; extra == 'litellm'
39
41
  Provides-Extra: tests
40
42
  Requires-Dist: factory-boy<4.0.0,>=3.3.0; extra == 'tests'
41
43
  Requires-Dist: pytest-asyncio<0.22.0,>=0.21.1; extra == 'tests'
@@ -1,8 +1,8 @@
1
1
  langwatch/__init__.py,sha256=OX8vN2-VFNUqRo9mJC8LUjHGMKYSRTwmzUQj_sKAVXQ,4210
2
- langwatch/__version__.py,sha256=hDqsjjAbGMSl_DZBFOqD1TXiZ5AnjBLKY1nrRxJz6zo,65
2
+ langwatch/__version__.py,sha256=zBSlISkVLNMQm4p_0afBBJuscq6Fwt88EDKwt5vf9_I,65
3
3
  langwatch/attributes.py,sha256=nXdI_G85wQQCAdAcwjCiLYdEYj3wATmfgCmhlf6dVIk,3910
4
4
  langwatch/batch_evaluation.py,sha256=piez7TYqUZPb9NlIShTuTPmSzrZqX-vm2Grz_NGXe04,16078
5
- langwatch/client.py,sha256=w-WkYRwgFMlfljAwcR6GBT11kBQOc3Ifb3hGY1htOd4,13156
5
+ langwatch/client.py,sha256=9mLnGOZsVjwQ8AMp0f-J8-nNtg5EPXGkaQ4m8Jck3ew,14197
6
6
  langwatch/evaluations.py,sha256=U8zMVbn0FmsUuUGiQ-XfmIejNjKY3oW9V4ymAFS8tDw,16828
7
7
  langwatch/guardrails.py,sha256=4d320HyklXPUVszF34aWsDKGzuvPggcDM_f45_eJTnc,1352
8
8
  langwatch/langchain.py,sha256=nUuV5puASRs66kSW05i9tCRy09st5m_6uy9FYR672Zg,18658
@@ -13,7 +13,7 @@ langwatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  langwatch/state.py,sha256=qXvPAjO90jdokCU6tPSwjHIac4QU_5N0pSd9dfmc9kY,1204
14
14
  langwatch/tracer.py,sha256=t5FOdP1es9H_pPGqGUBLXCyEln0tTi4m4M9b6WxCrPU,975
15
15
  langwatch/types.py,sha256=DkZThS7ptUY0_Ao7PNO6ZGBE9Qj0YmJf5auRkq2Cphw,2570
16
- langwatch/dataset/__init__.py,sha256=1vUqnyFymnzcIOTahtsPvKTyAet_q-HTKByRUkuED80,2290
16
+ langwatch/dataset/__init__.py,sha256=hZBcbjXuBO2qE5osJtd9wIE9f45F6-jpNTrne5nk4eE,2606
17
17
  langwatch/domain/__init__.py,sha256=luuin3-6mmMqDaOJE_1wb7M1ccjhhZL80UN0TBA_TXM,6040
18
18
  langwatch/dspy/__init__.py,sha256=E9rqyhOyIO3E-GxJSZlHtsvjapFjKQGF85QRcpKSvKE,34280
19
19
  langwatch/evaluation/__init__.py,sha256=Jy7PW5VQbMoDGdOLRlQmDEvo_9TDkBLmrLrfocxddLM,281
@@ -408,6 +408,6 @@ langwatch/utils/initialization.py,sha256=LOmGCiox7JRiHprnB04AdO8BhUggZtRbWgBPF9m
408
408
  langwatch/utils/module.py,sha256=KLBNOK3mA9gCSifCcQX_lOtU48BJQDWvFKtF6NMvwVA,688
409
409
  langwatch/utils/transformation.py,sha256=5XUnW7Oz8Ck9EMsKeKeoDOrIw3EXpLGMk_fMSeA0Zng,7216
410
410
  langwatch/utils/utils.py,sha256=ZCOSie4o9LdJ7odshNfCNjmgwgQ27ojc5ENqt1rXuSs,596
411
- langwatch-0.2.14.dist-info/METADATA,sha256=dQi4CnhlrCsdJBMxJLw3rX_e4JZS-KjZenTPLIf9MjI,13036
412
- langwatch-0.2.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
413
- langwatch-0.2.14.dist-info/RECORD,,
411
+ langwatch-0.2.16.dist-info/METADATA,sha256=OYg6R9Xvlpydm4Zb3GUc7yFFfrLOwBLvgff0b_jzy0c,13095
412
+ langwatch-0.2.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
413
+ langwatch-0.2.16.dist-info/RECORD,,