lmnr 0.4.35__py3-none-any.whl → 0.4.37__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.
Files changed (48) hide show
  1. lmnr/__init__.py +2 -2
  2. lmnr/{traceloop_sdk → openllmetry_sdk}/__init__.py +3 -3
  3. lmnr/{traceloop_sdk → openllmetry_sdk}/decorators/base.py +4 -4
  4. lmnr/openllmetry_sdk/tracing/__init__.py +1 -0
  5. lmnr/{traceloop_sdk → openllmetry_sdk}/tracing/context_manager.py +1 -1
  6. lmnr/{traceloop_sdk → openllmetry_sdk}/tracing/tracing.py +61 -47
  7. lmnr/sdk/decorators.py +3 -3
  8. lmnr/sdk/evaluations.py +2 -2
  9. lmnr/sdk/laminar.py +35 -9
  10. {lmnr-0.4.35.dist-info → lmnr-0.4.37.dist-info}/METADATA +2 -2
  11. lmnr-0.4.37.dist-info/RECORD +32 -0
  12. lmnr/traceloop_sdk/tests/__init__.py +0 -1
  13. lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_and_external_association_properties.yaml +0 -101
  14. lmnr/traceloop_sdk/tests/cassettes/test_association_properties/test_langchain_association_properties.yaml +0 -99
  15. lmnr/traceloop_sdk/tests/cassettes/test_manual/test_manual_report.yaml +0 -98
  16. lmnr/traceloop_sdk/tests/cassettes/test_manual/test_resource_attributes.yaml +0 -98
  17. lmnr/traceloop_sdk/tests/cassettes/test_privacy_no_prompts/test_simple_workflow.yaml +0 -199
  18. lmnr/traceloop_sdk/tests/cassettes/test_prompt_management/test_prompt_management.yaml +0 -202
  19. lmnr/traceloop_sdk/tests/cassettes/test_sdk_initialization/test_resource_attributes.yaml +0 -199
  20. lmnr/traceloop_sdk/tests/cassettes/test_tasks/test_task_io_serialization_with_langchain.yaml +0 -96
  21. lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_aworkflow.yaml +0 -98
  22. lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_simple_workflow.yaml +0 -199
  23. lmnr/traceloop_sdk/tests/cassettes/test_workflows/test_streaming_workflow.yaml +0 -167
  24. lmnr/traceloop_sdk/tests/conftest.py +0 -111
  25. lmnr/traceloop_sdk/tests/test_association_properties.py +0 -229
  26. lmnr/traceloop_sdk/tests/test_manual.py +0 -48
  27. lmnr/traceloop_sdk/tests/test_nested_tasks.py +0 -47
  28. lmnr/traceloop_sdk/tests/test_privacy_no_prompts.py +0 -50
  29. lmnr/traceloop_sdk/tests/test_sdk_initialization.py +0 -57
  30. lmnr/traceloop_sdk/tests/test_tasks.py +0 -32
  31. lmnr/traceloop_sdk/tests/test_workflows.py +0 -262
  32. lmnr/traceloop_sdk/tracing/__init__.py +0 -1
  33. lmnr-0.4.35.dist-info/RECORD +0 -52
  34. /lmnr/{traceloop_sdk → openllmetry_sdk}/.flake8 +0 -0
  35. /lmnr/{traceloop_sdk → openllmetry_sdk}/.python-version +0 -0
  36. /lmnr/{traceloop_sdk → openllmetry_sdk}/config/__init__.py +0 -0
  37. /lmnr/{traceloop_sdk → openllmetry_sdk}/decorators/__init__.py +0 -0
  38. /lmnr/{traceloop_sdk → openllmetry_sdk}/instruments.py +0 -0
  39. /lmnr/{traceloop_sdk → openllmetry_sdk}/tracing/attributes.py +0 -0
  40. /lmnr/{traceloop_sdk → openllmetry_sdk}/tracing/content_allow_list.py +0 -0
  41. /lmnr/{traceloop_sdk → openllmetry_sdk}/utils/__init__.py +0 -0
  42. /lmnr/{traceloop_sdk → openllmetry_sdk}/utils/in_memory_span_exporter.py +0 -0
  43. /lmnr/{traceloop_sdk → openllmetry_sdk}/utils/json_encoder.py +0 -0
  44. /lmnr/{traceloop_sdk → openllmetry_sdk}/utils/package_check.py +0 -0
  45. /lmnr/{traceloop_sdk → openllmetry_sdk}/version.py +0 -0
  46. {lmnr-0.4.35.dist-info → lmnr-0.4.37.dist-info}/LICENSE +0 -0
  47. {lmnr-0.4.35.dist-info → lmnr-0.4.37.dist-info}/WHEEL +0 -0
  48. {lmnr-0.4.35.dist-info → lmnr-0.4.37.dist-info}/entry_points.txt +0 -0
lmnr/__init__.py CHANGED
@@ -9,6 +9,6 @@ from .sdk.types import (
9
9
  PipelineRunResponse,
10
10
  )
11
11
  from .sdk.decorators import observe
12
- from .traceloop_sdk import Instruments
13
- from .traceloop_sdk.tracing.attributes import Attributes
12
+ from .openllmetry_sdk import Instruments
13
+ from .openllmetry_sdk.tracing.attributes import Attributes
14
14
  from opentelemetry.trace import use_span
@@ -9,12 +9,12 @@ from opentelemetry.sdk.resources import SERVICE_NAME
9
9
  from opentelemetry.propagators.textmap import TextMapPropagator
10
10
  from opentelemetry.util.re import parse_env_headers
11
11
 
12
- from lmnr.traceloop_sdk.instruments import Instruments
13
- from lmnr.traceloop_sdk.config import (
12
+ from lmnr.openllmetry_sdk.instruments import Instruments
13
+ from lmnr.openllmetry_sdk.config import (
14
14
  is_content_tracing_enabled,
15
15
  is_tracing_enabled,
16
16
  )
17
- from lmnr.traceloop_sdk.tracing.tracing import TracerWrapper
17
+ from lmnr.openllmetry_sdk.tracing.tracing import TracerWrapper
18
18
  from typing import Dict
19
19
 
20
20
 
@@ -10,10 +10,10 @@ from opentelemetry import trace
10
10
  from opentelemetry import context as context_api
11
11
 
12
12
  from lmnr.sdk.utils import get_input_from_func_args, is_method
13
- from lmnr.traceloop_sdk.tracing import get_tracer
14
- from lmnr.traceloop_sdk.tracing.attributes import SPAN_INPUT, SPAN_OUTPUT, SPAN_PATH
15
- from lmnr.traceloop_sdk.tracing.tracing import TracerWrapper, get_span_path
16
- from lmnr.traceloop_sdk.utils.json_encoder import JSONEncoder
13
+ from lmnr.openllmetry_sdk.tracing import get_tracer
14
+ from lmnr.openllmetry_sdk.tracing.attributes import SPAN_INPUT, SPAN_OUTPUT, SPAN_PATH
15
+ from lmnr.openllmetry_sdk.tracing.tracing import TracerWrapper, get_span_path
16
+ from lmnr.openllmetry_sdk.utils.json_encoder import JSONEncoder
17
17
 
18
18
 
19
19
  class CustomJSONEncoder(JSONEncoder):
@@ -0,0 +1 @@
1
+ from lmnr.openllmetry_sdk.tracing.context_manager import get_tracer
@@ -1,6 +1,6 @@
1
1
  from contextlib import contextmanager
2
2
 
3
- from lmnr.traceloop_sdk.tracing.tracing import TracerWrapper
3
+ from lmnr.openllmetry_sdk.tracing.tracing import TracerWrapper
4
4
 
5
5
 
6
6
  @contextmanager
@@ -4,15 +4,16 @@ import logging
4
4
 
5
5
 
6
6
  from contextvars import Context
7
- from lmnr.traceloop_sdk.instruments import Instruments
8
- from lmnr.traceloop_sdk.tracing.attributes import (
7
+ from lmnr.sdk.log import VerboseColorfulFormatter
8
+ from lmnr.openllmetry_sdk.instruments import Instruments
9
+ from lmnr.openllmetry_sdk.tracing.attributes import (
9
10
  ASSOCIATION_PROPERTIES,
10
11
  SPAN_INSTRUMENTATION_SOURCE,
11
12
  SPAN_PATH,
12
13
  )
13
- from lmnr.traceloop_sdk.tracing.content_allow_list import ContentAllowList
14
- from lmnr.traceloop_sdk.utils import is_notebook
15
- from lmnr.traceloop_sdk.utils.package_check import is_package_installed
14
+ from lmnr.openllmetry_sdk.tracing.content_allow_list import ContentAllowList
15
+ from lmnr.openllmetry_sdk.utils import is_notebook
16
+ from lmnr.openllmetry_sdk.utils.package_check import is_package_installed
16
17
  from opentelemetry import trace
17
18
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
18
19
  OTLPSpanExporter as HTTPExporter,
@@ -35,6 +36,11 @@ from opentelemetry.trace import get_tracer_provider, ProxyTracerProvider
35
36
 
36
37
  from typing import Dict, Optional, Set
37
38
 
39
+ module_logger = logging.getLogger(__name__)
40
+ console_log_handler = logging.StreamHandler()
41
+ console_log_handler.setFormatter(VerboseColorfulFormatter())
42
+ module_logger.addHandler(console_log_handler)
43
+
38
44
 
39
45
  TRACER_NAME = "lmnr.tracer"
40
46
  EXCLUDED_URLS = """
@@ -62,6 +68,7 @@ class TracerWrapper(object):
62
68
  endpoint: str = None
63
69
  headers: Dict[str, str] = {}
64
70
  __tracer_provider: TracerProvider = None
71
+ __logger: logging.Logger = None
65
72
 
66
73
  def __new__(
67
74
  cls,
@@ -72,6 +79,7 @@ class TracerWrapper(object):
72
79
  should_enrich_metrics: bool = False,
73
80
  instruments: Optional[Set[Instruments]] = None,
74
81
  ) -> "TracerWrapper":
82
+ cls._initialize_logger(cls)
75
83
  if not hasattr(cls, "instance"):
76
84
  obj = cls.instance = super(TracerWrapper, cls).__new__(cls)
77
85
  if not TracerWrapper.endpoint:
@@ -115,8 +123,8 @@ class TracerWrapper(object):
115
123
  )
116
124
 
117
125
  if not instrument_set:
118
- logging.warning(
119
- "Warning: No valid instruments set. Remove 'instrument' "
126
+ cls.__logger.warning(
127
+ "No valid instruments set. Remove 'instrument' "
120
128
  "argument to use all instruments, or set a valid instrument."
121
129
  )
122
130
 
@@ -130,6 +138,12 @@ class TracerWrapper(object):
130
138
  def exit_handler(self):
131
139
  self.flush()
132
140
 
141
+ def _initialize_logger(self):
142
+ self.__logger = logging.getLogger(__name__)
143
+ console_log_handler = logging.StreamHandler()
144
+ console_log_handler.setFormatter(VerboseColorfulFormatter())
145
+ self.__logger.addHandler(console_log_handler)
146
+
133
147
  def _span_processor_on_start(self, span, parent_context):
134
148
  span_path = get_value("span_path")
135
149
  if span_path is not None:
@@ -172,7 +186,7 @@ class TracerWrapper(object):
172
186
  if hasattr(cls, "instance"):
173
187
  return True
174
188
 
175
- logging.warning("Warning: Laminar not initialized, make sure to initialize")
189
+ cls.__logger.warning("Laminar not initialized, make sure to initialize")
176
190
  return False
177
191
 
178
192
  def flush(self):
@@ -253,7 +267,7 @@ def init_tracer_provider(resource: Resource) -> TracerProvider:
253
267
  provider = TracerProvider(resource=resource)
254
268
  trace.set_tracer_provider(provider)
255
269
  elif not hasattr(default_provider, "add_span_processor"):
256
- logging.error(
270
+ module_logger.error(
257
271
  "Cannot add span processor to the default provider since it doesn't support it"
258
272
  )
259
273
  return
@@ -280,7 +294,11 @@ def init_instrumentations(
280
294
  ]
281
295
  )
282
296
 
283
- instruments = instruments or (set(Instruments) - default_off_instruments)
297
+ instruments = (
298
+ instruments
299
+ if instruments is not None
300
+ else (set(Instruments) - default_off_instruments)
301
+ )
284
302
 
285
303
  # Remove any instruments that were explicitly blocked
286
304
  instruments = instruments - block_instruments
@@ -375,19 +393,15 @@ def init_instrumentations(
375
393
  if init_weaviate_instrumentor():
376
394
  instrument_set = True
377
395
  else:
378
- logging.warning(f"Warning: {instrument} instrumentation does not exist.")
379
- logging.warning(
396
+ module_logger.warning(
397
+ f"Warning: {instrument} instrumentation does not exist."
398
+ )
399
+ module_logger.warning(
380
400
  "Usage:\n"
381
401
  "from lmnr import Laminar, Instruments\n"
382
402
  "Laminar.init(instruments=set([Instruments.OPENAI]))"
383
403
  )
384
404
 
385
- if not instrument_set:
386
- logging.warning(
387
- "Warning: No valid instruments set. "
388
- + "Specify instruments or remove 'instruments' argument to use all instruments."
389
- )
390
-
391
405
  return instrument_set
392
406
 
393
407
 
@@ -405,7 +419,7 @@ def init_openai_instrumentor(should_enrich_metrics: bool):
405
419
  return True
406
420
 
407
421
  except Exception as e:
408
- logging.error(f"Error initializing OpenAI instrumentor: {e}")
422
+ module_logger.error(f"Error initializing OpenAI instrumentor: {e}")
409
423
  return False
410
424
 
411
425
 
@@ -422,7 +436,7 @@ def init_anthropic_instrumentor(should_enrich_metrics: bool):
422
436
  instrumentor.instrument()
423
437
  return True
424
438
  except Exception as e:
425
- logging.error(f"Error initializing Anthropic instrumentor: {e}")
439
+ module_logger.error(f"Error initializing Anthropic instrumentor: {e}")
426
440
  return False
427
441
 
428
442
 
@@ -436,7 +450,7 @@ def init_cohere_instrumentor():
436
450
  instrumentor.instrument()
437
451
  return True
438
452
  except Exception as e:
439
- logging.error(f"Error initializing Cohere instrumentor: {e}")
453
+ module_logger.error(f"Error initializing Cohere instrumentor: {e}")
440
454
  return False
441
455
 
442
456
 
@@ -450,7 +464,7 @@ def init_pinecone_instrumentor():
450
464
  instrumentor.instrument()
451
465
  return True
452
466
  except Exception as e:
453
- logging.error(f"Error initializing Pinecone instrumentor: {e}")
467
+ module_logger.error(f"Error initializing Pinecone instrumentor: {e}")
454
468
  return False
455
469
 
456
470
 
@@ -463,7 +477,7 @@ def init_qdrant_instrumentor():
463
477
  if not instrumentor.is_instrumented_by_opentelemetry:
464
478
  instrumentor.instrument()
465
479
  except Exception as e:
466
- logging.error(f"Error initializing Qdrant instrumentor: {e}")
480
+ module_logger.error(f"Error initializing Qdrant instrumentor: {e}")
467
481
  return False
468
482
 
469
483
 
@@ -477,7 +491,7 @@ def init_chroma_instrumentor():
477
491
  instrumentor.instrument()
478
492
  return True
479
493
  except Exception as e:
480
- logging.error(f"Error initializing Chroma instrumentor: {e}")
494
+ module_logger.error(f"Error initializing Chroma instrumentor: {e}")
481
495
  return False
482
496
 
483
497
 
@@ -493,7 +507,7 @@ def init_google_generativeai_instrumentor():
493
507
  instrumentor.instrument()
494
508
  return True
495
509
  except Exception as e:
496
- logging.error(f"Error initializing Gemini instrumentor: {e}")
510
+ module_logger.error(f"Error initializing Gemini instrumentor: {e}")
497
511
  return False
498
512
 
499
513
 
@@ -507,7 +521,7 @@ def init_haystack_instrumentor():
507
521
  instrumentor.instrument()
508
522
  return True
509
523
  except Exception as e:
510
- logging.error(f"Error initializing Haystack instrumentor: {e}")
524
+ module_logger.error(f"Error initializing Haystack instrumentor: {e}")
511
525
  return False
512
526
 
513
527
 
@@ -523,7 +537,7 @@ def init_langchain_instrumentor():
523
537
  except Exception as e:
524
538
  # FIXME: silencing this error temporarily, it appears to not be critical
525
539
  if str(e) != "No module named 'langchain_community'":
526
- logging.error(f"Error initializing LangChain instrumentor: {e}")
540
+ module_logger.error(f"Error initializing LangChain instrumentor: {e}")
527
541
  return False
528
542
 
529
543
 
@@ -537,7 +551,7 @@ def init_mistralai_instrumentor():
537
551
  instrumentor.instrument()
538
552
  return True
539
553
  except Exception as e:
540
- logging.error(f"Error initializing MistralAI instrumentor: {e}")
554
+ module_logger.error(f"Error initializing MistralAI instrumentor: {e}")
541
555
  return False
542
556
 
543
557
 
@@ -551,7 +565,7 @@ def init_ollama_instrumentor():
551
565
  instrumentor.instrument()
552
566
  return True
553
567
  except Exception as e:
554
- logging.error(f"Error initializing Ollama instrumentor: {e}")
568
+ module_logger.error(f"Error initializing Ollama instrumentor: {e}")
555
569
  return False
556
570
 
557
571
 
@@ -567,7 +581,7 @@ def init_transformers_instrumentor():
567
581
  instrumentor.instrument()
568
582
  return True
569
583
  except Exception as e:
570
- logging.error(f"Error initializing Transformers instrumentor: {e}")
584
+ module_logger.error(f"Error initializing Transformers instrumentor: {e}")
571
585
  return False
572
586
 
573
587
 
@@ -581,7 +595,7 @@ def init_together_instrumentor():
581
595
  instrumentor.instrument()
582
596
  return True
583
597
  except Exception as e:
584
- logging.error(f"Error initializing TogetherAI instrumentor: {e}")
598
+ module_logger.error(f"Error initializing TogetherAI instrumentor: {e}")
585
599
  return False
586
600
 
587
601
 
@@ -595,7 +609,7 @@ def init_llama_index_instrumentor():
595
609
  instrumentor.instrument()
596
610
  return True
597
611
  except Exception as e:
598
- logging.error(f"Error initializing LlamaIndex instrumentor: {e}")
612
+ module_logger.error(f"Error initializing LlamaIndex instrumentor: {e}")
599
613
  return False
600
614
 
601
615
 
@@ -609,7 +623,7 @@ def init_milvus_instrumentor():
609
623
  instrumentor.instrument()
610
624
  return True
611
625
  except Exception as e:
612
- logging.error(f"Error initializing Milvus instrumentor: {e}")
626
+ module_logger.error(f"Error initializing Milvus instrumentor: {e}")
613
627
  return False
614
628
 
615
629
 
@@ -623,7 +637,7 @@ def init_requests_instrumentor():
623
637
  instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
624
638
  return True
625
639
  except Exception as e:
626
- logging.error(f"Error initializing Requests instrumentor: {e}")
640
+ module_logger.error(f"Error initializing Requests instrumentor: {e}")
627
641
  return False
628
642
 
629
643
 
@@ -637,7 +651,7 @@ def init_urllib3_instrumentor():
637
651
  instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
638
652
  return True
639
653
  except Exception as e:
640
- logging.error(f"Error initializing urllib3 instrumentor: {e}")
654
+ module_logger.error(f"Error initializing urllib3 instrumentor: {e}")
641
655
  return False
642
656
 
643
657
 
@@ -651,7 +665,7 @@ def init_pymysql_instrumentor():
651
665
  instrumentor.instrument()
652
666
  return True
653
667
  except Exception as e:
654
- logging.error(f"Error initializing SQLAlchemy instrumentor: {e}")
668
+ module_logger.error(f"Error initializing SQLAlchemy instrumentor: {e}")
655
669
  return False
656
670
 
657
671
 
@@ -667,7 +681,7 @@ def init_bedrock_instrumentor(should_enrich_metrics: bool):
667
681
  instrumentor.instrument()
668
682
  return True
669
683
  except Exception as e:
670
- logging.error(f"Error initializing Bedrock instrumentor: {e}")
684
+ module_logger.error(f"Error initializing Bedrock instrumentor: {e}")
671
685
  return False
672
686
 
673
687
 
@@ -681,7 +695,7 @@ def init_replicate_instrumentor():
681
695
  instrumentor.instrument()
682
696
  return True
683
697
  except Exception as e:
684
- logging.error(f"Error initializing Replicate instrumentor: {e}")
698
+ module_logger.error(f"Error initializing Replicate instrumentor: {e}")
685
699
  return False
686
700
 
687
701
 
@@ -695,7 +709,7 @@ def init_vertexai_instrumentor():
695
709
  instrumentor.instrument()
696
710
  return True
697
711
  except Exception as e:
698
- logging.warning(f"Error initializing Vertex AI instrumentor: {e}")
712
+ module_logger.warning(f"Error initializing Vertex AI instrumentor: {e}")
699
713
  return False
700
714
 
701
715
 
@@ -711,7 +725,7 @@ def init_watsonx_instrumentor():
711
725
  instrumentor.instrument()
712
726
  return True
713
727
  except Exception as e:
714
- logging.warning(f"Error initializing Watsonx instrumentor: {e}")
728
+ module_logger.warning(f"Error initializing Watsonx instrumentor: {e}")
715
729
  return False
716
730
 
717
731
 
@@ -725,7 +739,7 @@ def init_weaviate_instrumentor():
725
739
  instrumentor.instrument()
726
740
  return True
727
741
  except Exception as e:
728
- logging.warning(f"Error initializing Weaviate instrumentor: {e}")
742
+ module_logger.warning(f"Error initializing Weaviate instrumentor: {e}")
729
743
  return False
730
744
 
731
745
 
@@ -739,7 +753,7 @@ def init_alephalpha_instrumentor():
739
753
  instrumentor.instrument()
740
754
  return True
741
755
  except Exception as e:
742
- logging.error(f"Error initializing Aleph Alpha instrumentor: {e}")
756
+ module_logger.error(f"Error initializing Aleph Alpha instrumentor: {e}")
743
757
  return False
744
758
 
745
759
 
@@ -753,7 +767,7 @@ def init_marqo_instrumentor():
753
767
  instrumentor.instrument()
754
768
  return True
755
769
  except Exception as e:
756
- logging.error(f"Error initializing marqo instrumentor: {e}")
770
+ module_logger.error(f"Error initializing marqo instrumentor: {e}")
757
771
  return False
758
772
 
759
773
 
@@ -767,7 +781,7 @@ def init_lancedb_instrumentor():
767
781
  instrumentor.instrument()
768
782
  return True
769
783
  except Exception as e:
770
- logging.error(f"Error initializing LanceDB instrumentor: {e}")
784
+ module_logger.error(f"Error initializing LanceDB instrumentor: {e}")
771
785
 
772
786
 
773
787
  def init_redis_instrumentor():
@@ -780,7 +794,7 @@ def init_redis_instrumentor():
780
794
  instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
781
795
  return True
782
796
  except Exception as e:
783
- logging.error(f"Error initializing redis instrumentor: {e}")
797
+ module_logger.error(f"Error initializing redis instrumentor: {e}")
784
798
  return False
785
799
 
786
800
 
@@ -794,7 +808,7 @@ def init_groq_instrumentor():
794
808
  instrumentor.instrument()
795
809
  return True
796
810
  except Exception as e:
797
- logging.error(f"Error initializing Groq instrumentor: {e}")
811
+ module_logger.error(f"Error initializing Groq instrumentor: {e}")
798
812
  return False
799
813
 
800
814
 
@@ -810,5 +824,5 @@ def init_sagemaker_instrumentor(should_enrich_metrics: bool):
810
824
  instrumentor.instrument()
811
825
  return True
812
826
  except Exception as e:
813
- logging.error(f"Error initializing SageMaker instrumentor: {e}")
827
+ module_logger.error(f"Error initializing SageMaker instrumentor: {e}")
814
828
  return False
lmnr/sdk/decorators.py CHANGED
@@ -1,4 +1,4 @@
1
- from lmnr.traceloop_sdk.decorators.base import (
1
+ from lmnr.openllmetry_sdk.decorators.base import (
2
2
  entity_method,
3
3
  aentity_method,
4
4
  )
@@ -7,8 +7,8 @@ from opentelemetry.trace import INVALID_SPAN, get_current_span
7
7
  from typing import Callable, Optional, TypeVar, cast
8
8
  from typing_extensions import ParamSpec
9
9
 
10
- from lmnr.traceloop_sdk.tracing.attributes import SESSION_ID, USER_ID
11
- from lmnr.traceloop_sdk.tracing.tracing import update_association_properties
10
+ from lmnr.openllmetry_sdk.tracing.attributes import SESSION_ID, USER_ID
11
+ from lmnr.openllmetry_sdk.tracing.tracing import update_association_properties
12
12
 
13
13
  from .utils import is_async
14
14
 
lmnr/sdk/evaluations.py CHANGED
@@ -7,8 +7,8 @@ from contextlib import contextmanager
7
7
  from tqdm import tqdm
8
8
  from typing import Any, Awaitable, Optional, Set, Union
9
9
 
10
- from ..traceloop_sdk.instruments import Instruments
11
- from ..traceloop_sdk.tracing.attributes import SPAN_TYPE
10
+ from ..openllmetry_sdk.instruments import Instruments
11
+ from ..openllmetry_sdk.tracing.attributes import SPAN_TYPE
12
12
 
13
13
  from .datasets import EvaluationDataset
14
14
  from .laminar import Laminar as L
lmnr/sdk/laminar.py CHANGED
@@ -1,15 +1,15 @@
1
1
  from contextlib import contextmanager
2
2
  from contextvars import Context
3
- from lmnr.traceloop_sdk import Traceloop
4
- from lmnr.traceloop_sdk.instruments import Instruments
5
- from lmnr.traceloop_sdk.tracing import get_tracer
6
- from lmnr.traceloop_sdk.tracing.attributes import (
3
+ from lmnr.openllmetry_sdk import Traceloop
4
+ from lmnr.openllmetry_sdk.instruments import Instruments
5
+ from lmnr.openllmetry_sdk.tracing import get_tracer
6
+ from lmnr.openllmetry_sdk.tracing.attributes import (
7
7
  ASSOCIATION_PROPERTIES,
8
8
  Attributes,
9
9
  SPAN_TYPE,
10
10
  OVERRIDE_PARENT_SPAN,
11
11
  )
12
- from lmnr.traceloop_sdk.decorators.base import json_dumps
12
+ from lmnr.openllmetry_sdk.decorators.base import json_dumps
13
13
  from opentelemetry import context, trace
14
14
  from opentelemetry.context import attach, detach, set_value
15
15
  from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
@@ -30,7 +30,7 @@ import requests
30
30
  import urllib.parse
31
31
  import uuid
32
32
 
33
- from lmnr.traceloop_sdk.tracing.attributes import (
33
+ from lmnr.openllmetry_sdk.tracing.attributes import (
34
34
  SESSION_ID,
35
35
  SPAN_INPUT,
36
36
  SPAN_OUTPUT,
@@ -38,7 +38,7 @@ from lmnr.traceloop_sdk.tracing.attributes import (
38
38
  TRACE_TYPE,
39
39
  USER_ID,
40
40
  )
41
- from lmnr.traceloop_sdk.tracing.tracing import (
41
+ from lmnr.openllmetry_sdk.tracing.tracing import (
42
42
  get_span_path,
43
43
  remove_association_properties,
44
44
  set_association_properties,
@@ -599,7 +599,9 @@ class Laminar:
599
599
  Useful to debug and group long-running\
600
600
  sessions/conversations.
601
601
  Defaults to None.
602
- user_id (Optional[str], optional): Custom user id.\
602
+ user_id (Optional[str], optional). Deprecated.\
603
+ Use `Laminar.set_metadata` instead.\
604
+ Custom user id.\
603
605
  Useful for grouping spans or traces by user.\
604
606
  Defaults to None.
605
607
  """
@@ -607,9 +609,33 @@ class Laminar:
607
609
  if session_id is not None:
608
610
  association_properties[SESSION_ID] = session_id
609
611
  if user_id is not None:
610
- association_properties[USER_ID] = user_id
612
+ cls.__logger.warning(
613
+ "User ID in set_session is deprecated and will be removed soon. "
614
+ "Please use `Laminar.set_metadata` instead."
615
+ )
616
+ association_properties["metadata." + USER_ID] = user_id
611
617
  update_association_properties(association_properties)
612
618
 
619
+ @classmethod
620
+ def set_metadata(cls, metadata: dict[str, Any]):
621
+ """Set the metadata for the current trace.
622
+
623
+ Args:
624
+ metadata (dict[str, Any]): Metadata to set for the trace. Willl be\
625
+ sent as attributes, so must be json serializable.
626
+ """
627
+ props = {f"metadata.{k}": json_dumps(v) for k, v in metadata.items()}
628
+ update_association_properties(props)
629
+
630
+ @classmethod
631
+ def clear_metadata(cls):
632
+ """Clear the metadata from the context"""
633
+ props: dict = copy.copy(context.get_value("association_properties"))
634
+ for k in props.keys():
635
+ if k.startswith("metadata."):
636
+ props.pop(k)
637
+ set_association_properties(props)
638
+
613
639
  @classmethod
614
640
  def _set_trace_type(
615
641
  cls,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lmnr
3
- Version: 0.4.35
3
+ Version: 0.4.37
4
4
  Summary: Python SDK for Laminar AI
5
5
  License: Apache-2.0
6
6
  Author: lmnr.ai
@@ -156,7 +156,7 @@ def handle_user_request(topic: str):
156
156
  Laminar allows you to automatically instrument majority of the most popular LLM, Vector DB, database, requests, and other libraries.
157
157
 
158
158
  If you want to automatically instrument a default set of libraries, then simply do NOT pass `instruments` argument to `.initialize()`.
159
- See the full list of available instrumentations in the [enum](/src/lmnr/traceloop_sdk/instruments.py).
159
+ See the full list of available instrumentations in the [enum](https://github.com/lmnr-ai/lmnr-python/blob/main/src/lmnr/openllmetry_sdk/instruments.py).
160
160
 
161
161
  If you want to automatically instrument only specific LLM, Vector DB, or other
162
162
  calls with OpenTelemetry-compatible instrumentation, then pass the appropriate instruments to `.initialize()`.
@@ -0,0 +1,32 @@
1
+ lmnr/__init__.py,sha256=5cTmg6sY8SYTH24VS-qEdcBwxMpbGkxks8kAqZKgXEU,434
2
+ lmnr/cli.py,sha256=Ptvm5dsNLKUY5lwnN8XkT5GtCYjzpRNi2WvefknB3OQ,1079
3
+ lmnr/openllmetry_sdk/.flake8,sha256=bCxuDlGx3YQ55QHKPiGJkncHanh9qGjQJUujcFa3lAU,150
4
+ lmnr/openllmetry_sdk/.python-version,sha256=9OLQBQVbD4zE4cJsPePhnAfV_snrPSoqEQw-PXgPMOs,6
5
+ lmnr/openllmetry_sdk/__init__.py,sha256=vVSGTAwUnJvdulHtslkGAd8QCBuv78WUK3bgfBpH6Do,2390
6
+ lmnr/openllmetry_sdk/config/__init__.py,sha256=DliMGp2NjYAqRFLKpWQPUKjGMHRO8QsVfazBA1qENQ8,248
7
+ lmnr/openllmetry_sdk/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ lmnr/openllmetry_sdk/decorators/base.py,sha256=UpOFkiEWEXbfDhJ-wZNzD4GJ9IyIsb13w-mgyUJYPeU,5567
9
+ lmnr/openllmetry_sdk/instruments.py,sha256=CGGUEELldrXkQwAzAkDeAtDq07_pjhz7i14a92P7C_E,1036
10
+ lmnr/openllmetry_sdk/tracing/__init__.py,sha256=xT73L1t2si2CM6QmMiTZ7zn-dKKYBLNrpBBWq6WfVBw,68
11
+ lmnr/openllmetry_sdk/tracing/attributes.py,sha256=h970zmb7yTszzf2oHBfOY3cDYhE6O7LhkiHLqa_7x1k,1261
12
+ lmnr/openllmetry_sdk/tracing/content_allow_list.py,sha256=3feztm6PBWNelc8pAZUcQyEGyeSpNiVKjOaDk65l2ps,846
13
+ lmnr/openllmetry_sdk/tracing/context_manager.py,sha256=rdSus-p-TaevQ8hIAhfbnZr5dTqRvACDkzXGDpflncY,306
14
+ lmnr/openllmetry_sdk/tracing/tracing.py,sha256=j16opjtsUZ_xjh0kKAi3JswX7HUxou6EnFV63atpFnM,29808
15
+ lmnr/openllmetry_sdk/utils/__init__.py,sha256=pNhf0G3vTd5ccoc03i1MXDbricSaiqCbi1DLWhSekK8,604
16
+ lmnr/openllmetry_sdk/utils/in_memory_span_exporter.py,sha256=H_4TRaThMO1H6vUQ0OpQvzJk_fZH0OOsRAM1iZQXsR8,2112
17
+ lmnr/openllmetry_sdk/utils/json_encoder.py,sha256=dK6b_axr70IYL7Vv-bu4wntvDDuyntoqsHaddqX7P58,463
18
+ lmnr/openllmetry_sdk/utils/package_check.py,sha256=Ki74WZME-ASF0fx7RXSIMsULGYUzI86sOINi1EGrc_Y,235
19
+ lmnr/openllmetry_sdk/version.py,sha256=OlatFEFA4ttqSSIiV8jdE-sq3KG5zu2hnC4B4mzWF3s,23
20
+ lmnr/sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ lmnr/sdk/datasets.py,sha256=w8U9E6fvetAo65Cb2CbYzlfhY8CfXAR-VysrakG6-4I,1591
22
+ lmnr/sdk/decorators.py,sha256=kH7wNmxahNYu8DieodQrf3DyNtzEoxt0XB7LErGkn8k,2256
23
+ lmnr/sdk/evaluations.py,sha256=rz92RKam5bWTj-w-c2ZTdsK6Bl7KSxW5UarBjG472Mc,16268
24
+ lmnr/sdk/laminar.py,sha256=k5vxPdS4IN48M-k-JqGK2VPuAD6kvzhOLjEZcOuW8b8,27443
25
+ lmnr/sdk/log.py,sha256=cZBeUoSK39LMEV-X4-eEhTWOciULRfHaKfRK8YqIM8I,1532
26
+ lmnr/sdk/types.py,sha256=qGD1tkGszd-_sZJaZ_Zx9U_CdUYzoDkUeN2g-o48Gls,5588
27
+ lmnr/sdk/utils.py,sha256=Uk8y15x-sd5tP2ERONahElLDJVEy_3dA_1_5g9A6auY,3358
28
+ lmnr-0.4.37.dist-info/LICENSE,sha256=67b_wJHVV1CBaWkrKFWU1wyqTPSdzH77Ls-59631COg,10411
29
+ lmnr-0.4.37.dist-info/METADATA,sha256=pvk3QWPbv584qCSV8M30cozvymsaBz-4wG5CXDG9PvU,10372
30
+ lmnr-0.4.37.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
31
+ lmnr-0.4.37.dist-info/entry_points.txt,sha256=K1jE20ww4jzHNZLnsfWBvU3YKDGBgbOiYG5Y7ivQcq4,37
32
+ lmnr-0.4.37.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- # """unit tests."""