langtrace-python-sdk 2.2.3__py3-none-any.whl → 2.2.5__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.
@@ -5,7 +5,7 @@ from dspy.teleprompt import BootstrapFewShot
5
5
  from concurrent.futures import ThreadPoolExecutor
6
6
 
7
7
  # flake8: noqa
8
- from langtrace_python_sdk import langtrace, with_langtrace_root_span
8
+ from langtrace_python_sdk import langtrace, with_langtrace_root_span, inject_additional_attributes
9
9
 
10
10
  langtrace.init()
11
11
 
@@ -1,24 +1,32 @@
1
- # langtrace.init(write_spans_to_console=True)
2
1
  import fsspec
3
2
  from inspect_ai import Task, task
4
- from inspect_ai.dataset import csv_dataset
3
+ from inspect_ai.dataset import csv_dataset, Sample
5
4
  from inspect_ai.scorer import model_graded_qa
6
- from inspect_ai.solver import chain_of_thought, generate, self_critique
7
-
5
+ from inspect_ai.solver import chain_of_thought, self_critique
8
6
  from langtrace_python_sdk.extensions.langtrace_filesystem import LangTraceFileSystem
9
7
 
10
- # from langtrace_python_sdk import langtrace
11
-
12
8
 
13
9
  # Manually register the filesystem with fsspec
14
10
  # Note: This is only necessary because the filesystem is not registered.
15
11
  fsspec.register_implementation(LangTraceFileSystem.protocol, LangTraceFileSystem)
16
12
 
13
+ question = "What is the price?"
14
+
15
+
16
+ def hydrate_with_question(record):
17
+ # add context to input
18
+ record["input"] = f"Context: {record['input']}\n question: {question}"
19
+
20
+ return Sample(
21
+ input=record["input"],
22
+ target=record["target"],
23
+ )
24
+
17
25
 
18
26
  @task
19
- def security_guide():
27
+ def pricing_question():
20
28
  return Task(
21
- dataset=csv_dataset("langtracefs://clxc2mxu6000lpc7ntsvcjvp9"),
29
+ dataset=csv_dataset("langtracefs://clyythmcs0001145cuvi426zi", hydrate_with_question),
22
30
  plan=[chain_of_thought(), self_critique()],
23
31
  scorer=model_graded_qa(),
24
32
  )
@@ -0,0 +1,34 @@
1
+ from langtrace_python_sdk import langtrace
2
+ from openai import OpenAI
3
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
4
+
5
+ service_name = "langtrace-python-ollama"
6
+ otlp_endpoint = "http://localhost:4318/v1/traces"
7
+ otlp_exporter = OTLPSpanExporter(
8
+ endpoint=otlp_endpoint,
9
+ headers=(("Content-Type", "application/json"),))
10
+ langtrace.init(custom_remote_exporter=otlp_exporter, batch=False)
11
+
12
+
13
+ def chat_with_ollama():
14
+ # Use the OpenAI endpoint, not the Ollama API.
15
+ base_url = "http://localhost:11434/v1"
16
+ client = OpenAI(base_url=base_url, api_key="unused")
17
+ messages = [
18
+ {
19
+ "role": "user",
20
+ "content": "Hello, I'm a human.",
21
+ },
22
+ ]
23
+ chat_completion = client.chat.completions.create(
24
+ model="llama3", messages=messages
25
+ )
26
+ print(chat_completion.choices[0].message.content)
27
+
28
+
29
+ def main():
30
+ chat_with_ollama()
31
+
32
+
33
+ if __name__ == "__main__":
34
+ main()
@@ -0,0 +1,43 @@
1
+ # Instructions
2
+ # 1. Run the OpenTelemetry Collector with the OTLP receiver enabled
3
+ # Create otel-config.yaml with the following content:
4
+ # receivers:
5
+ # otlp:
6
+ # protocols:
7
+ # grpc:
8
+ # endpoint: "0.0.0.0:4317"
9
+ # http:
10
+ # endpoint: "0.0.0.0:4318"
11
+
12
+ # exporters:
13
+ # logging:
14
+ # loglevel: debug
15
+
16
+ # service:
17
+ # pipelines:
18
+ # traces:
19
+ # receivers: [otlp]
20
+ # exporters: [logging]
21
+ # docker pull otel/opentelemetry-collector:latest
22
+ # docker run --rm -p 4317:4317 -p 4318:4318 -v $(pwd)/otel-config.yaml:/otel-config.yaml otel/opentelemetry-collector --config otel-config.yaml
23
+ # 2. Run the following code
24
+
25
+ from opentelemetry import trace
26
+ from opentelemetry.sdk.trace import TracerProvider
27
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
28
+ from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
29
+
30
+ # Set up the tracer provider
31
+ trace.set_tracer_provider(TracerProvider())
32
+ tracer = trace.get_tracer(__name__)
33
+
34
+ # Set up the OTLP exporter
35
+ otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4317")
36
+
37
+ # Set up a span processor and add it to the tracer provider
38
+ span_processor = BatchSpanProcessor(otlp_exporter)
39
+ trace.get_tracer_provider().add_span_processor(span_processor)
40
+
41
+ # Create a span
42
+ with tracer.start_as_current_span("example-span"):
43
+ print("Hello, World!")
@@ -104,10 +104,10 @@ def chat_completions_create(original_method, version, tracer):
104
104
 
105
105
  # TODO(Karthik): Gotta figure out how to handle streaming with context
106
106
  # with tracer.start_as_current_span(APIS["CHAT_COMPLETION"]["METHOD"],
107
- # kind=SpanKind.CLIENT.value) as span:
107
+ # kind=SpanKind.CLIENT) as span:
108
108
  span = tracer.start_span(
109
109
  APIS["CHAT_COMPLETION"]["METHOD"],
110
- kind=SpanKind.CLIENT.value,
110
+ kind=SpanKind.CLIENT,
111
111
  context=set_span_in_context(trace.get_current_span()),
112
112
  )
113
113
  for field, value in attributes.model_dump(by_alias=True).items():
@@ -333,9 +333,9 @@ def async_chat_completions_create(original_method, version, tracer):
333
333
 
334
334
  # TODO(Karthik): Gotta figure out how to handle streaming with context
335
335
  # with tracer.start_as_current_span(APIS["CHAT_COMPLETION"]["METHOD"],
336
- # kind=SpanKind.CLIENT.value) as span:
336
+ # kind=SpanKind.CLIENT) as span:
337
337
  span = tracer.start_span(
338
- APIS["CHAT_COMPLETION"]["METHOD"], kind=SpanKind.CLIENT.value
338
+ APIS["CHAT_COMPLETION"]["METHOD"], kind=SpanKind.CLIENT
339
339
  )
340
340
  for field, value in attributes.model_dump(by_alias=True).items():
341
341
  set_span_attribute(span, field, value)
@@ -65,7 +65,7 @@ def images_generate(original_method, version, tracer):
65
65
 
66
66
  with tracer.start_as_current_span(
67
67
  APIS["IMAGES_GENERATION"]["METHOD"],
68
- kind=SpanKind.CLIENT.value,
68
+ kind=SpanKind.CLIENT,
69
69
  context=set_span_in_context(trace.get_current_span()),
70
70
  ) as span:
71
71
  set_span_attributes(span, attributes)
@@ -128,7 +128,7 @@ def async_images_generate(original_method, version, tracer):
128
128
 
129
129
  with tracer.start_as_current_span(
130
130
  APIS["IMAGES_GENERATION"]["METHOD"],
131
- kind=SpanKind.CLIENT.value,
131
+ kind=SpanKind.CLIENT,
132
132
  context=set_span_in_context(trace.get_current_span()),
133
133
  ) as span:
134
134
  set_span_attributes(span, attributes)
@@ -193,7 +193,7 @@ def images_edit(original_method, version, tracer):
193
193
 
194
194
  with tracer.start_as_current_span(
195
195
  APIS["IMAGES_EDIT"]["METHOD"],
196
- kind=SpanKind.CLIENT.value,
196
+ kind=SpanKind.CLIENT,
197
197
  context=set_span_in_context(trace.get_current_span()),
198
198
  ) as span:
199
199
  set_span_attributes(span, attributes)
@@ -283,7 +283,7 @@ def chat_completions_create(original_method, version, tracer):
283
283
 
284
284
  span = tracer.start_span(
285
285
  APIS["CHAT_COMPLETION"]["METHOD"],
286
- kind=SpanKind.CLIENT.value,
286
+ kind=SpanKind.CLIENT,
287
287
  context=set_span_in_context(trace.get_current_span()),
288
288
  )
289
289
  _set_input_attributes(span, kwargs, attributes)
@@ -377,7 +377,7 @@ def async_chat_completions_create(original_method, version, tracer):
377
377
 
378
378
  span = tracer.start_span(
379
379
  APIS["CHAT_COMPLETION"]["METHOD"],
380
- kind=SpanKind.CLIENT.value,
380
+ kind=SpanKind.CLIENT,
381
381
  context=set_span_in_context(trace.get_current_span()),
382
382
  )
383
383
  _set_input_attributes(span, kwargs, attributes)
@@ -456,7 +456,7 @@ def embeddings_create(original_method, version, tracer):
456
456
 
457
457
  with tracer.start_as_current_span(
458
458
  APIS["EMBEDDINGS_CREATE"]["METHOD"],
459
- kind=SpanKind.CLIENT.value,
459
+ kind=SpanKind.CLIENT,
460
460
  context=set_span_in_context(trace.get_current_span()),
461
461
  ) as span:
462
462
 
@@ -513,7 +513,7 @@ def async_embeddings_create(original_method, version, tracer):
513
513
 
514
514
  with tracer.start_as_current_span(
515
515
  APIS["EMBEDDINGS_CREATE"]["METHOD"],
516
- kind=SpanKind.CLIENT.value,
516
+ kind=SpanKind.CLIENT,
517
517
  context=set_span_in_context(trace.get_current_span()),
518
518
  ) as span:
519
519
 
@@ -1 +1 @@
1
- __version__ = "2.2.3"
1
+ __version__ = "2.2.5"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: langtrace-python-sdk
3
- Version: 2.2.3
3
+ Version: 2.2.5
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>
@@ -20,7 +20,7 @@ Requires-Dist: opentelemetry-instrumentation>=0.46b0
20
20
  Requires-Dist: opentelemetry-sdk>=1.25.0
21
21
  Requires-Dist: sqlalchemy
22
22
  Requires-Dist: tiktoken>=0.1.1
23
- Requires-Dist: trace-attributes<7.0.0,>=6.0.0
23
+ Requires-Dist: trace-attributes<7.0.0,>=6.0.3
24
24
  Provides-Extra: dev
25
25
  Requires-Dist: anthropic; extra == 'dev'
26
26
  Requires-Dist: chromadb; extra == 'dev'
@@ -11,7 +11,7 @@ examples/cohere_example/rerank.py,sha256=e7OU0A2FzfiQDuOmCy3Kg5LLNYGRmRIK5LqeLnT
11
11
  examples/cohere_example/tools.py,sha256=a5uvS058tcwU6PJbF9EDO6LPVmPj2LoW4Vn8Web3Iq8,1656
12
12
  examples/crewai_example/basic.py,sha256=PBu4f8yQfZO1L_22UDm_ReU9lnEcycjZcGuy5UpgDJM,1948
13
13
  examples/dspy_example/math_problems_cot.py,sha256=Z98nB6myt8WJse2dWS6Ap7CFUhC27lBNb37R1Gg80VQ,1282
14
- examples/dspy_example/math_problems_cot_parallel.py,sha256=s3jdEjhwZD-Dd2-EqYFrA_dc3D3vm5bhMwFRYAjCCJw,1734
14
+ examples/dspy_example/math_problems_cot_parallel.py,sha256=5clw-IIVA0mWm0N0xWNDMQaSY07YVYW8R1mcyCJJ1_8,1764
15
15
  examples/dspy_example/program_of_thought_basic.py,sha256=oEbtJdeKENMUbex25-zyStWwurRWW6OdP0KDs-jUkko,984
16
16
  examples/dspy_example/quiz_gen.py,sha256=OyGhepeX8meKOtLdmlYUjMD2ECk-ZQuQXUZif1hFQY4,3371
17
17
  examples/dspy_example/react.py,sha256=APAnHqgy9w-qY5jnPD_WbBx6bwo9C-DhPnUuhL-t7sg,1376
@@ -21,7 +21,7 @@ examples/gemini_example/__init__.py,sha256=omVgLyIiLc3c0zwy3vTtYKdeenYEXzEbLZsYi
21
21
  examples/gemini_example/function_tools.py,sha256=ZOBrdPy_8s3NDfsF5A4RXIoUi2VXlD8og4UsWz_8AuQ,2700
22
22
  examples/gemini_example/main.py,sha256=cTXqgOa6lEMwgX56uneM-1TbIY_QZtDRkByW5z0LpNk,2470
23
23
  examples/hiveagent_example/basic.py,sha256=Sd7I5w8w5Xx7ODaydTY30yiq9HwJDMKHQywrZjgehP0,441
24
- examples/inspect_ai_example/basic_eval.py,sha256=dUbF4yicNSG8HWxAfzS3V-813bpLyfb7Zdgo544yqGc,802
24
+ examples/inspect_ai_example/basic_eval.py,sha256=zNrAyyhFEHnDcl8AUBMyCToYxcQ_Easp5eYaRV5hCYs,994
25
25
  examples/langchain_example/__init__.py,sha256=xAys_K5AbVqaJ8d5wCcE6w2tCiTXPkSGMyY9paBXitI,410
26
26
  examples/langchain_example/basic.py,sha256=hrwMHOUv78-su5DP9i5krkQnMGHq0svEXsBa40Jkggg,2981
27
27
  examples/langchain_example/groq_example.py,sha256=egrg3FHCnSJ-kV22Z2_t9ElJfKilddfcO5bwcKCfc5M,1060
@@ -33,6 +33,7 @@ examples/llamaindex_example/basic.py,sha256=aFZngkye95sjUr4wc2Uo_Je0iEexXpNcdlV0
33
33
  examples/llamaindex_example/data/abramov.txt,sha256=Ou-GyWZm5AjHLgxviBoRE9ikNv5MScsF0cd--0vVVhI,32667
34
34
  examples/ollama_example/__init__.py,sha256=qOx0jGCPuSpRCPiqtDVm7F0z8hIZ8C75hDZ_C8Apz-s,399
35
35
  examples/ollama_example/basic.py,sha256=EPbsigOF4xBDBgLgAD0EzPo737ycVm7aXZr7F5Xt-A4,1062
36
+ examples/ollama_example/basic_example_2.py,sha256=h6hLX4Mot6H8ezg970zrh5XFVyI4zMVHeYLhvAMTQlQ,953
36
37
  examples/openai_example/__init__.py,sha256=MU4CELvhe2EU6d4Okg-bTfjvfGxQO7PNzqMw1yrVeCA,828
37
38
  examples/openai_example/async_tool_calling_nonstreaming.py,sha256=H1-CrNfNDfqAkB5wEipITXlW2OsYL7XD5uQb6k3C6ps,3865
38
39
  examples/openai_example/async_tool_calling_streaming.py,sha256=LaSKmn_Unv55eTHXYdEmKjo39eNuB3ASOBV-m8U1HfU,7136
@@ -47,6 +48,7 @@ examples/openai_example/tool_calling_nonstreaming.py,sha256=Yc848IooZRXNynHL6z0k
47
48
  examples/openai_example/tool_calling_streaming.py,sha256=mV1RbyAoVhumGRPpqPWQ6PMhnJyeifrlELd2-K1qJ_w,7015
48
49
  examples/openai_example/resources/lounge_flamingo.png,sha256=aspniTtmWqwLp3YUhYqAe2ze8nJaq-bTSW7uUJudtd0,2416234
49
50
  examples/openai_example/resources/mask.png,sha256=mUE9Dfp-x8jI0Nh4WGr0P9pueUqEZfpjwxR-6Rxzxz4,2483660
51
+ examples/otlp_example/otlp_basic.py,sha256=Ykbzu6EpO-V1wQsPePgC16eLFVym91r-ZR-SDj2mIT0,1346
50
52
  examples/perplexity_example/basic.py,sha256=bp7n27gaugJkaFVyt8pjaEfi66lYcqP6eFFjPewUShY,668
51
53
  examples/pinecone_example/__init__.py,sha256=_rvn7Ygt_QWMQoa5wB2GB0S9gZVrlJrPrEhXqU3hPKw,427
52
54
  examples/pinecone_example/basic.py,sha256=5MoHZMBxHMdC61oj-CP19gj9SxSvIcDrQL934JPZoQs,1549
@@ -58,7 +60,7 @@ examples/weaviate_example/__init__.py,sha256=8JMDBsRSEV10HfTd-YC7xb4txBjD3la56sn
58
60
  examples/weaviate_example/query_text.py,sha256=sG8O-bXQpflBAiYpgE_M2X7GcHUlZNgl_wJW8_h-W6Q,127024
59
61
  langtrace_python_sdk/__init__.py,sha256=VZM6i71NR7pBQK6XvJWRelknuTYUhqwqE7PlicKa5Wg,1166
60
62
  langtrace_python_sdk/langtrace.py,sha256=1L0IjME-pzEYht92QfwByPZr3H1MClTrqQdoN1KyKJY,7689
61
- langtrace_python_sdk/version.py,sha256=3pvG1dVJuHEcdu38cc8mGwpb57ZUjsnbAe_LVURnTPQ,22
63
+ langtrace_python_sdk/version.py,sha256=r1Tn-QXWA9VMrkPdk9c6Clll9uei6qKO7PemQL_uDYI,22
62
64
  langtrace_python_sdk/constants/__init__.py,sha256=P8QvYwt5czUNDZsKS64vxm9Dc41ptGbuF1TFtAF6nv4,44
63
65
  langtrace_python_sdk/constants/exporter/langtrace_exporter.py,sha256=5MNjnAOg-4am78J3gVMH6FSwq5N8TOj72ugkhsw4vi0,46
64
66
  langtrace_python_sdk/constants/instrumentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -98,7 +100,7 @@ langtrace_python_sdk/instrumentation/gemini/instrumentation.py,sha256=rhGOt1YsTm
98
100
  langtrace_python_sdk/instrumentation/gemini/patch.py,sha256=XtsxD9vbe4lv4o8K8iRb9K1-U8DrjtUG6rWCYkCdJuc,6315
99
101
  langtrace_python_sdk/instrumentation/groq/__init__.py,sha256=ZXeq_nrej6Lm_uoMFEg8wbSejhjB2UJ5IoHQBPc2-C0,91
100
102
  langtrace_python_sdk/instrumentation/groq/instrumentation.py,sha256=Ttf07XVKhdYY1_fqJc7QWiSdmgEhEVyQB_3Az2_wqYo,1832
101
- langtrace_python_sdk/instrumentation/groq/patch.py,sha256=zvQ0WPSHXLYQwzST-9-hRvDyjPG3vkY6FX0LeGV-Cgg,23863
103
+ langtrace_python_sdk/instrumentation/groq/patch.py,sha256=y9WxhPfDmxGfAip1dL4vOAW3FTmFHKLMgPlZjK0m0js,23839
102
104
  langtrace_python_sdk/instrumentation/langchain/__init__.py,sha256=-7ZkqQFu64F-cxSFd1ZPrciODKqmUIyUbQQ-eHuQPyM,101
103
105
  langtrace_python_sdk/instrumentation/langchain/instrumentation.py,sha256=_Z4AeNb2hBPSCvMRxE-mUfmkUO_wP_tGGtu-jppWPiI,3462
104
106
  langtrace_python_sdk/instrumentation/langchain/patch.py,sha256=2ZgLdgQpvie4PtpVC068T3KUEBqcLQCRsdyThmKh7VQ,4089
@@ -119,7 +121,7 @@ langtrace_python_sdk/instrumentation/ollama/instrumentation.py,sha256=jdsvkqUJAA
119
121
  langtrace_python_sdk/instrumentation/ollama/patch.py,sha256=Twi3yeGgBj0DadBmZ0X0DsMPx71iSdL4R3OjOw3-p_E,8132
120
122
  langtrace_python_sdk/instrumentation/openai/__init__.py,sha256=VPHRNCQEdkizIVP2d0Uw_a7t8XOTSTprEIB8oboJFbs,95
121
123
  langtrace_python_sdk/instrumentation/openai/instrumentation.py,sha256=A0BJHRLcZ74TNVg6I0I9M5YWvSpAtXwMmME6N5CEQ_M,2945
122
- langtrace_python_sdk/instrumentation/openai/patch.py,sha256=9QfXSTjpj8b4KBWqDq-md8rkX8F6GM6VMTQK_Fpjoj4,23971
124
+ langtrace_python_sdk/instrumentation/openai/patch.py,sha256=CBZ_f1os7LMCkikh6Gvv-eqEA83aWs5R3lbSrtrroJY,23929
123
125
  langtrace_python_sdk/instrumentation/pinecone/__init__.py,sha256=DzXyGh9_MGWveJvXULkFwdkf7PbG2s3bAWtT1Dmz7Ok,99
124
126
  langtrace_python_sdk/instrumentation/pinecone/instrumentation.py,sha256=HDXkRITrVPwdQEoOYJOfMzZE_2-vDDvuqHTlD8W1lQw,1845
125
127
  langtrace_python_sdk/instrumentation/pinecone/patch.py,sha256=KiIRRz8kk47FllFT746Cb_w6F6M60AN_pcsguD979E4,5172
@@ -184,8 +186,8 @@ tests/pinecone/cassettes/test_query.yaml,sha256=b5v9G3ssUy00oG63PlFUR3JErF2Js-5A
184
186
  tests/pinecone/cassettes/test_upsert.yaml,sha256=neWmQ1v3d03V8WoLl8FoFeeCYImb8pxlJBWnFd_lITU,38607
185
187
  tests/qdrant/conftest.py,sha256=9n0uHxxIjWk9fbYc4bx-uP8lSAgLBVx-cV9UjnsyCHM,381
186
188
  tests/qdrant/test_qdrant.py,sha256=pzjAjVY2kmsmGfrI2Gs2xrolfuaNHz7l1fqGQCjp5_o,3353
187
- langtrace_python_sdk-2.2.3.dist-info/METADATA,sha256=ZKVh06M9VHfn7ESym1J4vECVp8-aM9aaDqqDpjsOVHE,14471
188
- langtrace_python_sdk-2.2.3.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
189
- langtrace_python_sdk-2.2.3.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
190
- langtrace_python_sdk-2.2.3.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
191
- langtrace_python_sdk-2.2.3.dist-info/RECORD,,
189
+ langtrace_python_sdk-2.2.5.dist-info/METADATA,sha256=Q9d_8pAxJt3obqJrTALvxbRnlXyrqMn3nySOt7-x4KM,14471
190
+ langtrace_python_sdk-2.2.5.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
191
+ langtrace_python_sdk-2.2.5.dist-info/entry_points.txt,sha256=1_b9-qvf2fE7uQNZcbUei9vLpFZBbbh9LrtGw95ssAo,70
192
+ langtrace_python_sdk-2.2.5.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
193
+ langtrace_python_sdk-2.2.5.dist-info/RECORD,,