lmnr 0.4.44__py3-none-any.whl → 0.4.46__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.
lmnr/__init__.py CHANGED
@@ -7,6 +7,7 @@ from .sdk.types import (
7
7
  NodeInput,
8
8
  PipelineRunError,
9
9
  PipelineRunResponse,
10
+ TracingLevel,
10
11
  )
11
12
  from .sdk.decorators import observe
12
13
  from .openllmetry_sdk import Instruments
@@ -3,7 +3,6 @@ from functools import wraps
3
3
  import logging
4
4
  import os
5
5
  import pydantic
6
- import traceback
7
6
  import types
8
7
  from typing import Any, Optional
9
8
 
@@ -192,14 +191,4 @@ def _should_send_prompts():
192
191
 
193
192
 
194
193
  def _process_exception(span: Span, e: Exception):
195
- exception_path = [type(e).__module__] if type(e).__module__ != "builtins" else []
196
- exception_path.append(type(e).__qualname__)
197
- span.add_event(
198
- "exception",
199
- {
200
- "exception.message": str(e),
201
- "exception.type": ".".join(exception_path),
202
- "exception.stacktrace": traceback.format_exc(),
203
- "exception.escaped": True,
204
- },
205
- )
194
+ span.record_exception(e)
@@ -12,6 +12,7 @@ ASSOCIATION_PROPERTIES = "lmnr.association.properties"
12
12
  SESSION_ID = "session_id"
13
13
  USER_ID = "user_id"
14
14
  TRACE_TYPE = "trace_type"
15
+ TRACING_LEVEL = "tracing_level"
15
16
 
16
17
 
17
18
  # exposed to the user, configurable
@@ -10,6 +10,7 @@ from lmnr.openllmetry_sdk.tracing.attributes import (
10
10
  ASSOCIATION_PROPERTIES,
11
11
  SPAN_INSTRUMENTATION_SOURCE,
12
12
  SPAN_PATH,
13
+ TRACING_LEVEL,
13
14
  )
14
15
  from lmnr.openllmetry_sdk.tracing.content_allow_list import ContentAllowList
15
16
  from lmnr.openllmetry_sdk.utils import is_notebook
@@ -224,6 +225,9 @@ def remove_association_properties(properties: dict) -> None:
224
225
 
225
226
  def _set_association_properties_attributes(span, properties: dict) -> None:
226
227
  for key, value in properties.items():
228
+ if key == TRACING_LEVEL:
229
+ span.set_attribute(f"lmnr.internal.{TRACING_LEVEL}", value)
230
+ continue
227
231
  span.set_attribute(f"{ASSOCIATION_PROPERTIES}.{key}", value)
228
232
 
229
233
 
lmnr/sdk/laminar.py CHANGED
@@ -59,6 +59,7 @@ from .types import (
59
59
  SemanticSearchRequest,
60
60
  SemanticSearchResponse,
61
61
  TraceType,
62
+ TracingLevel,
62
63
  )
63
64
 
64
65
 
@@ -558,6 +559,39 @@ class Laminar:
558
559
  if output is not None and span != trace.INVALID_SPAN:
559
560
  span.set_attribute(SPAN_OUTPUT, json_dumps(output))
560
561
 
562
+ @classmethod
563
+ @contextmanager
564
+ def set_tracing_level(self, level: TracingLevel):
565
+ """Set the tracing level for the current span and the context
566
+ (i.e. any children spans created from the current span in the current
567
+ thread).
568
+
569
+ Tracing level can be one of:
570
+ - `TracingLevel.ALL`: Enable tracing for the current span and all
571
+ children spans.
572
+ - `TracingLevel.META_ONLY`: Enable tracing for the current span and all
573
+ children spans, but only record metadata, e.g. tokens, costs.
574
+ - `TracingLevel.OFF`: Disable recording any spans.
575
+
576
+ Example:
577
+ ```python
578
+ from lmnr import Laminar, TracingLevel
579
+
580
+ with Laminar.set_tracing_level(TracingLevel.META_ONLY):
581
+ openai_client.chat.completions.create()
582
+ ```
583
+ """
584
+ if level == TracingLevel.ALL:
585
+ yield
586
+ else:
587
+ level = "meta_only" if level == TracingLevel.META_ONLY else "off"
588
+ update_association_properties({"tracing_level": level})
589
+ yield
590
+ try:
591
+ remove_association_properties({"tracing_level": level})
592
+ except Exception:
593
+ pass
594
+
561
595
  @classmethod
562
596
  def set_span_attributes(
563
597
  cls,
@@ -643,20 +677,6 @@ class Laminar:
643
677
  props.pop(k)
644
678
  set_association_properties(props)
645
679
 
646
- @classmethod
647
- def _set_trace_type(
648
- cls,
649
- trace_type: TraceType,
650
- ):
651
- """Set the trace_type for the current span and the context
652
- Args:
653
- trace_type (TraceType): Type of the trace
654
- """
655
- association_properties = {
656
- TRACE_TYPE: trace_type.value,
657
- }
658
- update_association_properties(association_properties)
659
-
660
680
  @classmethod
661
681
  def clear_session(cls):
662
682
  """Clear the session and user id from the context"""
@@ -732,6 +752,20 @@ class Laminar:
732
752
  "Content-Type": "application/json",
733
753
  }
734
754
 
755
+ @classmethod
756
+ def _set_trace_type(
757
+ cls,
758
+ trace_type: TraceType,
759
+ ):
760
+ """Set the trace_type for the current span and the context
761
+ Args:
762
+ trace_type (TraceType): Type of the trace
763
+ """
764
+ association_properties = {
765
+ TRACE_TYPE: trace_type.value,
766
+ }
767
+ update_association_properties(association_properties)
768
+
735
769
  @classmethod
736
770
  async def __run(
737
771
  cls,
lmnr/sdk/types.py CHANGED
@@ -203,3 +203,9 @@ class TraceType(Enum):
203
203
  class GetDatapointsResponse(pydantic.BaseModel):
204
204
  items: list[Datapoint]
205
205
  totalCount: int
206
+
207
+
208
+ class TracingLevel(Enum):
209
+ OFF = 0
210
+ META_ONLY = 1
211
+ ALL = 2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lmnr
3
- Version: 0.4.44
3
+ Version: 0.4.46
4
4
  Summary: Python SDK for Laminar AI
5
5
  License: Apache-2.0
6
6
  Author: lmnr.ai
@@ -38,11 +38,9 @@ Provides-Extra: transformers
38
38
  Provides-Extra: vertexai
39
39
  Provides-Extra: watsonx
40
40
  Provides-Extra: weaviate
41
- Requires-Dist: aiohttp (>=3.0,<4.0)
42
- Requires-Dist: argparse (>=1.0,<2.0)
43
- Requires-Dist: backoff (>=2.0,<3.0)
44
- Requires-Dist: deprecated (>=1.0,<2.0)
45
- Requires-Dist: jinja2 (>=3.0,<4.0)
41
+ Requires-Dist: aiohttp (>=3.0)
42
+ Requires-Dist: argparse (>=1.0)
43
+ Requires-Dist: deprecated (>=1.0)
46
44
  Requires-Dist: opentelemetry-api (>=1.28.0)
47
45
  Requires-Dist: opentelemetry-exporter-otlp-proto-grpc (>=1.28.0)
48
46
  Requires-Dist: opentelemetry-exporter-otlp-proto-http (>=1.28.0)
@@ -77,11 +75,11 @@ Requires-Dist: opentelemetry-instrumentation-watsonx (>=0.33.12) ; extra == "all
77
75
  Requires-Dist: opentelemetry-instrumentation-weaviate (>=0.33.12) ; extra == "all" or extra == "weaviate"
78
76
  Requires-Dist: opentelemetry-sdk (>=1.28.0)
79
77
  Requires-Dist: opentelemetry-semantic-conventions-ai (==0.4.2)
80
- Requires-Dist: pydantic (>=2.7,<3.0)
81
- Requires-Dist: python-dotenv (>=1.0,<2.0)
82
- Requires-Dist: requests (>=2.0,<3.0)
78
+ Requires-Dist: pydantic (>=2.7)
79
+ Requires-Dist: python-dotenv (>=1.0)
80
+ Requires-Dist: requests (>=2.0)
83
81
  Requires-Dist: tenacity (>=8.0)
84
- Requires-Dist: tqdm (>=4.0,<5.0)
82
+ Requires-Dist: tqdm (>=4.0)
85
83
  Description-Content-Type: text/markdown
86
84
 
87
85
  # Laminar Python
@@ -1,17 +1,17 @@
1
- lmnr/__init__.py,sha256=5cTmg6sY8SYTH24VS-qEdcBwxMpbGkxks8kAqZKgXEU,434
1
+ lmnr/__init__.py,sha256=Bqxs-8Mh4h69pOHURgBCgo9EW1GwChebxP6wUX2-bsU,452
2
2
  lmnr/cli.py,sha256=W5zn5DBJiFaVARFy2D-8tJI8ZlGNzjJqk3qiXAG2woo,1456
3
3
  lmnr/openllmetry_sdk/.flake8,sha256=bCxuDlGx3YQ55QHKPiGJkncHanh9qGjQJUujcFa3lAU,150
4
4
  lmnr/openllmetry_sdk/.python-version,sha256=9OLQBQVbD4zE4cJsPePhnAfV_snrPSoqEQw-PXgPMOs,6
5
5
  lmnr/openllmetry_sdk/__init__.py,sha256=vVSGTAwUnJvdulHtslkGAd8QCBuv78WUK3bgfBpH6Do,2390
6
6
  lmnr/openllmetry_sdk/config/__init__.py,sha256=DliMGp2NjYAqRFLKpWQPUKjGMHRO8QsVfazBA1qENQ8,248
7
7
  lmnr/openllmetry_sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- lmnr/openllmetry_sdk/decorators/base.py,sha256=xwLsUFd5husf3p-ZllVTYEe9gkwl9T3Bf1WpW1-Ua5I,6413
8
+ lmnr/openllmetry_sdk/decorators/base.py,sha256=f8kh7TG3Q99RGXLMrLNlq12s1FWRBftWjzFBpc813k4,6027
9
9
  lmnr/openllmetry_sdk/instruments.py,sha256=CGGUEELldrXkQwAzAkDeAtDq07_pjhz7i14a92P7C_E,1036
10
10
  lmnr/openllmetry_sdk/tracing/__init__.py,sha256=xT73L1t2si2CM6QmMiTZ7zn-dKKYBLNrpBBWq6WfVBw,68
11
- lmnr/openllmetry_sdk/tracing/attributes.py,sha256=h970zmb7yTszzf2oHBfOY3cDYhE6O7LhkiHLqa_7x1k,1261
11
+ lmnr/openllmetry_sdk/tracing/attributes.py,sha256=B_4KVYWAUu-6DQmsm2eCJQcTxm8pG1EByCBK3uOPkuI,1293
12
12
  lmnr/openllmetry_sdk/tracing/content_allow_list.py,sha256=3feztm6PBWNelc8pAZUcQyEGyeSpNiVKjOaDk65l2ps,846
13
13
  lmnr/openllmetry_sdk/tracing/context_manager.py,sha256=rdSus-p-TaevQ8hIAhfbnZr5dTqRvACDkzXGDpflncY,306
14
- lmnr/openllmetry_sdk/tracing/tracing.py,sha256=GJM2-VbknimiksqnpI-Zu0KRWFKa93tea0GyONEspkE,31993
14
+ lmnr/openllmetry_sdk/tracing/tracing.py,sha256=pa8ZPhH4NSwP1QnvD5qNaOZ775H5Q4KVa9OwSki9KUE,32138
15
15
  lmnr/openllmetry_sdk/utils/__init__.py,sha256=pNhf0G3vTd5ccoc03i1MXDbricSaiqCbi1DLWhSekK8,604
16
16
  lmnr/openllmetry_sdk/utils/in_memory_span_exporter.py,sha256=H_4TRaThMO1H6vUQ0OpQvzJk_fZH0OOsRAM1iZQXsR8,2112
17
17
  lmnr/openllmetry_sdk/utils/json_encoder.py,sha256=dK6b_axr70IYL7Vv-bu4wntvDDuyntoqsHaddqX7P58,463
@@ -22,12 +22,12 @@ lmnr/sdk/datasets.py,sha256=KNMp_v3z1ocIltIw7kTgj8o-l9R8N8Tgj0sw1ajQ9C8,1582
22
22
  lmnr/sdk/decorators.py,sha256=ja2EUWUWvFOp28ER0k78PRuxNahwCVyH0TdM3U-xY7U,1856
23
23
  lmnr/sdk/eval_control.py,sha256=G6Fg3Xx_KWv72iBaWlNMdyRTF2bZFQnwJ68sJNSpIcY,177
24
24
  lmnr/sdk/evaluations.py,sha256=gLImD_uB9uXgw07QiJ_OYRTFDGxiPtFCO1c8HyOq2s0,15935
25
- lmnr/sdk/laminar.py,sha256=wCQ-GyJkH58kbazfYfYzZj-oSh-TOZycRIyf2f01v6w,30024
25
+ lmnr/sdk/laminar.py,sha256=4Saelm9m6pB9GWquCdHWY-1VhAB8Q2tWlq6hnmorzHU,31250
26
26
  lmnr/sdk/log.py,sha256=cZBeUoSK39LMEV-X4-eEhTWOciULRfHaKfRK8YqIM8I,1532
27
- lmnr/sdk/types.py,sha256=hqaZ8sg97PIrZzmCyEc2uH_g4GKRPIIz4c_LuGlNyHM,6320
27
+ lmnr/sdk/types.py,sha256=FCNoFoa0ingOvpXGfbiETVsakYyq9Zpoc56MXJ1YDzQ,6390
28
28
  lmnr/sdk/utils.py,sha256=Uk8y15x-sd5tP2ERONahElLDJVEy_3dA_1_5g9A6auY,3358
29
- lmnr-0.4.44.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
30
- lmnr-0.4.44.dist-info/METADATA,sha256=gj3Eu8hQmEXB3azu404wIGU6VUFetHDIemd5f3S2EEE,12350
31
- lmnr-0.4.44.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
32
- lmnr-0.4.44.dist-info/entry_points.txt,sha256=K1jE20ww4jzHNZLnsfWBvU3YKDGBgbOiYG5Y7ivQcq4,37
33
- lmnr-0.4.44.dist-info/RECORD,,
29
+ lmnr-0.4.46.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
30
+ lmnr-0.4.46.dist-info/METADATA,sha256=cL1X2RUUQ9jI6m8iybxhBOE1LsoKVxXUYYHp_WmzqNA,12244
31
+ lmnr-0.4.46.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
32
+ lmnr-0.4.46.dist-info/entry_points.txt,sha256=K1jE20ww4jzHNZLnsfWBvU3YKDGBgbOiYG5Y7ivQcq4,37
33
+ lmnr-0.4.46.dist-info/RECORD,,
File without changes
File without changes