langtrace-python-sdk 2.3.9__py3-none-any.whl → 2.3.11__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.
@@ -1 +1,2 @@
1
1
  LANGTRACE_SDK_NAME = "langtrace-python-sdk"
2
+ SENTRY_DSN = "https://7f8eed3a1237fb2efef0f5e96ab407af@o1419498.ingest.us.sentry.io/4507929133056000"
@@ -51,7 +51,6 @@ def patch_memory(operation_name, version, tracer: Tracer):
51
51
  )
52
52
  if result:
53
53
  span.set_status(Status(StatusCode.OK))
54
- span.end()
55
54
  return result
56
55
 
57
56
  except Exception as err:
@@ -102,7 +101,6 @@ def patch_crew(operation_name, version, tracer: Tracer):
102
101
  span.set_attribute(
103
102
  f"crewai.crew.{attr}", str(getattr(result, attr))
104
103
  )
105
- span.end()
106
104
  return result
107
105
 
108
106
  except Exception as err:
@@ -139,21 +137,27 @@ class CrewAISpanAttributes:
139
137
  for key, value in self.crew.items():
140
138
  key = f"crewai.crew.{key}"
141
139
  if value is not None:
142
- set_span_attribute(self.span, key, value)
140
+ set_span_attribute(
141
+ self.span, key, str(value) if isinstance(value, list) else value
142
+ )
143
143
 
144
144
  elif instance_name == "Agent":
145
145
  agent = self.set_agent_attributes()
146
146
  for key, value in agent.items():
147
147
  key = f"crewai.agent.{key}"
148
148
  if value is not None:
149
- set_span_attribute(self.span, key, value)
149
+ set_span_attribute(
150
+ self.span, key, str(value) if isinstance(value, list) else value
151
+ )
150
152
 
151
153
  elif instance_name == "Task":
152
154
  task = self.set_task_attributes()
153
155
  for key, value in task.items():
154
156
  key = f"crewai.task.{key}"
155
157
  if value is not None:
156
- set_span_attribute(self.span, key, value)
158
+ set_span_attribute(
159
+ self.span, key, str(value) if isinstance(value, list) else value
160
+ )
157
161
 
158
162
  def set_crew_attributes(self):
159
163
  for key, value in self.instance.__dict__.items():
@@ -17,8 +17,9 @@ limitations under the License.
17
17
  import os
18
18
  import sys
19
19
  from typing import Optional
20
-
20
+ import importlib.util
21
21
  from colorama import Fore
22
+ from langtrace_python_sdk.constants import LANGTRACE_SDK_NAME, SENTRY_DSN
22
23
  from opentelemetry import trace
23
24
  from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
24
25
  from opentelemetry.sdk.resources import SERVICE_NAME, Resource
@@ -60,8 +61,9 @@ from langtrace_python_sdk.types import (
60
61
  InstrumentationMethods,
61
62
  InstrumentationType,
62
63
  )
63
- from langtrace_python_sdk.utils import check_if_sdk_is_outdated
64
+ from langtrace_python_sdk.utils import check_if_sdk_is_outdated, get_sdk_version
64
65
  from langtrace_python_sdk.utils.langtrace_sampler import LangtraceSampler
66
+ import sentry_sdk
65
67
 
66
68
 
67
69
  def init(
@@ -120,25 +122,25 @@ def init(
120
122
  all_instrumentations = {
121
123
  "openai": OpenAIInstrumentation(),
122
124
  "groq": GroqInstrumentation(),
123
- "pinecone": PineconeInstrumentation(),
124
- "llamaindex": LlamaindexInstrumentation(),
125
- "chroma": ChromaInstrumentation(),
125
+ "pinecone-client": PineconeInstrumentation(),
126
+ "llama-index": LlamaindexInstrumentation(),
127
+ "chromadb": ChromaInstrumentation(),
126
128
  "embedchain": EmbedchainInstrumentation(),
127
- "qdrant": QdrantInstrumentation(),
129
+ "qdrant-client": QdrantInstrumentation(),
128
130
  "langchain": LangchainInstrumentation(),
129
- "langchain_core": LangchainCoreInstrumentation(),
130
- "langchain_community": LangchainCommunityInstrumentation(),
131
+ "langchain-core": LangchainCoreInstrumentation(),
132
+ "langchain-community": LangchainCommunityInstrumentation(),
131
133
  "langgraph": LanggraphInstrumentation(),
132
134
  "anthropic": AnthropicInstrumentation(),
133
135
  "cohere": CohereInstrumentation(),
134
- "weaviate": WeaviateInstrumentation(),
136
+ "weaviate-client": WeaviateInstrumentation(),
135
137
  "sqlalchemy": SQLAlchemyInstrumentor(),
136
138
  "ollama": OllamaInstrumentor(),
137
- "dspy": DspyInstrumentation(),
139
+ "dspy-ai": DspyInstrumentation(),
138
140
  "crewai": CrewAIInstrumentation(),
139
- "vertexai": VertexAIInstrumentation(),
140
- "gemini": GeminiInstrumentation(),
141
- "mistral": MistralInstrumentation(),
141
+ "google-cloud-aiplatform": VertexAIInstrumentation(),
142
+ "google-generativeai": GeminiInstrumentation(),
143
+ "mistralai": MistralInstrumentation(),
142
144
  }
143
145
 
144
146
  init_instrumentations(disable_instrumentations, all_instrumentations)
@@ -164,6 +166,27 @@ def init(
164
166
  provider.add_span_processor(batch_processor_remote)
165
167
 
166
168
  sys.stdout = sys.__stdout__
169
+ if os.environ.get("LANGTRACE_ERROR_REPORTING", "True") == "True":
170
+ sentry_sdk.init(
171
+ dsn=SENTRY_DSN,
172
+ traces_sample_rate=1.0,
173
+ profiles_sample_rate=1.0,
174
+ )
175
+ sdk_options = {
176
+ "service_name": os.environ.get("OTEL_SERVICE_NAME")
177
+ or service_name
178
+ or sys.argv[0],
179
+ "disable_logging": disable_logging,
180
+ "disable_instrumentations": disable_instrumentations,
181
+ "disable_tracing_for_functions": disable_tracing_for_functions,
182
+ "batch": batch,
183
+ "write_spans_to_console": write_spans_to_console,
184
+ "custom_remote_exporter": custom_remote_exporter,
185
+ "sdk_name": LANGTRACE_SDK_NAME,
186
+ "sdk_version": get_sdk_version(),
187
+ "api_host": host,
188
+ }
189
+ sentry_sdk.set_context("sdk_init_options", sdk_options)
167
190
 
168
191
 
169
192
  def init_instrumentations(
@@ -171,8 +194,9 @@ def init_instrumentations(
171
194
  ):
172
195
  if disable_instrumentations is None:
173
196
  for idx, (name, v) in enumerate(all_instrumentations.items()):
197
+ if is_package_installed(name):
198
+ v.instrument()
174
199
 
175
- v.instrument()
176
200
  else:
177
201
 
178
202
  validate_instrumentations(disable_instrumentations)
@@ -229,3 +253,10 @@ def validate_instrumentations(disable_instrumentations):
229
253
  raise ValueError(
230
254
  "Cannot specify both only and all_except in disable_instrumentations"
231
255
  )
256
+
257
+
258
+ def is_package_installed(package_name):
259
+ import pkg_resources
260
+
261
+ installed_packages = {p.key for p in pkg_resources.working_set}
262
+ return package_name in installed_packages
@@ -31,3 +31,7 @@ def set_event_prompt(span: Span, prompt):
31
31
  def check_if_sdk_is_outdated():
32
32
  SDKVersionChecker().check()
33
33
  return
34
+
35
+
36
+ def get_sdk_version():
37
+ return SDKVersionChecker().get_sdk_version()
@@ -44,6 +44,9 @@ class SDKVersionChecker:
44
44
  return self._current_version < latest_version
45
45
  return False
46
46
 
47
+ def get_sdk_version(self):
48
+ return self._current_version
49
+
47
50
  def check(self):
48
51
  if self.is_outdated():
49
52
  print(
@@ -1 +1 @@
1
- __version__ = "2.3.9"
1
+ __version__ = "2.3.11"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.3.9
3
+ Version: 2.3.11
4
4
  Summary: Python SDK for LangTrace
5
5
  Project-URL: Homepage, https://github.com/Scale3-Labs/langtrace-python-sdk
6
6
  Author-email: Scale3 Labs <engineering@scale3labs.com>
@@ -18,6 +18,7 @@ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.25.0
18
18
  Requires-Dist: opentelemetry-instrumentation-sqlalchemy>=0.46b0
19
19
  Requires-Dist: opentelemetry-instrumentation>=0.47b0
20
20
  Requires-Dist: opentelemetry-sdk>=1.25.0
21
+ Requires-Dist: sentry-sdk>=2.14.0
21
22
  Requires-Dist: sqlalchemy
22
23
  Requires-Dist: tiktoken>=0.1.1
23
24
  Requires-Dist: trace-attributes==7.0.4
@@ -196,6 +197,10 @@ langtrace.init(custom_remote_exporter=<your_exporter>, batch=<True or False>)
196
197
  | `api_host` | `Optional[str]` | `https://langtrace.ai/` | The API host for the remote exporter. |
197
198
  | `disable_instrumentations` | `Optional[DisableInstrumentations]` | `None` | You can pass an object to disable instrumentation for specific vendors ex: `{'only': ['openai']}` or `{'all_except': ['openai']}` |
198
199
 
200
+ ### Error Reporting to Langtrace
201
+
202
+ By default all sdk errors are reported to langtrace via Sentry. This can be disabled by setting the following enviroment variable to `False` like so `LANGTRACE_ERROR_REPORTING=False`
203
+
199
204
  ### Additional Customization
200
205
 
201
206
  - `@with_langtrace_root_span` - this decorator is designed to organize and relate different spans, in a hierarchical manner. When you're performing multiple operations that you want to monitor together as a unit, this function helps by establishing a "parent" (`LangtraceRootSpan` or whatever is passed to `name`) span. Then, any calls to the LLM APIs made within the given function (fn) will be considered "children" of this parent span. This setup is especially useful for tracking the performance or behavior of a group of operations collectively, rather than individually.
@@ -277,6 +282,7 @@ prompt = get_prompt_from_registry(<Registry ID>, options={"prompt_version": 1, "
277
282
  ```
278
283
 
279
284
  ### Opt out of tracing prompt and completion data
285
+
280
286
  By default, prompt and completion data are captured. If you would like to opt out of it, set the following env var,
281
287
 
282
288
  `TRACE_PROMPT_COMPLETION_DATA=false`
@@ -88,9 +88,9 @@ examples/vertexai_example/main.py,sha256=gndId5X5ksD-ycxnAWMdEqIDbLc3kz5Vt8vm4YP
88
88
  examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56snk-Bbg2Kw,618
89
89
  examples/weaviate_example/query_text.py,sha256=wPHQTc_58kPoKTZMygVjTj-2ZcdrIuaausJfMxNQnQc,127162
90
90
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
91
- langtrace_python_sdk/langtrace.py,sha256=rjIEwPd-Iq0mcSCh_3CEK-38kyJwazdR1CfDa_U4mfQ,8468
92
- langtrace_python_sdk/version.py,sha256=D-g59GCDAYNGtmSDbA58lus9aZV9I6vr9VPEHibmnVQ,22
93
- langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
91
+ langtrace_python_sdk/langtrace.py,sha256=labHlbgL6BbGwmreWT0xJwD2UxNU2vLOmojBzRQslR8,9771
92
+ langtrace_python_sdk/version.py,sha256=nuL9dghQK8vN4aR24DmbKir_FPU7ZcuF5DEn_IKqPMA,23
93
+ langtrace_python_sdk/constants/__init__.py,sha256=3CNYkWMdd1DrkGqzLUgNZXjdAlM6UFMlf_F-odAToyc,146
94
94
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
95
95
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  langtrace_python_sdk/constants/instrumentation/anthropic.py,sha256=YX3llt3zwDY6XrYk3CB8WEVqgrzRXEw_ffyk56JoF3k,126
@@ -123,7 +123,7 @@ langtrace_python_sdk/instrumentation/cohere/instrumentation.py,sha256=YQFHZIBd7S
123
123
  langtrace_python_sdk/instrumentation/cohere/patch.py,sha256=L-Lmh1apO7XiyJnByZk8F-icjrKqAwVo0JZUQS3uNNQ,20873
124
124
  langtrace_python_sdk/instrumentation/crewai/__init__.py,sha256=_UBKfvQv7l0g2_wnmA5F6CdSAFH0atNOVPd49zsN3aM,88
125
125
  langtrace_python_sdk/instrumentation/crewai/instrumentation.py,sha256=5Umzq8zjEnMEtjZZiMB4DQOPkxZ-1vts7RKC6JWpn24,2969
126
- langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=CHTYkioOMifIzK5o7BMJLgh0D_cnbHQN3fbUqaLGBpI,8896
126
+ langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=C2OKKPC-pzfzZWxPc74kHdYsKTX9yRhOgVY47WY9KN8,9109
127
127
  langtrace_python_sdk/instrumentation/dspy/__init__.py,sha256=tM1srfi_QgyCzrde4izojMrRq2Wm7Dj5QUvVQXIJzkk,84
128
128
  langtrace_python_sdk/instrumentation/dspy/instrumentation.py,sha256=o8URiDvCbZ8LL0I-4xKHkn_Ms2sETBRpn-gOliv3xzQ,2929
129
129
  langtrace_python_sdk/instrumentation/dspy/patch.py,sha256=eddxKIzJSUzZOcqg5LIwv9P0t66RXjB2NesDYGoJs8c,9898
@@ -174,12 +174,12 @@ langtrace_python_sdk/instrumentation/weaviate/__init__.py,sha256=Mc-Je6evPo-kKQz
174
174
  langtrace_python_sdk/instrumentation/weaviate/instrumentation.py,sha256=bzPwtoQD0X6beLYXe6ZL7XRkyRkqdiqKiGc4gOlCQdU,2295
175
175
  langtrace_python_sdk/instrumentation/weaviate/patch.py,sha256=3qxhJjEnu5lNb6_x0p82PaFBgXul-b0XTyTQV1JHzhw,6597
176
176
  langtrace_python_sdk/types/__init__.py,sha256=MeGkmoy2OY3V21GErDIdlf_N8Aj7HDld5Tpbvq2PwTY,4104
177
- langtrace_python_sdk/utils/__init__.py,sha256=giTHkvDOQdqFqXU4PoGP7DhA9tAteZN-KxX3mEUg6QQ,893
177
+ langtrace_python_sdk/utils/__init__.py,sha256=E_e67mDn5fSGF3qcYilz2X2qtqAiIS0HTpbh9kzYcXY,967
178
178
  langtrace_python_sdk/utils/langtrace_sampler.py,sha256=BupNndHbU9IL_wGleKetz8FdcveqHMBVz1bfKTTW80w,1753
179
179
  langtrace_python_sdk/utils/llm.py,sha256=k16jQL3wf1dYIDOcXSvHVfL0s97cu3QVLMmZmtTT3Gk,14741
180
180
  langtrace_python_sdk/utils/misc.py,sha256=7PRJ45BwuwJ6fPAdy1OpBau8QERR2aWaVvzDvZ7JTkE,1729
181
181
  langtrace_python_sdk/utils/prompt_registry.py,sha256=n5dQMVLBw8aJZY8Utvf67bncc25ELf6AH9BYw8_hSzo,2619
182
- langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
182
+ langtrace_python_sdk/utils/sdk_version_checker.py,sha256=F-VVVH7Fmhr5LcY0IIe-34zIi5RQcx26uuxFpPzZesM,1782
183
183
  langtrace_python_sdk/utils/silently_fail.py,sha256=wzmvRDZppaRZgVP8C1xpq2GlWXYCwubhaeWvEbQP1SI,1196
184
184
  langtrace_python_sdk/utils/types.py,sha256=l-N6o7cnWUyrD6dBvW7W3Pf5CkPo5QaoT__k1XLbrQg,383
185
185
  langtrace_python_sdk/utils/with_root_span.py,sha256=2iWu8XD1NOFqSFgDZDJiMHZ1JB4HzmYPLr_F3Ugul2k,8480
@@ -225,8 +225,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
225
225
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
226
226
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
227
227
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
228
- langtrace_python_sdk-2.3.9.dist-info/METADATA,sha256=l8f-KcSKM_uYw_-ngMN4NgbnNeZ5dawGPardr7r2_YI,15011
229
- langtrace_python_sdk-2.3.9.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
230
- langtrace_python_sdk-2.3.9.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
231
- langtrace_python_sdk-2.3.9.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
232
- langtrace_python_sdk-2.3.9.dist-info/RECORD,,
228
+ langtrace_python_sdk-2.3.11.dist-info/METADATA,sha256=6ZhhzV4Eyq5rgOMd1k-fLf20WBgoKzS8yPd6KTG7bLo,15265
229
+ langtrace_python_sdk-2.3.11.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
230
+ langtrace_python_sdk-2.3.11.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
231
+ langtrace_python_sdk-2.3.11.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
232
+ langtrace_python_sdk-2.3.11.dist-info/RECORD,,