lmnr 0.6.3__py3-none-any.whl → 0.6.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.
Files changed (35) hide show
  1. lmnr/cli.py +1 -2
  2. lmnr/opentelemetry_lib/__init__.py +6 -7
  3. lmnr/opentelemetry_lib/decorators/__init__.py +9 -9
  4. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/__init__.py +2 -2
  5. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/config.py +4 -4
  6. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/utils.py +19 -19
  7. lmnr/opentelemetry_lib/tracing/__init__.py +6 -7
  8. lmnr/opentelemetry_lib/tracing/_instrument_initializers.py +34 -35
  9. lmnr/opentelemetry_lib/tracing/context_properties.py +2 -3
  10. lmnr/opentelemetry_lib/tracing/exporter.py +4 -5
  11. lmnr/opentelemetry_lib/tracing/instruments.py +5 -6
  12. lmnr/opentelemetry_lib/tracing/processor.py +6 -7
  13. lmnr/sdk/browser/utils.py +4 -3
  14. lmnr/sdk/client/asynchronous/async_client.py +26 -11
  15. lmnr/sdk/client/asynchronous/resources/__init__.py +2 -0
  16. lmnr/sdk/client/asynchronous/resources/agent.py +89 -91
  17. lmnr/sdk/client/asynchronous/resources/evals.py +7 -8
  18. lmnr/sdk/client/asynchronous/resources/tags.py +89 -0
  19. lmnr/sdk/client/synchronous/resources/__init__.py +2 -1
  20. lmnr/sdk/client/synchronous/resources/agent.py +91 -91
  21. lmnr/sdk/client/synchronous/resources/evals.py +7 -8
  22. lmnr/sdk/client/synchronous/resources/tags.py +89 -0
  23. lmnr/sdk/client/synchronous/sync_client.py +28 -13
  24. lmnr/sdk/decorators.py +27 -29
  25. lmnr/sdk/evaluations.py +49 -46
  26. lmnr/sdk/laminar.py +67 -59
  27. lmnr/sdk/types.py +45 -39
  28. lmnr/sdk/utils.py +3 -3
  29. lmnr/version.py +1 -1
  30. {lmnr-0.6.3.dist-info → lmnr-0.6.5.dist-info}/METADATA +1 -1
  31. lmnr-0.6.5.dist-info/RECORD +56 -0
  32. lmnr-0.6.3.dist-info/RECORD +0 -54
  33. {lmnr-0.6.3.dist-info → lmnr-0.6.5.dist-info}/LICENSE +0 -0
  34. {lmnr-0.6.3.dist-info → lmnr-0.6.5.dist-info}/WHEEL +0 -0
  35. {lmnr-0.6.3.dist-info → lmnr-0.6.5.dist-info}/entry_points.txt +0 -0
lmnr/cli.py CHANGED
@@ -4,7 +4,6 @@ import importlib.util
4
4
  import os
5
5
  import re
6
6
  import sys
7
- from typing import Optional
8
7
 
9
8
  from lmnr.sdk.evaluations import Evaluation
10
9
 
@@ -55,7 +54,7 @@ async def run_evaluation(args):
55
54
  sys.modules[name] = mod
56
55
 
57
56
  spec.loader.exec_module(mod)
58
- evaluations: Optional[list[Evaluation]] = EVALUATION_INSTANCES.get()
57
+ evaluations: list[Evaluation] | None = EVALUATION_INSTANCES.get()
59
58
  if evaluations is None:
60
59
  LOG.warning("Evaluation instance not found")
61
60
  if args.fail_on_error:
@@ -1,7 +1,6 @@
1
1
  import logging
2
2
  import sys
3
3
 
4
- from typing import Optional, Set
5
4
  from opentelemetry.sdk.trace.export import SpanExporter
6
5
  from opentelemetry.sdk.resources import SERVICE_NAME
7
6
 
@@ -16,17 +15,17 @@ class TracerManager:
16
15
 
17
16
  @staticmethod
18
17
  def init(
19
- app_name: Optional[str] = sys.argv[0],
18
+ app_name: str | None = sys.argv[0],
20
19
  disable_batch=False,
21
- exporter: Optional[SpanExporter] = None,
20
+ exporter: SpanExporter | None = None,
22
21
  resource_attributes: dict = {},
23
- instruments: Optional[Set[Instruments]] = None,
24
- block_instruments: Optional[Set[Instruments]] = None,
22
+ instruments: set[Instruments] | None = None,
23
+ block_instruments: set[Instruments] | None = None,
25
24
  base_url: str = "https://api.lmnr.ai",
26
25
  port: int = 8443,
27
26
  http_port: int = 443,
28
- project_api_key: Optional[str] = None,
29
- max_export_batch_size: Optional[int] = None,
27
+ project_api_key: str | None = None,
28
+ max_export_batch_size: int | None = None,
30
29
  force_http: bool = False,
31
30
  timeout_seconds: int = 30,
32
31
  set_global_tracer_provider: bool = True,
@@ -3,7 +3,7 @@ import json
3
3
  import logging
4
4
  import pydantic
5
5
  import types
6
- from typing import Any, Literal, Optional, Union
6
+ from typing import Any, Literal
7
7
 
8
8
  from opentelemetry import trace
9
9
  from opentelemetry import context as context_api
@@ -41,12 +41,12 @@ def json_dumps(data: dict) -> str:
41
41
 
42
42
 
43
43
  def entity_method(
44
- name: Optional[str] = None,
44
+ name: str | None = None,
45
45
  ignore_input: bool = False,
46
- ignore_inputs: Optional[list[str]] = None,
46
+ ignore_inputs: list[str] | None = None,
47
47
  ignore_output: bool = False,
48
- span_type: Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]] = "DEFAULT",
49
- association_properties: Optional[dict[str, Any]] = None,
48
+ span_type: Literal["DEFAULT", "LLM", "TOOL"] = "DEFAULT",
49
+ association_properties: dict[str, Any] | None = None,
50
50
  ):
51
51
  def decorate(fn):
52
52
  @wraps(fn)
@@ -130,12 +130,12 @@ def entity_method(
130
130
 
131
131
  # Async Decorators
132
132
  def aentity_method(
133
- name: Optional[str] = None,
133
+ name: str | None = None,
134
134
  ignore_input: bool = False,
135
- ignore_inputs: Optional[list[str]] = None,
135
+ ignore_inputs: list[str] | None = None,
136
136
  ignore_output: bool = False,
137
- span_type: Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]] = "DEFAULT",
138
- association_properties: Optional[dict[str, Any]] = None,
137
+ span_type: Literal["DEFAULT", "LLM", "TOOL"] = "DEFAULT",
138
+ association_properties: dict[str, Any] | None = None,
139
139
  ):
140
140
  def decorate(fn):
141
141
  @wraps(fn)
@@ -3,7 +3,7 @@
3
3
  from collections import defaultdict
4
4
  import logging
5
5
  import os
6
- from typing import AsyncGenerator, Callable, Collection, Generator, Optional
6
+ from typing import AsyncGenerator, Callable, Collection, Generator
7
7
 
8
8
  from google.genai import types
9
9
 
@@ -152,7 +152,7 @@ def _set_request_attributes(span, args, kwargs):
152
152
 
153
153
  if should_send_prompts():
154
154
  i = 0
155
- system_instruction: Optional[types.ContentUnion] = config_dict.get(
155
+ system_instruction: types.ContentUnion | None = config_dict.get(
156
156
  "system_instruction"
157
157
  )
158
158
  if system_instruction:
@@ -1,9 +1,9 @@
1
- from typing import Callable, Coroutine, Optional
1
+ from typing import Callable, Coroutine
2
2
 
3
3
 
4
4
  class Config:
5
5
  exception_logger = None
6
- upload_base64_image: Optional[
7
- Callable[[str, str, str, str], Coroutine[None, None, str]]
8
- ] = None
6
+ upload_base64_image: (
7
+ Callable[[str, str, str, str], Coroutine[None, None, str]] | None
8
+ ) = None
9
9
  convert_image_to_openai_format: bool = True
@@ -9,7 +9,7 @@ from google.genai import types
9
9
  from google.genai._common import BaseModel
10
10
  import pydantic
11
11
  from opentelemetry.trace import Span
12
- from typing import Any, Optional, Union
12
+ from typing import Any
13
13
 
14
14
 
15
15
  def set_span_attribute(span: Span, name: str, value: str):
@@ -44,7 +44,7 @@ def dont_throw(func):
44
44
  return wrapper
45
45
 
46
46
 
47
- def to_dict(obj: Union[BaseModel, pydantic.BaseModel, dict]) -> dict[str, Any]:
47
+ def to_dict(obj: BaseModel | pydantic.BaseModel | dict) -> dict[str, Any]:
48
48
  try:
49
49
  if isinstance(obj, BaseModel):
50
50
  return obj.model_dump()
@@ -59,11 +59,11 @@ def to_dict(obj: Union[BaseModel, pydantic.BaseModel, dict]) -> dict[str, Any]:
59
59
 
60
60
 
61
61
  def process_content_union(
62
- content: Union[types.ContentUnion, types.ContentUnionDict],
63
- trace_id: Optional[str] = None,
64
- span_id: Optional[str] = None,
62
+ content: types.ContentUnion | types.ContentUnionDict,
63
+ trace_id: str | None = None,
64
+ span_id: str | None = None,
65
65
  message_index: int = 0,
66
- ) -> Optional[str]:
66
+ ) -> str | None:
67
67
  parts = _process_content_union(content, trace_id, span_id, message_index)
68
68
  if parts is None:
69
69
  return None
@@ -83,11 +83,11 @@ def process_content_union(
83
83
 
84
84
 
85
85
  def _process_content_union(
86
- content: Union[types.ContentUnion, types.ContentUnionDict],
87
- trace_id: Optional[str] = None,
88
- span_id: Optional[str] = None,
86
+ content: types.ContentUnion | types.ContentUnionDict,
87
+ trace_id: str | None = None,
88
+ span_id: str | None = None,
89
89
  message_index: int = 0,
90
- ) -> Union[str, list[str], None]:
90
+ ) -> str | list[str] | None:
91
91
  if isinstance(content, types.Content):
92
92
  parts = to_dict(content).get("parts", [])
93
93
  return [_process_part(part) for part in parts]
@@ -111,12 +111,12 @@ def _process_content_union(
111
111
 
112
112
 
113
113
  def _process_part_union(
114
- content: Union[types.PartDict, types.File, types.Part, str],
115
- trace_id: Optional[str] = None,
116
- span_id: Optional[str] = None,
114
+ content: types.PartDict | types.File | types.Part | str,
115
+ trace_id: str | None = None,
116
+ span_id: str | None = None,
117
117
  message_index: int = 0,
118
118
  content_index: int = 0,
119
- ) -> Optional[str]:
119
+ ) -> str | None:
120
120
  if isinstance(content, str):
121
121
  return content
122
122
  elif isinstance(content, types.File):
@@ -135,11 +135,11 @@ def _process_part_union(
135
135
 
136
136
  def _process_part(
137
137
  content: types.Part,
138
- trace_id: Optional[str] = None,
139
- span_id: Optional[str] = None,
138
+ trace_id: str | None = None,
139
+ span_id: str | None = None,
140
140
  message_index: int = 0,
141
141
  content_index: int = 0,
142
- ) -> Optional[str]:
142
+ ) -> str | None:
143
143
  part_dict = to_dict(content)
144
144
  if part_dict.get("text") is not None:
145
145
  return part_dict.get("text")
@@ -157,8 +157,8 @@ def _process_part(
157
157
 
158
158
 
159
159
  def role_from_content_union(
160
- content: Union[types.ContentUnion, types.ContentUnionDict],
161
- ) -> Optional[str]:
160
+ content: types.ContentUnion | types.ContentUnionDict,
161
+ ) -> str | None:
162
162
  if isinstance(content, types.Content):
163
163
  return to_dict(content).get("role")
164
164
  elif isinstance(content, list) and len(content) > 0:
@@ -15,7 +15,6 @@ from opentelemetry.instrumentation.threading import ThreadingInstrumentor
15
15
  from opentelemetry.sdk.resources import Resource
16
16
  from opentelemetry.sdk.trace import TracerProvider, SpanProcessor
17
17
  from opentelemetry.sdk.trace.export import SpanExporter
18
- from typing import Optional, Set
19
18
 
20
19
  module_logger = logging.getLogger(__name__)
21
20
  console_log_handler = logging.StreamHandler()
@@ -31,7 +30,7 @@ MAX_EVENTS_OR_ATTRIBUTES_PER_SPAN = 5000
31
30
  class TracerWrapper(object):
32
31
  resource_attributes: dict = {}
33
32
  enable_content_tracing: bool = True
34
- __tracer_provider: Optional[TracerProvider] = None
33
+ __tracer_provider: TracerProvider | None = None
35
34
  __logger: logging.Logger
36
35
  __client: LaminarClient
37
36
  __async_client: AsyncLaminarClient
@@ -41,14 +40,14 @@ class TracerWrapper(object):
41
40
  def __new__(
42
41
  cls,
43
42
  disable_batch=False,
44
- exporter: Optional[SpanExporter] = None,
45
- instruments: Optional[Set[Instruments]] = None,
46
- block_instruments: Optional[Set[Instruments]] = None,
43
+ exporter: SpanExporter | None = None,
44
+ instruments: set[Instruments] | None = None,
45
+ block_instruments: set[Instruments] | None = None,
47
46
  base_url: str = "https://api.lmnr.ai",
48
47
  port: int = 8443,
49
48
  http_port: int = 443,
50
- project_api_key: Optional[str] = None,
51
- max_export_batch_size: Optional[int] = None,
49
+ project_api_key: str | None = None,
50
+ max_export_batch_size: int | None = None,
52
51
  force_http: bool = False,
53
52
  timeout_seconds: int = 10,
54
53
  set_global_tracer_provider: bool = True,
@@ -1,6 +1,5 @@
1
1
  import abc
2
2
 
3
- from typing import Optional
4
3
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5
4
 
6
5
  from lmnr.opentelemetry_lib.utils.package_check import is_package_installed
@@ -8,12 +7,12 @@ from lmnr.opentelemetry_lib.utils.package_check import is_package_installed
8
7
 
9
8
  class InstrumentorInitializer(abc.ABC):
10
9
  @abc.abstractmethod
11
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
10
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
12
11
  pass
13
12
 
14
13
 
15
14
  class AlephAlphaInstrumentorInitializer(InstrumentorInitializer):
16
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
15
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
17
16
  if not is_package_installed("aleph_alpha_client"):
18
17
  return None
19
18
  if not is_package_installed("opentelemetry-instrumentation-alephalpha"):
@@ -25,7 +24,7 @@ class AlephAlphaInstrumentorInitializer(InstrumentorInitializer):
25
24
 
26
25
 
27
26
  class AnthropicInstrumentorInitializer(InstrumentorInitializer):
28
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
27
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
29
28
  if not is_package_installed("anthropic"):
30
29
  return None
31
30
  if not is_package_installed("opentelemetry-instrumentation-anthropic"):
@@ -39,7 +38,7 @@ class AnthropicInstrumentorInitializer(InstrumentorInitializer):
39
38
 
40
39
 
41
40
  class BedrockInstrumentorInitializer(InstrumentorInitializer):
42
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
41
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
43
42
  if not is_package_installed("boto3"):
44
43
  return None
45
44
  if not is_package_installed("opentelemetry-instrumentation-bedrock"):
@@ -51,7 +50,7 @@ class BedrockInstrumentorInitializer(InstrumentorInitializer):
51
50
 
52
51
 
53
52
  class BrowserUseInstrumentorInitializer(InstrumentorInitializer):
54
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
53
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
55
54
  if not is_package_installed("browser-use"):
56
55
  return None
57
56
 
@@ -61,7 +60,7 @@ class BrowserUseInstrumentorInitializer(InstrumentorInitializer):
61
60
 
62
61
 
63
62
  class ChromaInstrumentorInitializer(InstrumentorInitializer):
64
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
63
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
65
64
  if not is_package_installed("chromadb"):
66
65
  return None
67
66
  if not is_package_installed("opentelemetry-instrumentation-chromadb"):
@@ -73,7 +72,7 @@ class ChromaInstrumentorInitializer(InstrumentorInitializer):
73
72
 
74
73
 
75
74
  class CohereInstrumentorInitializer(InstrumentorInitializer):
76
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
75
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
77
76
  if not is_package_installed("cohere"):
78
77
  return None
79
78
  if not is_package_installed("opentelemetry-instrumentation-cohere"):
@@ -85,7 +84,7 @@ class CohereInstrumentorInitializer(InstrumentorInitializer):
85
84
 
86
85
 
87
86
  class CrewAIInstrumentorInitializer(InstrumentorInitializer):
88
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
87
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
89
88
  if not is_package_installed("crewai"):
90
89
  return None
91
90
  if not is_package_installed("opentelemetry-instrumentation-crewai"):
@@ -97,7 +96,7 @@ class CrewAIInstrumentorInitializer(InstrumentorInitializer):
97
96
 
98
97
 
99
98
  class GoogleGenerativeAIInstrumentorInitializer(InstrumentorInitializer):
100
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
99
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
101
100
  if not is_package_installed("google-generativeai"):
102
101
  return None
103
102
  if not is_package_installed(
@@ -113,7 +112,7 @@ class GoogleGenerativeAIInstrumentorInitializer(InstrumentorInitializer):
113
112
 
114
113
 
115
114
  class GoogleGenAIInstrumentorInitializer(InstrumentorInitializer):
116
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
115
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
117
116
  if not is_package_installed("google-genai"):
118
117
  return None
119
118
 
@@ -125,7 +124,7 @@ class GoogleGenAIInstrumentorInitializer(InstrumentorInitializer):
125
124
 
126
125
 
127
126
  class GroqInstrumentorInitializer(InstrumentorInitializer):
128
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
127
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
129
128
  if not is_package_installed("groq"):
130
129
  return None
131
130
  if not is_package_installed("opentelemetry-instrumentation-groq"):
@@ -137,7 +136,7 @@ class GroqInstrumentorInitializer(InstrumentorInitializer):
137
136
 
138
137
 
139
138
  class HaystackInstrumentorInitializer(InstrumentorInitializer):
140
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
139
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
141
140
  if not is_package_installed("haystack"):
142
141
  return None
143
142
  if not is_package_installed("opentelemetry-instrumentation-haystack"):
@@ -149,7 +148,7 @@ class HaystackInstrumentorInitializer(InstrumentorInitializer):
149
148
 
150
149
 
151
150
  class LanceDBInstrumentorInitializer(InstrumentorInitializer):
152
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
151
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
153
152
  if not is_package_installed("lancedb"):
154
153
  return None
155
154
  if not is_package_installed("opentelemetry-instrumentation-lancedb"):
@@ -161,7 +160,7 @@ class LanceDBInstrumentorInitializer(InstrumentorInitializer):
161
160
 
162
161
 
163
162
  class LangchainInstrumentorInitializer(InstrumentorInitializer):
164
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
163
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
165
164
  if not is_package_installed("langchain"):
166
165
  return None
167
166
  if not is_package_installed("opentelemetry-instrumentation-langchain"):
@@ -173,7 +172,7 @@ class LangchainInstrumentorInitializer(InstrumentorInitializer):
173
172
 
174
173
 
175
174
  class LlamaIndexInstrumentorInitializer(InstrumentorInitializer):
176
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
175
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
177
176
  if not (
178
177
  is_package_installed("llama-index") or is_package_installed("llama_index")
179
178
  ):
@@ -187,7 +186,7 @@ class LlamaIndexInstrumentorInitializer(InstrumentorInitializer):
187
186
 
188
187
 
189
188
  class MarqoInstrumentorInitializer(InstrumentorInitializer):
190
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
189
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
191
190
  if not is_package_installed("marqo"):
192
191
  return None
193
192
  if not is_package_installed("opentelemetry-instrumentation-marqo"):
@@ -199,19 +198,19 @@ class MarqoInstrumentorInitializer(InstrumentorInitializer):
199
198
 
200
199
 
201
200
  class MCPInstrumentorInitializer(InstrumentorInitializer):
202
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
201
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
203
202
  if not is_package_installed("mcp"):
204
203
  return None
205
204
  if not is_package_installed("opentelemetry-instrumentation-mcp"):
206
205
  return None
207
206
 
208
- from opentelemetry.instrumentation.mcp import MCPInstrumentor
207
+ from opentelemetry.instrumentation.mcp import McpInstrumentor
209
208
 
210
- return MCPInstrumentor()
209
+ return McpInstrumentor()
211
210
 
212
211
 
213
212
  class MilvusInstrumentorInitializer(InstrumentorInitializer):
214
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
213
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
215
214
  if not is_package_installed("pymilvus"):
216
215
  return None
217
216
  if not is_package_installed("opentelemetry-instrumentation-milvus"):
@@ -223,7 +222,7 @@ class MilvusInstrumentorInitializer(InstrumentorInitializer):
223
222
 
224
223
 
225
224
  class MistralInstrumentorInitializer(InstrumentorInitializer):
226
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
225
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
227
226
  if not is_package_installed("mistralai"):
228
227
  return None
229
228
  if not is_package_installed("opentelemetry-instrumentation-mistralai"):
@@ -235,7 +234,7 @@ class MistralInstrumentorInitializer(InstrumentorInitializer):
235
234
 
236
235
 
237
236
  class OllamaInstrumentorInitializer(InstrumentorInitializer):
238
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
237
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
239
238
  if not is_package_installed("ollama"):
240
239
  return None
241
240
  if not is_package_installed("opentelemetry-instrumentation-ollama"):
@@ -247,7 +246,7 @@ class OllamaInstrumentorInitializer(InstrumentorInitializer):
247
246
 
248
247
 
249
248
  class OpenAIInstrumentorInitializer(InstrumentorInitializer):
250
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
249
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
251
250
  if not is_package_installed("openai"):
252
251
  return None
253
252
  if not is_package_installed("opentelemetry-instrumentation-openai"):
@@ -266,7 +265,7 @@ class OpenAIInstrumentorInitializer(InstrumentorInitializer):
266
265
  class PatchrightInstrumentorInitializer(InstrumentorInitializer):
267
266
  def init_instrumentor(
268
267
  self, client, async_client, *args, **kwargs
269
- ) -> Optional[BaseInstrumentor]:
268
+ ) -> BaseInstrumentor | None:
270
269
  if not is_package_installed("patchright"):
271
270
  return None
272
271
 
@@ -276,7 +275,7 @@ class PatchrightInstrumentorInitializer(InstrumentorInitializer):
276
275
 
277
276
 
278
277
  class PineconeInstrumentorInitializer(InstrumentorInitializer):
279
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
278
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
280
279
  if not is_package_installed("pinecone"):
281
280
  return None
282
281
  if not is_package_installed("opentelemetry-instrumentation-pinecone"):
@@ -290,7 +289,7 @@ class PineconeInstrumentorInitializer(InstrumentorInitializer):
290
289
  class PlaywrightInstrumentorInitializer(InstrumentorInitializer):
291
290
  def init_instrumentor(
292
291
  self, client, async_client, *args, **kwargs
293
- ) -> Optional[BaseInstrumentor]:
292
+ ) -> BaseInstrumentor | None:
294
293
  if not is_package_installed("playwright"):
295
294
  return None
296
295
 
@@ -300,7 +299,7 @@ class PlaywrightInstrumentorInitializer(InstrumentorInitializer):
300
299
 
301
300
 
302
301
  class QdrantInstrumentorInitializer(InstrumentorInitializer):
303
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
302
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
304
303
  if not is_package_installed("qdrant_client"):
305
304
  return None
306
305
  if not is_package_installed("opentelemetry-instrumentation-qdrant"):
@@ -312,7 +311,7 @@ class QdrantInstrumentorInitializer(InstrumentorInitializer):
312
311
 
313
312
 
314
313
  class ReplicateInstrumentorInitializer(InstrumentorInitializer):
315
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
314
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
316
315
  if not is_package_installed("replicate"):
317
316
  return None
318
317
  if not is_package_installed("opentelemetry-instrumentation-replicate"):
@@ -324,7 +323,7 @@ class ReplicateInstrumentorInitializer(InstrumentorInitializer):
324
323
 
325
324
 
326
325
  class SageMakerInstrumentorInitializer(InstrumentorInitializer):
327
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
326
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
328
327
  if not is_package_installed("boto3"):
329
328
  return None
330
329
  if not is_package_installed("opentelemetry-instrumentation-sagemaker"):
@@ -336,7 +335,7 @@ class SageMakerInstrumentorInitializer(InstrumentorInitializer):
336
335
 
337
336
 
338
337
  class TogetherInstrumentorInitializer(InstrumentorInitializer):
339
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
338
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
340
339
  if not is_package_installed("together"):
341
340
  return None
342
341
  if not is_package_installed("opentelemetry-instrumentation-together"):
@@ -348,7 +347,7 @@ class TogetherInstrumentorInitializer(InstrumentorInitializer):
348
347
 
349
348
 
350
349
  class TransformersInstrumentorInitializer(InstrumentorInitializer):
351
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
350
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
352
351
  if not is_package_installed("transformers"):
353
352
  return None
354
353
  if not is_package_installed("opentelemetry-instrumentation-transformers"):
@@ -360,7 +359,7 @@ class TransformersInstrumentorInitializer(InstrumentorInitializer):
360
359
 
361
360
 
362
361
  class VertexAIInstrumentorInitializer(InstrumentorInitializer):
363
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
362
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
364
363
  if not is_package_installed("vertexai"):
365
364
  return None
366
365
  if not is_package_installed("opentelemetry-instrumentation-vertexai"):
@@ -372,7 +371,7 @@ class VertexAIInstrumentorInitializer(InstrumentorInitializer):
372
371
 
373
372
 
374
373
  class WatsonxInstrumentorInitializer(InstrumentorInitializer):
375
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
374
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
376
375
  if not (
377
376
  is_package_installed("ibm-watsonx-ai")
378
377
  or is_package_installed("ibm-watson-machine-learning")
@@ -387,7 +386,7 @@ class WatsonxInstrumentorInitializer(InstrumentorInitializer):
387
386
 
388
387
 
389
388
  class WeaviateInstrumentorInitializer(InstrumentorInitializer):
390
- def init_instrumentor(self, *args, **kwargs) -> Optional[BaseInstrumentor]:
389
+ def init_instrumentor(self, *args, **kwargs) -> BaseInstrumentor | None:
391
390
  if not is_package_installed("weaviate"):
392
391
  return None
393
392
  if not is_package_installed("opentelemetry-instrumentation-weaviate"):
@@ -1,5 +1,4 @@
1
1
  import copy
2
- from typing import Optional
3
2
 
4
3
  from lmnr.opentelemetry_lib.tracing.attributes import (
5
4
  ASSOCIATION_PROPERTIES,
@@ -18,14 +17,14 @@ def set_association_properties(properties: dict) -> None:
18
17
  _set_association_properties_attributes(span, properties)
19
18
 
20
19
 
21
- def get_association_properties(context: Optional[Context] = None) -> dict:
20
+ def get_association_properties(context: Context | None = None) -> dict:
22
21
  return get_value("association_properties", context) or {}
23
22
 
24
23
 
25
24
  def update_association_properties(
26
25
  properties: dict,
27
26
  set_on_current_span: bool = True,
28
- context: Optional[Context] = None,
27
+ context: Context | None = None,
29
28
  ) -> None:
30
29
  """Only adds or updates properties that are not already present"""
31
30
  association_properties = get_value("association_properties", context) or {}
@@ -9,19 +9,18 @@ from opentelemetry.exporter.otlp.proto.http import Compression
9
9
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
10
10
  OTLPSpanExporter as HTTPOTLPSpanExporter,
11
11
  )
12
- from typing import Optional, Union
13
12
 
14
13
  from lmnr.sdk.utils import from_env
15
14
 
16
15
 
17
16
  class LaminarSpanExporter(SpanExporter):
18
- instance: Union[OTLPSpanExporter, HTTPOTLPSpanExporter]
17
+ instance: OTLPSpanExporter | HTTPOTLPSpanExporter
19
18
 
20
19
  def __init__(
21
20
  self,
22
- base_url: Optional[str] = None,
23
- port: Optional[int] = None,
24
- api_key: Optional[str] = None,
21
+ base_url: str | None = None,
22
+ port: int | None = None,
23
+ api_key: str | None = None,
25
24
  timeout_seconds: int = 30,
26
25
  force_http: bool = False,
27
26
  ):
@@ -1,7 +1,6 @@
1
1
  import logging
2
2
 
3
3
  from enum import Enum
4
- from typing import Optional, Set, Dict
5
4
 
6
5
  from opentelemetry.trace import TracerProvider
7
6
  import lmnr.opentelemetry_lib.tracing._instrument_initializers as initializers
@@ -47,7 +46,7 @@ class Instruments(Enum):
47
46
  WEAVIATE = "weaviate"
48
47
 
49
48
 
50
- INSTRUMENTATION_INITIALIZERS: Dict[
49
+ INSTRUMENTATION_INITIALIZERS: dict[
51
50
  Instruments, initializers.InstrumentorInitializer
52
51
  ] = {
53
52
  Instruments.ALEPHALPHA: initializers.AlephAlphaInstrumentorInitializer(),
@@ -86,10 +85,10 @@ INSTRUMENTATION_INITIALIZERS: Dict[
86
85
 
87
86
  def init_instrumentations(
88
87
  tracer_provider: TracerProvider,
89
- instruments: Optional[Set[Instruments]] = None,
90
- block_instruments: Optional[Set[Instruments]] = None,
91
- client: Optional[LaminarClient] = None,
92
- async_client: Optional[AsyncLaminarClient] = None,
88
+ instruments: set[Instruments] | None = None,
89
+ block_instruments: set[Instruments] | None = None,
90
+ client: LaminarClient | None = None,
91
+ async_client: AsyncLaminarClient | None = None,
93
92
  ):
94
93
  block_instruments = block_instruments or set()
95
94
  if instruments is None:
@@ -1,6 +1,5 @@
1
1
  import uuid
2
2
 
3
- from typing import Optional, Union
4
3
  from opentelemetry.sdk.trace.export import (
5
4
  SpanProcessor,
6
5
  SpanExporter,
@@ -25,20 +24,20 @@ from lmnr.version import PYTHON_VERSION, __version__
25
24
 
26
25
 
27
26
  class LaminarSpanProcessor(SpanProcessor):
28
- instance: Union[BatchSpanProcessor, SimpleSpanProcessor]
27
+ instance: BatchSpanProcessor | SimpleSpanProcessor
29
28
  __span_id_to_path: dict[int, list[str]] = {}
30
29
  __span_id_lists: dict[int, list[str]] = {}
31
30
 
32
31
  def __init__(
33
32
  self,
34
- base_url: Optional[str] = None,
35
- port: Optional[int] = None,
36
- api_key: Optional[str] = None,
33
+ base_url: str | None = None,
34
+ port: int | None = None,
35
+ api_key: str | None = None,
37
36
  timeout_seconds: int = 30,
38
37
  force_http: bool = False,
39
38
  max_export_batch_size: int = 512,
40
39
  disable_batch: bool = False,
41
- exporter: Optional[SpanExporter] = None,
40
+ exporter: SpanExporter | None = None,
42
41
  ):
43
42
  self.exporter = exporter or LaminarSpanExporter(
44
43
  base_url=base_url,
@@ -55,7 +54,7 @@ class LaminarSpanProcessor(SpanProcessor):
55
54
  )
56
55
  )
57
56
 
58
- def on_start(self, span: Span, parent_context: Optional[Context] = None):
57
+ def on_start(self, span: Span, parent_context: Context | None = None):
59
58
  span_path_in_context = get_value("span_path", parent_context or get_current())
60
59
  parent_span_path = span_path_in_context or (
61
60
  self.__span_id_to_path.get(span.parent.span_id) if span.parent else None