lmnr 0.5.0__py3-none-any.whl → 0.5.1a0__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,5 +1,6 @@
1
1
  import sys
2
2
 
3
+ from contextlib import contextmanager
3
4
  from typing import Optional, Set
4
5
  from opentelemetry.sdk.trace import SpanProcessor
5
6
  from opentelemetry.sdk.trace.export import SpanExporter
@@ -18,6 +19,7 @@ from typing import Dict
18
19
 
19
20
  class TracerManager:
20
21
  __tracer_wrapper: TracerWrapper
22
+ __initialized: bool = False
21
23
 
22
24
  @staticmethod
23
25
  def init(
@@ -51,9 +53,6 @@ class TracerManager:
51
53
 
52
54
  # Tracer init
53
55
  resource_attributes.update({SERVICE_NAME: app_name})
54
- TracerWrapper.set_static_params(
55
- resource_attributes, enable_content_tracing, api_endpoint, headers
56
- )
57
56
  TracerManager.__tracer_wrapper = TracerWrapper(
58
57
  disable_batch=disable_batch,
59
58
  processor=processor,
@@ -64,9 +63,41 @@ class TracerManager:
64
63
  base_http_url=base_http_url,
65
64
  project_api_key=project_api_key,
66
65
  max_export_batch_size=max_export_batch_size,
66
+ resource_attributes=resource_attributes,
67
+ enable_content_tracing=enable_content_tracing,
68
+ endpoint=api_endpoint,
69
+ headers=headers,
67
70
  )
71
+ TracerManager.__initialized = True
72
+
73
+ @staticmethod
74
+ def flush() -> bool:
75
+ return TracerManager.__tracer_wrapper.flush()
76
+
77
+ @staticmethod
78
+ def shutdown() -> bool:
79
+ try:
80
+ res = TracerManager.__tracer_wrapper.shutdown()
81
+ TracerManager.__tracer_wrapper = None
82
+ TracerManager.__initialized = False
83
+ return res
84
+ except Exception:
85
+ return False
68
86
 
69
87
  @staticmethod
70
- def flush():
71
- if getattr(TracerManager, "__tracer_wrapper", None):
72
- TracerManager.__tracer_wrapper.flush()
88
+ def is_initialized() -> bool:
89
+ return TracerManager.__initialized
90
+
91
+ @staticmethod
92
+ def get_tracer_wrapper() -> TracerWrapper:
93
+ return TracerManager.__tracer_wrapper
94
+
95
+
96
+ @contextmanager
97
+ def get_tracer(flush_on_exit: bool = False):
98
+ wrapper = TracerManager.get_tracer_wrapper()
99
+ try:
100
+ yield wrapper.get_tracer()
101
+ finally:
102
+ if flush_on_exit:
103
+ wrapper.flush()
@@ -11,9 +11,9 @@ from opentelemetry import context as context_api
11
11
  from opentelemetry.trace import Span
12
12
 
13
13
  from lmnr.sdk.utils import get_input_from_func_args, is_method
14
- from lmnr.openllmetry_sdk.tracing import get_tracer
14
+ from lmnr.openllmetry_sdk import get_tracer
15
15
  from lmnr.openllmetry_sdk.tracing.attributes import SPAN_INPUT, SPAN_OUTPUT, SPAN_TYPE
16
- from lmnr.openllmetry_sdk.tracing.tracing import TracerWrapper
16
+ from lmnr.openllmetry_sdk import TracerManager
17
17
  from lmnr.openllmetry_sdk.utils.json_encoder import JSONEncoder
18
18
  from lmnr.openllmetry_sdk.config import MAX_MANUAL_SPAN_PAYLOAD_SIZE
19
19
 
@@ -46,7 +46,7 @@ def entity_method(
46
46
  def decorate(fn):
47
47
  @wraps(fn)
48
48
  def wrap(*args, **kwargs):
49
- if not TracerWrapper.verify_initialized():
49
+ if not TracerManager.is_initialized():
50
50
  return fn(*args, **kwargs)
51
51
 
52
52
  span_name = name or fn.__name__
@@ -114,7 +114,7 @@ def aentity_method(
114
114
  def decorate(fn):
115
115
  @wraps(fn)
116
116
  async def wrap(*args, **kwargs):
117
- if not TracerWrapper.verify_initialized():
117
+ if not TracerManager.is_initialized():
118
118
  return await fn(*args, **kwargs)
119
119
 
120
120
  span_name = name or fn.__name__
@@ -1 +0,0 @@
1
- from lmnr.openllmetry_sdk.tracing.context_manager import get_tracer