langtrace-python-sdk 2.2.8__py3-none-any.whl → 2.2.9__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.
@@ -25,6 +25,7 @@ from langtrace_python_sdk.utils.llm import (
25
25
  get_llm_url,
26
26
  is_streaming,
27
27
  set_event_completion,
28
+ set_event_completion_chunk,
28
29
  set_usage_attributes,
29
30
  )
30
31
  from opentelemetry.trace import SpanKind
@@ -119,10 +120,7 @@ def messages_create(original_method, version, tracer):
119
120
  # Assuming span.add_event is part of a larger logging or event system
120
121
  # Add event for each chunk of content
121
122
  if content:
122
- span.add_event(
123
- Event.STREAM_OUTPUT.value,
124
- {SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: "".join(content)},
125
- )
123
+ set_event_completion_chunk(span, "".join(content))
126
124
 
127
125
  # Assuming this is part of a generator, yield chunk or aggregated content
128
126
  yield content
@@ -22,6 +22,7 @@ from langtrace_python_sdk.utils.llm import (
22
22
  get_extra_attributes,
23
23
  get_llm_url,
24
24
  set_event_completion,
25
+ set_event_completion_chunk,
25
26
  set_usage_attributes,
26
27
  )
27
28
  from langtrace.trace_attributes import Event, LLMSpanAttributes
@@ -403,10 +404,7 @@ def chat_stream(original_method, version, tracer):
403
404
  content = event.text
404
405
  else:
405
406
  content = ""
406
- span.add_event(
407
- Event.STREAM_OUTPUT.value,
408
- {SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: "".join(content)},
409
- )
407
+ set_event_completion_chunk(span, "".join(content))
410
408
 
411
409
  if (
412
410
  hasattr(event, "finish_reason")
@@ -30,6 +30,7 @@ from langtrace_python_sdk.utils.llm import (
30
30
  get_llm_url,
31
31
  get_langtrace_attributes,
32
32
  set_event_completion,
33
+ set_event_completion_chunk,
33
34
  set_usage_attributes,
34
35
  )
35
36
  from langtrace_python_sdk.constants.instrumentation.common import (
@@ -242,15 +243,14 @@ def chat_completions_create(original_method, version, tracer):
242
243
  content = content + []
243
244
  else:
244
245
  content = []
245
- span.add_event(
246
- Event.STREAM_OUTPUT.value,
247
- {
248
- SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: (
249
- "".join(content)
250
- if len(content) > 0 and content[0] is not None
251
- else ""
252
- )
253
- },
246
+
247
+ set_event_completion_chunk(
248
+ span,
249
+ (
250
+ "".join(content)
251
+ if len(content) > 0 and content[0] is not None
252
+ else ""
253
+ ),
254
254
  )
255
255
  result_content.append(content[0] if len(content) > 0 else "")
256
256
  yield chunk
@@ -6,6 +6,7 @@ from langtrace_python_sdk.utils.llm import (
6
6
  get_llm_request_attributes,
7
7
  get_llm_url,
8
8
  set_event_completion,
9
+ set_event_completion_chunk,
9
10
  )
10
11
  from langtrace_python_sdk.utils.silently_fail import silently_fail
11
12
  from langtrace_python_sdk.constants.instrumentation.common import SERVICE_PROVIDERS
@@ -177,12 +178,8 @@ def _handle_streaming_response(span, response, api):
177
178
  if api == "generate":
178
179
  accumulated_tokens["response"] += chunk["response"]
179
180
 
180
- span.add_event(
181
- Event.STREAM_OUTPUT.value,
182
- {
183
- SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: chunk.get("response")
184
- or chunk.get("message").get("content"),
185
- },
181
+ set_event_completion_chunk(
182
+ span, chunk.get("response") or chunk.get("message").get("content")
186
183
  )
187
184
 
188
185
  _set_response_attributes(span, chunk | accumulated_tokens)
@@ -211,12 +208,7 @@ async def _ahandle_streaming_response(span, response, api):
211
208
  if api == "generate":
212
209
  accumulated_tokens["response"] += chunk["response"]
213
210
 
214
- span.add_event(
215
- Event.STREAM_OUTPUT.value,
216
- {
217
- SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: json.dumps(chunk),
218
- },
219
- )
211
+ set_event_completion_chunk(span, chunk)
220
212
  _set_response_attributes(span, chunk | accumulated_tokens)
221
213
  finally:
222
214
  # Finalize span after processing all chunks
@@ -2,23 +2,32 @@ from openai import NOT_GIVEN
2
2
  from .sdk_version_checker import SDKVersionChecker
3
3
  from opentelemetry.trace import Span
4
4
  from langtrace.trace_attributes import SpanAttributes
5
+ import os
5
6
 
6
7
 
7
8
  def set_span_attribute(span: Span, name, value):
8
9
  if value is not None:
9
10
  if value != "" or value != NOT_GIVEN:
10
11
  if name == SpanAttributes.LLM_PROMPTS:
11
- span.add_event(
12
- name=SpanAttributes.LLM_CONTENT_PROMPT,
13
- attributes={
14
- SpanAttributes.LLM_PROMPTS: value,
15
- },
16
- )
12
+ set_event_prompt(span, value)
17
13
  else:
18
14
  span.set_attribute(name, value)
19
15
  return
20
16
 
21
17
 
18
+ def set_event_prompt(span: Span, prompt):
19
+ enabled = os.environ.get("TRACE_PROMPT_COMPLETION_DATA", "true")
20
+ if enabled.lower() == "false":
21
+ return
22
+
23
+ span.add_event(
24
+ name=SpanAttributes.LLM_CONTENT_PROMPT,
25
+ attributes={
26
+ SpanAttributes.LLM_PROMPTS: prompt,
27
+ },
28
+ )
29
+
30
+
22
31
  def check_if_sdk_is_outdated():
23
32
  SDKVersionChecker().check()
24
33
  return
@@ -30,6 +30,7 @@ import json
30
30
  from opentelemetry import baggage
31
31
  from opentelemetry.trace import Span
32
32
  from opentelemetry.trace.status import StatusCode
33
+ import os
33
34
 
34
35
 
35
36
  def estimate_tokens(prompt):
@@ -42,6 +43,9 @@ def estimate_tokens(prompt):
42
43
 
43
44
 
44
45
  def set_event_completion_chunk(span: Span, chunk):
46
+ enabled = os.environ.get("TRACE_PROMPT_COMPLETION_DATA", "true")
47
+ if enabled.lower() == "false":
48
+ return
45
49
  span.add_event(
46
50
  name=SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK,
47
51
  attributes={
@@ -203,6 +207,9 @@ def get_tool_calls(item):
203
207
 
204
208
 
205
209
  def set_event_completion(span: Span, result_content):
210
+ enabled = os.environ.get("TRACE_PROMPT_COMPLETION_DATA", "true")
211
+ if enabled.lower() == "false":
212
+ return
206
213
 
207
214
  span.add_event(
208
215
  name=SpanAttributes.LLM_CONTENT_COMPLETION,
@@ -352,15 +359,9 @@ class StreamWrapper:
352
359
  )
353
360
  self.completion_tokens += token_counts
354
361
  content.append(tool_call.function.arguments)
355
- self.span.add_event(
356
- Event.STREAM_OUTPUT.value,
357
- {
358
- SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: (
359
- "".join(content)
360
- if len(content) > 0 and content[0] is not None
361
- else ""
362
- )
363
- },
362
+ set_event_completion_chunk(
363
+ self.span,
364
+ "".join(content) if len(content) > 0 and content[0] is not None else "",
364
365
  )
365
366
  if content:
366
367
  self.result_content.append(content[0])
@@ -369,16 +370,11 @@ class StreamWrapper:
369
370
  token_counts = estimate_tokens(chunk.text)
370
371
  self.completion_tokens += token_counts
371
372
  content = [chunk.text]
372
- self.span.add_event(
373
- Event.STREAM_OUTPUT.value,
374
- {
375
- SpanAttributes.LLM_CONTENT_COMPLETION_CHUNK: (
376
- "".join(content)
377
- if len(content) > 0 and content[0] is not None
378
- else ""
379
- )
380
- },
373
+ set_event_completion_chunk(
374
+ self.span,
375
+ "".join(content) if len(content) > 0 and content[0] is not None else "",
381
376
  )
377
+
382
378
  if content:
383
379
  self.result_content.append(content[0])
384
380
 
@@ -1 +1 @@
1
- __version__ = "2.2.8"
1
+ __version__ = "2.2.9"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.8
3
+ Version: 2.2.9
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>
@@ -273,6 +273,11 @@ from langtrace_python_sdk import get_prompt_from_registry
273
273
  prompt = get_prompt_from_registry(<Registry ID>, options={"prompt_version": 1, "variables": {"foo": "bar"} })
274
274
  ```
275
275
 
276
+ ### Opt out of tracing prompt and completion data
277
+ By default, prompt and completion data are captured. If you would like to opt out of it, set the following env var,
278
+
279
+ `TRACE_PROMPT_COMPLETION_DATA=false`
280
+
276
281
  ## Supported integrations
277
282
 
278
283
  Langtrace automatically captures traces from the following vendors:
@@ -62,7 +62,7 @@ examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56sn
62
62
  examples/weaviate_example/query_text.py,sha256=sG8O-bXQpflBAiYpgE_M2X7GcHUlZNgl_wJW8_h-W6Q,127024
63
63
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
64
64
  langtrace_python_sdk/langtrace.py,sha256=1L0IjME-pzEYht92QfwByPZr3H1MClTrqQdoN1KyKJY,7689
65
- langtrace_python_sdk/version.py,sha256=YZuLtr55Kuq9kEWnoXMkj5a8XMpLccTIPbg7OO2S8KM,22
65
+ langtrace_python_sdk/version.py,sha256=4yiQmg1jez9eDe7VvOU40EgTkcAYoip5MZXkPgQyf-I,22
66
66
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
67
67
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
68
68
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -84,13 +84,13 @@ langtrace_python_sdk/extensions/langtrace_filesystem.py,sha256=34fZutG28EJ66l67O
84
84
  langtrace_python_sdk/instrumentation/__init__.py,sha256=yJd3aGu4kPfm2h6oe6kiCWvzTF9awpC1UztjXF9WSO4,1391
85
85
  langtrace_python_sdk/instrumentation/anthropic/__init__.py,sha256=donrurJAGYlxrSRA3BIf76jGeUcAx9Tq8CVpah68S0Y,101
86
86
  langtrace_python_sdk/instrumentation/anthropic/instrumentation.py,sha256=-srgE8qumAn0ulQYZxMa8ch-9IBH0XgBW_rfEnGk6LI,1684
87
- langtrace_python_sdk/instrumentation/anthropic/patch.py,sha256=Ol0U6vi5UG55ZC_Y7RBmuW87x0FCerAIbio0GSNjOqk,6914
87
+ langtrace_python_sdk/instrumentation/anthropic/patch.py,sha256=aii6bcdMQFfwsSbOKoMtqA3bCJdBW2GalD425H5bpvg,6819
88
88
  langtrace_python_sdk/instrumentation/chroma/__init__.py,sha256=pNZ5UO8Q-d5VkXSobBf79reB6AmEl_usnnTp5Itv818,95
89
89
  langtrace_python_sdk/instrumentation/chroma/instrumentation.py,sha256=nT6PS6bsrIOO9kLV5GuUeRjMe6THHHAZGvqWBP1dYog,1807
90
90
  langtrace_python_sdk/instrumentation/chroma/patch.py,sha256=JfFc8SDfwkEyIwTd1yM6jwa1vu5hZH6IXyxAEcQQQOs,9010
91
91
  langtrace_python_sdk/instrumentation/cohere/__init__.py,sha256=sGUSLdTUyYf36Tm6L5jQflhzCqvmWrhnBOMYHjvp6Hs,95
92
92
  langtrace_python_sdk/instrumentation/cohere/instrumentation.py,sha256=YQFHZIBd7SSPD4b6Va-ZR0thf_AuBCqj5yzHLHJVWnM,2121
93
- langtrace_python_sdk/instrumentation/cohere/patch.py,sha256=_0mmJ9eCjokkJTQTXWYK2hSd5XY02_iu5PW6HB6DvQI,21175
93
+ langtrace_python_sdk/instrumentation/cohere/patch.py,sha256=Qokp9qPTYwRvQzp3dTG2_g6r3EC3zJT1fujyJo30fXE,21080
94
94
  langtrace_python_sdk/instrumentation/crewai/__init__.py,sha256=_UBKfvQv7l0g2_wnmA5F6CdSAFH0atNOVPd49zsN3aM,88
95
95
  langtrace_python_sdk/instrumentation/crewai/instrumentation.py,sha256=q07x6nnig9JPxDT6ZylyIShfXWjNafKBetnNcA1UdEU,1836
96
96
  langtrace_python_sdk/instrumentation/crewai/patch.py,sha256=Vnpip9Pbk4UFbTFHoUrHtAnDgsaihwSvZBgtUeOtLr8,6109
@@ -102,7 +102,7 @@ langtrace_python_sdk/instrumentation/gemini/instrumentation.py,sha256=rhGOt1YsTm
102
102
  langtrace_python_sdk/instrumentation/gemini/patch.py,sha256=XtsxD9vbe4lv4o8K8iRb9K1-U8DrjtUG6rWCYkCdJuc,6315
103
103
  langtrace_python_sdk/instrumentation/groq/__init__.py,sha256=ZXeq_nrej6Lm_uoMFEg8wbSejhjB2UJ5IoHQBPc2-C0,91
104
104
  langtrace_python_sdk/instrumentation/groq/instrumentation.py,sha256=Ttf07XVKhdYY1_fqJc7QWiSdmgEhEVyQB_3Az2_wqYo,1832
105
- langtrace_python_sdk/instrumentation/groq/patch.py,sha256=y9WxhPfDmxGfAip1dL4vOAW3FTmFHKLMgPlZjK0m0js,23839
105
+ langtrace_python_sdk/instrumentation/groq/patch.py,sha256=WHCPnzbg5GYkW58gIWs8TbDsmri7HxHTk7m9LqdRfWM,23754
106
106
  langtrace_python_sdk/instrumentation/langchain/__init__.py,sha256=-7ZkqQFu64F-cxSFd1ZPrciODKqmUIyUbQQ-eHuQPyM,101
107
107
  langtrace_python_sdk/instrumentation/langchain/instrumentation.py,sha256=_Z4AeNb2hBPSCvMRxE-mUfmkUO_wP_tGGtu-jppWPiI,3462
108
108
  langtrace_python_sdk/instrumentation/langchain/patch.py,sha256=2ZgLdgQpvie4PtpVC068T3KUEBqcLQCRsdyThmKh7VQ,4089
@@ -120,7 +120,7 @@ langtrace_python_sdk/instrumentation/llamaindex/instrumentation.py,sha256=8iAg-O
120
120
  langtrace_python_sdk/instrumentation/llamaindex/patch.py,sha256=OGk7ps438gW49zvJQCDp7ZmkQnFxouAUu2PvHbmcAP8,4496
121
121
  langtrace_python_sdk/instrumentation/ollama/__init__.py,sha256=g2zJsXnDHinXPzTc-WxDeTtHmr9gmAj3K6l_00kP8c8,82
122
122
  langtrace_python_sdk/instrumentation/ollama/instrumentation.py,sha256=jdsvkqUJAAUNLVPtAkn_rG26HXetVQXWtjn4a6eWZro,2029
123
- langtrace_python_sdk/instrumentation/ollama/patch.py,sha256=Twi3yeGgBj0DadBmZ0X0DsMPx71iSdL4R3OjOw3-p_E,8132
123
+ langtrace_python_sdk/instrumentation/ollama/patch.py,sha256=ky58NUyAETmaOqSAsB-LzDpoCosY6W54YeAJ9XftE-Q,7878
124
124
  langtrace_python_sdk/instrumentation/openai/__init__.py,sha256=VPHRNCQEdkizIVP2d0Uw_a7t8XOTSTprEIB8oboJFbs,95
125
125
  langtrace_python_sdk/instrumentation/openai/instrumentation.py,sha256=A0BJHRLcZ74TNVg6I0I9M5YWvSpAtXwMmME6N5CEQ_M,2945
126
126
  langtrace_python_sdk/instrumentation/openai/patch.py,sha256=T0g9BbUw5JWSupZbWCF6sQxO2Auj_oPpAFw0RdVkKLg,24075
@@ -137,9 +137,9 @@ langtrace_python_sdk/instrumentation/weaviate/__init__.py,sha256=Mc-Je6evPo-kKQz
137
137
  langtrace_python_sdk/instrumentation/weaviate/instrumentation.py,sha256=oWLCnh5_Nuw8bKpXJW6Zo-PpI_kJ7q2nA4BImnZ7YqY,2295
138
138
  langtrace_python_sdk/instrumentation/weaviate/patch.py,sha256=rRD6WfQcNGYpw9teoCkGPCZkzolG0h-mZdPGNKkgE10,5971
139
139
  langtrace_python_sdk/types/__init__.py,sha256=KDW6S74FDxpeBa9xoH5zVEYfmRjccCCHzlW7lTJg1TA,3194
140
- langtrace_python_sdk/utils/__init__.py,sha256=QPF7SMuiz_003fLCHkRrgNb9NjqErDQ5cQr6pkJReKc,724
140
+ langtrace_python_sdk/utils/__init__.py,sha256=SwYYPIh2AzEpI3zbwowQU2zJlwRwoVdWOCcrAKnkI9g,873
141
141
  langtrace_python_sdk/utils/langtrace_sampler.py,sha256=BupNndHbU9IL_wGleKetz8FdcveqHMBVz1bfKTTW80w,1753
142
- langtrace_python_sdk/utils/llm.py,sha256=bvJkU3IGt_ssx5taY_Dx5GkgxGJ9Jqc1CrKElMVJ5to,12983
142
+ langtrace_python_sdk/utils/llm.py,sha256=YLUqbHQWZwJBWtX2xyyiOXxfOkYdVFGSQmnMW6OEiYo,12852
143
143
  langtrace_python_sdk/utils/misc.py,sha256=CD9NWRLxLpFd0YwlHJqzlpFNedXVWtAKGOjQWnDCo8k,838
144
144
  langtrace_python_sdk/utils/prompt_registry.py,sha256=n5dQMVLBw8aJZY8Utvf67bncc25ELf6AH9BYw8_hSzo,2619
145
145
  langtrace_python_sdk/utils/sdk_version_checker.py,sha256=FzjIWZjn53cX0LEVPdipQd1fO9lG8iGVUEVUs9Hyk6M,1713
@@ -188,8 +188,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
188
188
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
189
189
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
190
190
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
191
- langtrace_python_sdk-2.2.8.dist-info/METADATA,sha256=YwWKH01P-qaU1otk19smm_jTfFxCWECL9bvMzumEEOU,14499
192
- langtrace_python_sdk-2.2.8.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
193
- langtrace_python_sdk-2.2.8.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
194
- langtrace_python_sdk-2.2.8.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
195
- langtrace_python_sdk-2.2.8.dist-info/RECORD,,
191
+ langtrace_python_sdk-2.2.9.dist-info/METADATA,sha256=awDVdeawZ8uvZro-f7KlAYL7A9JQmpFDC8U-Zfn14v8,14704
192
+ langtrace_python_sdk-2.2.9.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
193
+ langtrace_python_sdk-2.2.9.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
194
+ langtrace_python_sdk-2.2.9.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
195
+ langtrace_python_sdk-2.2.9.dist-info/RECORD,,