lmnr 0.4.53.dev0__py3-none-any.whl → 0.7.26__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 (133) hide show
  1. lmnr/__init__.py +32 -11
  2. lmnr/cli/__init__.py +270 -0
  3. lmnr/cli/datasets.py +371 -0
  4. lmnr/cli/evals.py +111 -0
  5. lmnr/cli/rules.py +42 -0
  6. lmnr/opentelemetry_lib/__init__.py +70 -0
  7. lmnr/opentelemetry_lib/decorators/__init__.py +337 -0
  8. lmnr/opentelemetry_lib/litellm/__init__.py +685 -0
  9. lmnr/opentelemetry_lib/litellm/utils.py +100 -0
  10. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/__init__.py +849 -0
  11. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/config.py +13 -0
  12. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/event_emitter.py +211 -0
  13. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/event_models.py +41 -0
  14. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/span_utils.py +401 -0
  15. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/streaming.py +425 -0
  16. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/utils.py +332 -0
  17. lmnr/opentelemetry_lib/opentelemetry/instrumentation/anthropic/version.py +1 -0
  18. lmnr/opentelemetry_lib/opentelemetry/instrumentation/claude_agent/__init__.py +451 -0
  19. lmnr/opentelemetry_lib/opentelemetry/instrumentation/claude_agent/proxy.py +144 -0
  20. lmnr/opentelemetry_lib/opentelemetry/instrumentation/cua_agent/__init__.py +100 -0
  21. lmnr/opentelemetry_lib/opentelemetry/instrumentation/cua_computer/__init__.py +476 -0
  22. lmnr/opentelemetry_lib/opentelemetry/instrumentation/cua_computer/utils.py +12 -0
  23. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/__init__.py +599 -0
  24. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/config.py +9 -0
  25. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/schema_utils.py +26 -0
  26. lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/utils.py +330 -0
  27. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/__init__.py +488 -0
  28. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/config.py +8 -0
  29. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/event_emitter.py +143 -0
  30. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/event_models.py +41 -0
  31. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/span_utils.py +229 -0
  32. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/utils.py +92 -0
  33. lmnr/opentelemetry_lib/opentelemetry/instrumentation/groq/version.py +1 -0
  34. lmnr/opentelemetry_lib/opentelemetry/instrumentation/kernel/__init__.py +381 -0
  35. lmnr/opentelemetry_lib/opentelemetry/instrumentation/kernel/utils.py +36 -0
  36. lmnr/opentelemetry_lib/opentelemetry/instrumentation/langgraph/__init__.py +121 -0
  37. lmnr/opentelemetry_lib/opentelemetry/instrumentation/langgraph/utils.py +60 -0
  38. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/__init__.py +61 -0
  39. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/__init__.py +472 -0
  40. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/chat_wrappers.py +1185 -0
  41. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/completion_wrappers.py +305 -0
  42. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/config.py +16 -0
  43. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py +312 -0
  44. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/event_emitter.py +100 -0
  45. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/event_models.py +41 -0
  46. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py +68 -0
  47. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/utils.py +197 -0
  48. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/v0/__init__.py +176 -0
  49. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/v1/__init__.py +368 -0
  50. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/v1/assistant_wrappers.py +325 -0
  51. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py +135 -0
  52. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/v1/responses_wrappers.py +786 -0
  53. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openai/version.py +1 -0
  54. lmnr/opentelemetry_lib/opentelemetry/instrumentation/openhands_ai/__init__.py +388 -0
  55. lmnr/opentelemetry_lib/opentelemetry/instrumentation/opentelemetry/__init__.py +69 -0
  56. lmnr/opentelemetry_lib/opentelemetry/instrumentation/skyvern/__init__.py +191 -0
  57. lmnr/opentelemetry_lib/opentelemetry/instrumentation/threading/__init__.py +197 -0
  58. lmnr/opentelemetry_lib/tracing/__init__.py +263 -0
  59. lmnr/opentelemetry_lib/tracing/_instrument_initializers.py +516 -0
  60. lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/attributes.py +21 -8
  61. lmnr/opentelemetry_lib/tracing/context.py +200 -0
  62. lmnr/opentelemetry_lib/tracing/exporter.py +153 -0
  63. lmnr/opentelemetry_lib/tracing/instruments.py +140 -0
  64. lmnr/opentelemetry_lib/tracing/processor.py +193 -0
  65. lmnr/opentelemetry_lib/tracing/span.py +398 -0
  66. lmnr/opentelemetry_lib/tracing/tracer.py +57 -0
  67. lmnr/opentelemetry_lib/tracing/utils.py +62 -0
  68. lmnr/opentelemetry_lib/utils/package_check.py +18 -0
  69. lmnr/opentelemetry_lib/utils/wrappers.py +11 -0
  70. lmnr/sdk/browser/__init__.py +0 -0
  71. lmnr/sdk/browser/background_send_events.py +158 -0
  72. lmnr/sdk/browser/browser_use_cdp_otel.py +100 -0
  73. lmnr/sdk/browser/browser_use_otel.py +142 -0
  74. lmnr/sdk/browser/bubus_otel.py +71 -0
  75. lmnr/sdk/browser/cdp_utils.py +518 -0
  76. lmnr/sdk/browser/inject_script.js +514 -0
  77. lmnr/sdk/browser/patchright_otel.py +151 -0
  78. lmnr/sdk/browser/playwright_otel.py +322 -0
  79. lmnr/sdk/browser/pw_utils.py +363 -0
  80. lmnr/sdk/browser/recorder/record.umd.min.cjs +84 -0
  81. lmnr/sdk/browser/utils.py +70 -0
  82. lmnr/sdk/client/asynchronous/async_client.py +180 -0
  83. lmnr/sdk/client/asynchronous/resources/__init__.py +6 -0
  84. lmnr/sdk/client/asynchronous/resources/base.py +32 -0
  85. lmnr/sdk/client/asynchronous/resources/browser_events.py +41 -0
  86. lmnr/sdk/client/asynchronous/resources/datasets.py +131 -0
  87. lmnr/sdk/client/asynchronous/resources/evals.py +266 -0
  88. lmnr/sdk/client/asynchronous/resources/evaluators.py +85 -0
  89. lmnr/sdk/client/asynchronous/resources/tags.py +83 -0
  90. lmnr/sdk/client/synchronous/resources/__init__.py +6 -0
  91. lmnr/sdk/client/synchronous/resources/base.py +32 -0
  92. lmnr/sdk/client/synchronous/resources/browser_events.py +40 -0
  93. lmnr/sdk/client/synchronous/resources/datasets.py +131 -0
  94. lmnr/sdk/client/synchronous/resources/evals.py +263 -0
  95. lmnr/sdk/client/synchronous/resources/evaluators.py +85 -0
  96. lmnr/sdk/client/synchronous/resources/tags.py +83 -0
  97. lmnr/sdk/client/synchronous/sync_client.py +191 -0
  98. lmnr/sdk/datasets/__init__.py +94 -0
  99. lmnr/sdk/datasets/file_utils.py +91 -0
  100. lmnr/sdk/decorators.py +163 -26
  101. lmnr/sdk/eval_control.py +3 -2
  102. lmnr/sdk/evaluations.py +403 -191
  103. lmnr/sdk/laminar.py +1080 -549
  104. lmnr/sdk/log.py +7 -2
  105. lmnr/sdk/types.py +246 -134
  106. lmnr/sdk/utils.py +151 -7
  107. lmnr/version.py +46 -0
  108. {lmnr-0.4.53.dev0.dist-info → lmnr-0.7.26.dist-info}/METADATA +152 -106
  109. lmnr-0.7.26.dist-info/RECORD +116 -0
  110. lmnr-0.7.26.dist-info/WHEEL +4 -0
  111. lmnr-0.7.26.dist-info/entry_points.txt +3 -0
  112. lmnr/cli.py +0 -101
  113. lmnr/openllmetry_sdk/.python-version +0 -1
  114. lmnr/openllmetry_sdk/__init__.py +0 -72
  115. lmnr/openllmetry_sdk/config/__init__.py +0 -9
  116. lmnr/openllmetry_sdk/decorators/base.py +0 -185
  117. lmnr/openllmetry_sdk/instruments.py +0 -38
  118. lmnr/openllmetry_sdk/tracing/__init__.py +0 -1
  119. lmnr/openllmetry_sdk/tracing/content_allow_list.py +0 -24
  120. lmnr/openllmetry_sdk/tracing/context_manager.py +0 -13
  121. lmnr/openllmetry_sdk/tracing/tracing.py +0 -884
  122. lmnr/openllmetry_sdk/utils/in_memory_span_exporter.py +0 -61
  123. lmnr/openllmetry_sdk/utils/package_check.py +0 -7
  124. lmnr/openllmetry_sdk/version.py +0 -1
  125. lmnr/sdk/datasets.py +0 -55
  126. lmnr-0.4.53.dev0.dist-info/LICENSE +0 -75
  127. lmnr-0.4.53.dev0.dist-info/RECORD +0 -33
  128. lmnr-0.4.53.dev0.dist-info/WHEEL +0 -4
  129. lmnr-0.4.53.dev0.dist-info/entry_points.txt +0 -3
  130. /lmnr/{openllmetry_sdk → opentelemetry_lib}/.flake8 +0 -0
  131. /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/__init__.py +0 -0
  132. /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/json_encoder.py +0 -0
  133. /lmnr/{openllmetry_sdk/decorators/__init__.py → py.typed} +0 -0
@@ -1,884 +0,0 @@
1
- import atexit
2
- import copy
3
- import logging
4
-
5
-
6
- from contextvars import Context
7
- from lmnr.sdk.log import VerboseColorfulFormatter
8
- from lmnr.openllmetry_sdk.instruments import Instruments
9
- from lmnr.openllmetry_sdk.tracing.attributes import (
10
- ASSOCIATION_PROPERTIES,
11
- SPAN_INSTRUMENTATION_SOURCE,
12
- SPAN_PATH,
13
- TRACING_LEVEL,
14
- )
15
- from lmnr.openllmetry_sdk.tracing.content_allow_list import ContentAllowList
16
- from lmnr.openllmetry_sdk.utils import is_notebook
17
- from lmnr.openllmetry_sdk.utils.package_check import is_package_installed
18
- from opentelemetry import trace
19
- from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
20
- OTLPSpanExporter as HTTPExporter,
21
- )
22
- from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
23
- OTLPSpanExporter as GRPCExporter,
24
- )
25
- from opentelemetry.instrumentation.threading import ThreadingInstrumentor
26
- from opentelemetry.context import get_value, attach, get_current, set_value, Context
27
- from opentelemetry.propagate import set_global_textmap
28
- from opentelemetry.propagators.textmap import TextMapPropagator
29
- from opentelemetry.sdk.resources import Resource
30
- from opentelemetry.sdk.trace import TracerProvider, SpanProcessor, Span
31
- from opentelemetry.sdk.trace.export import (
32
- SpanExporter,
33
- SimpleSpanProcessor,
34
- BatchSpanProcessor,
35
- )
36
- from opentelemetry.trace import get_tracer_provider, ProxyTracerProvider
37
-
38
- from typing import Dict, Optional, Set
39
-
40
- module_logger = logging.getLogger(__name__)
41
- console_log_handler = logging.StreamHandler()
42
- console_log_handler.setFormatter(VerboseColorfulFormatter())
43
- module_logger.addHandler(console_log_handler)
44
-
45
-
46
- TRACER_NAME = "lmnr.tracer"
47
- EXCLUDED_URLS = """
48
- iam.cloud.ibm.com,
49
- dataplatform.cloud.ibm.com,
50
- ml.cloud.ibm.com,
51
- api.openai.com,
52
- openai.azure.com,
53
- api.anthropic.com,
54
- api.cohere.ai,
55
- pinecone.io,
56
- api.lmnr.ai,
57
- posthog.com,
58
- sentry.io,
59
- bedrock-runtime,
60
- sagemaker-runtime,
61
- googleapis.com,
62
- githubusercontent.com,
63
- openaipublic.blob.core.windows.net"""
64
-
65
-
66
- class TracerWrapper(object):
67
- resource_attributes: dict = {}
68
- enable_content_tracing: bool = True
69
- endpoint: str = None
70
- headers: Dict[str, str] = {}
71
- __tracer_provider: TracerProvider = None
72
- __logger: logging.Logger = None
73
- __span_id_to_path: dict[int, str] = {}
74
-
75
- def __new__(
76
- cls,
77
- disable_batch=False,
78
- processor: Optional[SpanProcessor] = None,
79
- propagator: Optional[TextMapPropagator] = None,
80
- exporter: Optional[SpanExporter] = None,
81
- should_enrich_metrics: bool = False,
82
- instruments: Optional[Set[Instruments]] = None,
83
- ) -> "TracerWrapper":
84
- cls._initialize_logger(cls)
85
- if not hasattr(cls, "instance"):
86
- obj = cls.instance = super(TracerWrapper, cls).__new__(cls)
87
- if not TracerWrapper.endpoint:
88
- return obj
89
-
90
- obj.__resource = Resource(attributes=TracerWrapper.resource_attributes)
91
- obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
92
- if processor:
93
- obj.__spans_processor: SpanProcessor = processor
94
- obj.__spans_processor_original_on_start = processor.on_start
95
- else:
96
- obj.__spans_exporter: SpanExporter = (
97
- exporter
98
- if exporter
99
- else init_spans_exporter(
100
- TracerWrapper.endpoint, TracerWrapper.headers
101
- )
102
- )
103
- if disable_batch or is_notebook():
104
- obj.__spans_processor: SpanProcessor = SimpleSpanProcessor(
105
- obj.__spans_exporter
106
- )
107
- else:
108
- obj.__spans_processor: SpanProcessor = BatchSpanProcessor(
109
- obj.__spans_exporter
110
- )
111
- obj.__spans_processor_original_on_start = None
112
-
113
- obj.__spans_processor.on_start = obj._span_processor_on_start
114
- obj.__tracer_provider.add_span_processor(obj.__spans_processor)
115
-
116
- if propagator:
117
- set_global_textmap(propagator)
118
-
119
- # this makes sure otel context is propagated so we always want it
120
- ThreadingInstrumentor().instrument()
121
-
122
- instrument_set = init_instrumentations(
123
- should_enrich_metrics,
124
- instruments,
125
- )
126
-
127
- if not instrument_set:
128
- cls.__logger.warning(
129
- "No valid instruments set. Remove 'instrument' "
130
- "argument to use all instruments, or set a valid instrument."
131
- )
132
-
133
- obj.__content_allow_list = ContentAllowList()
134
-
135
- # Force flushes for debug environments (e.g. local development)
136
- atexit.register(obj.exit_handler)
137
-
138
- return cls.instance
139
-
140
- def exit_handler(self):
141
- self.__span_id_to_path = {}
142
- self.flush()
143
-
144
- def _initialize_logger(self):
145
- self.__logger = logging.getLogger(__name__)
146
- console_log_handler = logging.StreamHandler()
147
- console_log_handler.setFormatter(VerboseColorfulFormatter())
148
- self.__logger.addHandler(console_log_handler)
149
-
150
- def _span_processor_on_start(
151
- self, span: Span, parent_context: Optional[Context] = None
152
- ):
153
- span_path_in_context = get_value("span_path", parent_context or get_current())
154
- span_path_in_context = None
155
- parent_span_path = span_path_in_context or (
156
- self.__span_id_to_path.get(span.parent.span_id) if span.parent else None
157
- )
158
- span_path = f"{parent_span_path}.{span.name}" if parent_span_path else span.name
159
- span.set_attribute(SPAN_PATH, span_path)
160
- set_value("span_path", span_path, get_current())
161
- self.__span_id_to_path[span.get_span_context().span_id] = span_path
162
-
163
- span.set_attribute(SPAN_INSTRUMENTATION_SOURCE, "python")
164
-
165
- association_properties = get_value("association_properties")
166
- if association_properties is not None:
167
- _set_association_properties_attributes(span, association_properties)
168
-
169
- if not self.enable_content_tracing:
170
- if self.__content_allow_list.is_allowed(association_properties):
171
- attach(set_value("override_enable_content_tracing", True))
172
- else:
173
- attach(set_value("override_enable_content_tracing", False))
174
-
175
- # Call original on_start method if it exists in custom processor
176
- if self.__spans_processor_original_on_start:
177
- self.__spans_processor_original_on_start(span, parent_context)
178
-
179
- @staticmethod
180
- def set_static_params(
181
- resource_attributes: dict,
182
- enable_content_tracing: bool,
183
- endpoint: str,
184
- headers: Dict[str, str],
185
- ) -> None:
186
- TracerWrapper.resource_attributes = resource_attributes
187
- TracerWrapper.enable_content_tracing = enable_content_tracing
188
- TracerWrapper.endpoint = endpoint
189
- TracerWrapper.headers = headers
190
-
191
- @classmethod
192
- def verify_initialized(cls) -> bool:
193
- return hasattr(cls, "instance")
194
-
195
- @classmethod
196
- def clear(cls):
197
- # Any state cleanup. Now used in between tests
198
- cls.__span_id_to_path = {}
199
-
200
- def flush(self):
201
- self.__spans_processor.force_flush()
202
-
203
- def get_tracer(self):
204
- return self.__tracer_provider.get_tracer(TRACER_NAME)
205
-
206
-
207
- def set_association_properties(properties: dict) -> None:
208
- attach(set_value("association_properties", properties))
209
-
210
- span = trace.get_current_span()
211
- _set_association_properties_attributes(span, properties)
212
-
213
-
214
- def update_association_properties(
215
- properties: dict,
216
- set_on_current_span: bool = True,
217
- context: Optional[Context] = None,
218
- ) -> None:
219
- """Only adds or updates properties that are not already present"""
220
- association_properties = get_value("association_properties", context) or {}
221
- association_properties.update(properties)
222
-
223
- attach(set_value("association_properties", association_properties, context))
224
-
225
- if set_on_current_span:
226
- span = trace.get_current_span()
227
- _set_association_properties_attributes(span, properties)
228
-
229
-
230
- def remove_association_properties(properties: dict) -> None:
231
- props: dict = copy.copy(get_value("association_properties") or {})
232
- for k in properties.keys():
233
- props.pop(k, None)
234
- set_association_properties(props)
235
-
236
-
237
- def _set_association_properties_attributes(span, properties: dict) -> None:
238
- for key, value in properties.items():
239
- if key == TRACING_LEVEL:
240
- span.set_attribute(f"lmnr.internal.{TRACING_LEVEL}", value)
241
- continue
242
- span.set_attribute(f"{ASSOCIATION_PROPERTIES}.{key}", value)
243
-
244
-
245
- def set_managed_prompt_tracing_context(
246
- key: str,
247
- version: int,
248
- version_name: str,
249
- version_hash: str,
250
- template_variables: dict,
251
- ) -> None:
252
- attach(set_value("managed_prompt", True))
253
- attach(set_value("prompt_key", key))
254
- attach(set_value("prompt_version", version))
255
- attach(set_value("prompt_version_name", version_name))
256
- attach(set_value("prompt_version_hash", version_hash))
257
- attach(set_value("prompt_template_variables", template_variables))
258
-
259
-
260
- def init_spans_exporter(api_endpoint: str, headers: Dict[str, str]) -> SpanExporter:
261
- if "http" in api_endpoint.lower() or "https" in api_endpoint.lower():
262
- return HTTPExporter(endpoint=f"{api_endpoint}/v1/traces", headers=headers)
263
- else:
264
- return GRPCExporter(endpoint=f"{api_endpoint}", headers=headers)
265
-
266
-
267
- def init_tracer_provider(resource: Resource) -> TracerProvider:
268
- provider: TracerProvider = None
269
- default_provider: TracerProvider = get_tracer_provider()
270
-
271
- if isinstance(default_provider, ProxyTracerProvider):
272
- provider = TracerProvider(resource=resource)
273
- trace.set_tracer_provider(provider)
274
- elif not hasattr(default_provider, "add_span_processor"):
275
- module_logger.error(
276
- "Cannot add span processor to the default provider since it doesn't support it"
277
- )
278
- return
279
- else:
280
- provider = default_provider
281
-
282
- return provider
283
-
284
-
285
- def init_instrumentations(
286
- should_enrich_metrics: bool,
287
- instruments: Optional[Set[Instruments]] = None,
288
- block_instruments: Optional[Set[Instruments]] = None,
289
- ):
290
- block_instruments = block_instruments or set()
291
- # These libraries are not instrumented by default,
292
- # but if the user wants, they can manually specify them
293
- default_off_instruments = set(
294
- [
295
- Instruments.REQUESTS,
296
- Instruments.URLLIB3,
297
- Instruments.REDIS,
298
- Instruments.PYMYSQL,
299
- ]
300
- )
301
-
302
- instruments = (
303
- instruments
304
- if instruments is not None
305
- else (set(Instruments) - default_off_instruments)
306
- )
307
-
308
- # Remove any instruments that were explicitly blocked
309
- instruments = instruments - block_instruments
310
-
311
- instrument_set = False
312
- for instrument in instruments:
313
- if instrument == Instruments.ALEPHALPHA:
314
- if init_alephalpha_instrumentor():
315
- instrument_set = True
316
- elif instrument == Instruments.ANTHROPIC:
317
- if init_anthropic_instrumentor(should_enrich_metrics):
318
- instrument_set = True
319
- elif instrument == Instruments.BEDROCK:
320
- if init_bedrock_instrumentor(should_enrich_metrics):
321
- instrument_set = True
322
- elif instrument == Instruments.CHROMA:
323
- if init_chroma_instrumentor():
324
- instrument_set = True
325
- elif instrument == Instruments.COHERE:
326
- if init_cohere_instrumentor():
327
- instrument_set = True
328
- elif instrument == Instruments.GOOGLE_GENERATIVEAI:
329
- if init_google_generativeai_instrumentor():
330
- instrument_set = True
331
- elif instrument == Instruments.GROQ:
332
- if init_groq_instrumentor():
333
- instrument_set = True
334
- elif instrument == Instruments.HAYSTACK:
335
- if init_haystack_instrumentor():
336
- instrument_set = True
337
- elif instrument == Instruments.LANCEDB:
338
- if init_lancedb_instrumentor():
339
- instrument_set = True
340
- elif instrument == Instruments.LANGCHAIN:
341
- if init_langchain_instrumentor():
342
- instrument_set = True
343
- elif instrument == Instruments.LLAMA_INDEX:
344
- if init_llama_index_instrumentor():
345
- instrument_set = True
346
- elif instrument == Instruments.MARQO:
347
- if init_marqo_instrumentor():
348
- instrument_set = True
349
- elif instrument == Instruments.MILVUS:
350
- if init_milvus_instrumentor():
351
- instrument_set = True
352
- elif instrument == Instruments.MISTRAL:
353
- if init_mistralai_instrumentor():
354
- instrument_set = True
355
- elif instrument == Instruments.OLLAMA:
356
- if init_ollama_instrumentor():
357
- instrument_set = True
358
- elif instrument == Instruments.OPENAI:
359
- if init_openai_instrumentor(should_enrich_metrics):
360
- instrument_set = True
361
- elif instrument == Instruments.PINECONE:
362
- if init_pinecone_instrumentor():
363
- instrument_set = True
364
- elif instrument == Instruments.PYMYSQL:
365
- if init_pymysql_instrumentor():
366
- instrument_set = True
367
- elif instrument == Instruments.QDRANT:
368
- if init_qdrant_instrumentor():
369
- instrument_set = True
370
- elif instrument == Instruments.REDIS:
371
- if init_redis_instrumentor():
372
- instrument_set = True
373
- elif instrument == Instruments.REPLICATE:
374
- if init_replicate_instrumentor():
375
- instrument_set = True
376
- elif instrument == Instruments.REQUESTS:
377
- if init_requests_instrumentor():
378
- instrument_set = True
379
- elif instrument == Instruments.SAGEMAKER:
380
- if init_sagemaker_instrumentor(should_enrich_metrics):
381
- instrument_set = True
382
- elif instrument == Instruments.TOGETHER:
383
- if init_together_instrumentor():
384
- instrument_set = True
385
- elif instrument == Instruments.TRANSFORMERS:
386
- if init_transformers_instrumentor():
387
- instrument_set = True
388
- elif instrument == Instruments.URLLIB3:
389
- if init_urllib3_instrumentor():
390
- instrument_set = True
391
- elif instrument == Instruments.VERTEXAI:
392
- if init_vertexai_instrumentor():
393
- instrument_set = True
394
- elif instrument == Instruments.WATSONX:
395
- if init_watsonx_instrumentor():
396
- instrument_set = True
397
- elif instrument == Instruments.WEAVIATE:
398
- if init_weaviate_instrumentor():
399
- instrument_set = True
400
- else:
401
- module_logger.warning(
402
- f"Warning: {instrument} instrumentation does not exist."
403
- )
404
- module_logger.warning(
405
- "Usage:\n"
406
- "from lmnr import Laminar, Instruments\n"
407
- "Laminar.init(instruments=set([Instruments.OPENAI]))"
408
- )
409
-
410
- return instrument_set
411
-
412
-
413
- def init_openai_instrumentor(should_enrich_metrics: bool):
414
- try:
415
- if is_package_installed("openai") and is_package_installed(
416
- "opentelemetry-instrumentation-openai"
417
- ):
418
- from opentelemetry.instrumentation.openai import OpenAIInstrumentor
419
-
420
- instrumentor = OpenAIInstrumentor(
421
- enrich_assistant=should_enrich_metrics,
422
- enrich_token_usage=should_enrich_metrics,
423
- )
424
- if not instrumentor.is_instrumented_by_opentelemetry:
425
- instrumentor.instrument()
426
- return True
427
-
428
- except Exception as e:
429
- module_logger.error(f"Error initializing OpenAI instrumentor: {e}")
430
- return False
431
-
432
-
433
- def init_anthropic_instrumentor(should_enrich_metrics: bool):
434
- try:
435
- if is_package_installed("anthropic") and is_package_installed(
436
- "opentelemetry-instrumentation-anthropic"
437
- ):
438
- from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
439
-
440
- instrumentor = AnthropicInstrumentor(
441
- enrich_token_usage=should_enrich_metrics,
442
- upload_base64_image=None,
443
- )
444
- if not instrumentor.is_instrumented_by_opentelemetry:
445
- instrumentor.instrument()
446
- return True
447
- except Exception as e:
448
- module_logger.error(f"Error initializing Anthropic instrumentor: {e}")
449
- return False
450
-
451
-
452
- def init_cohere_instrumentor():
453
- try:
454
- if is_package_installed("cohere") and is_package_installed(
455
- "opentelemetry-instrumentation-cohere"
456
- ):
457
- from opentelemetry.instrumentation.cohere import CohereInstrumentor
458
-
459
- instrumentor = CohereInstrumentor()
460
- if not instrumentor.is_instrumented_by_opentelemetry:
461
- instrumentor.instrument()
462
- return True
463
- except Exception as e:
464
- module_logger.error(f"Error initializing Cohere instrumentor: {e}")
465
- return False
466
-
467
-
468
- def init_pinecone_instrumentor():
469
- try:
470
- if is_package_installed("pinecone") and is_package_installed(
471
- "opentelemetry-instrumentation-pinecone"
472
- ):
473
- from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
474
-
475
- instrumentor = PineconeInstrumentor()
476
- if not instrumentor.is_instrumented_by_opentelemetry:
477
- instrumentor.instrument()
478
- return True
479
- except Exception as e:
480
- module_logger.error(f"Error initializing Pinecone instrumentor: {e}")
481
- return False
482
-
483
-
484
- def init_qdrant_instrumentor():
485
- try:
486
- if is_package_installed("qdrant_client") and is_package_installed(
487
- "opentelemetry-instrumentation-qdrant"
488
- ):
489
- from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
490
-
491
- instrumentor = QdrantInstrumentor()
492
- if not instrumentor.is_instrumented_by_opentelemetry:
493
- instrumentor.instrument()
494
- except Exception as e:
495
- module_logger.error(f"Error initializing Qdrant instrumentor: {e}")
496
- return False
497
-
498
-
499
- def init_chroma_instrumentor():
500
- try:
501
- if is_package_installed("chromadb") and is_package_installed(
502
- "opentelemetry-instrumentation-chromadb"
503
- ):
504
- from opentelemetry.instrumentation.chromadb import ChromaInstrumentor
505
-
506
- instrumentor = ChromaInstrumentor()
507
- if not instrumentor.is_instrumented_by_opentelemetry:
508
- instrumentor.instrument()
509
- return True
510
- except Exception as e:
511
- module_logger.error(f"Error initializing Chroma instrumentor: {e}")
512
- return False
513
-
514
-
515
- def init_google_generativeai_instrumentor():
516
- try:
517
- if is_package_installed("google-generativeai") and is_package_installed(
518
- "opentelemetry-instrumentation-google-generativeai"
519
- ):
520
- from opentelemetry.instrumentation.google_generativeai import (
521
- GoogleGenerativeAiInstrumentor,
522
- )
523
-
524
- instrumentor = GoogleGenerativeAiInstrumentor()
525
- if not instrumentor.is_instrumented_by_opentelemetry:
526
- instrumentor.instrument()
527
- return True
528
- except Exception as e:
529
- module_logger.error(f"Error initializing Gemini instrumentor: {e}")
530
- return False
531
-
532
-
533
- def init_haystack_instrumentor():
534
- try:
535
- if is_package_installed("haystack") and is_package_installed(
536
- "opentelemetry-instrumentation-haystack"
537
- ):
538
- from opentelemetry.instrumentation.haystack import HaystackInstrumentor
539
-
540
- instrumentor = HaystackInstrumentor()
541
- if not instrumentor.is_instrumented_by_opentelemetry:
542
- instrumentor.instrument()
543
- return True
544
- except Exception as e:
545
- module_logger.error(f"Error initializing Haystack instrumentor: {e}")
546
- return False
547
-
548
-
549
- def init_langchain_instrumentor():
550
- try:
551
- if is_package_installed("langchain") and is_package_installed(
552
- "opentelemetry-instrumentation-langchain"
553
- ):
554
- from opentelemetry.instrumentation.langchain import LangchainInstrumentor
555
-
556
- instrumentor = LangchainInstrumentor()
557
- if not instrumentor.is_instrumented_by_opentelemetry:
558
- instrumentor.instrument()
559
- return True
560
- except Exception as e:
561
- # FIXME: silencing this error temporarily, it appears to not be critical
562
- if str(e) != "No module named 'langchain_community'":
563
- module_logger.error(f"Error initializing LangChain instrumentor: {e}")
564
- return False
565
-
566
-
567
- def init_mistralai_instrumentor():
568
- try:
569
- if is_package_installed("mistralai") and is_package_installed(
570
- "opentelemetry-instrumentation-mistralai"
571
- ):
572
- from opentelemetry.instrumentation.mistralai import MistralAiInstrumentor
573
-
574
- instrumentor = MistralAiInstrumentor()
575
- if not instrumentor.is_instrumented_by_opentelemetry:
576
- instrumentor.instrument()
577
- return True
578
- except Exception as e:
579
- module_logger.error(f"Error initializing MistralAI instrumentor: {e}")
580
- return False
581
-
582
-
583
- def init_ollama_instrumentor():
584
- try:
585
- if is_package_installed("ollama") and is_package_installed(
586
- "opentelemetry-instrumentation-ollama"
587
- ):
588
- from opentelemetry.instrumentation.ollama import OllamaInstrumentor
589
-
590
- instrumentor = OllamaInstrumentor()
591
- if not instrumentor.is_instrumented_by_opentelemetry:
592
- instrumentor.instrument()
593
- return True
594
- except Exception as e:
595
- module_logger.error(f"Error initializing Ollama instrumentor: {e}")
596
- return False
597
-
598
-
599
- def init_transformers_instrumentor():
600
- try:
601
- if is_package_installed("transformers") and is_package_installed(
602
- "opentelemetry-instrumentation-transformers"
603
- ):
604
- from opentelemetry.instrumentation.transformers import (
605
- TransformersInstrumentor,
606
- )
607
-
608
- instrumentor = TransformersInstrumentor()
609
- if not instrumentor.is_instrumented_by_opentelemetry:
610
- instrumentor.instrument()
611
- return True
612
- except Exception as e:
613
- module_logger.error(f"Error initializing Transformers instrumentor: {e}")
614
- return False
615
-
616
-
617
- def init_together_instrumentor():
618
- try:
619
- if is_package_installed("together") and is_package_installed(
620
- "opentelemetry-instrumentation-together"
621
- ):
622
- from opentelemetry.instrumentation.together import TogetherAiInstrumentor
623
-
624
- instrumentor = TogetherAiInstrumentor()
625
- if not instrumentor.is_instrumented_by_opentelemetry:
626
- instrumentor.instrument()
627
- return True
628
- except Exception as e:
629
- module_logger.error(f"Error initializing TogetherAI instrumentor: {e}")
630
- return False
631
-
632
-
633
- def init_llama_index_instrumentor():
634
- try:
635
- if (
636
- is_package_installed("llama-index") or is_package_installed("llama_index")
637
- ) and is_package_installed("opentelemetry-instrumentation-llamaindex"):
638
- from opentelemetry.instrumentation.llamaindex import LlamaIndexInstrumentor
639
-
640
- instrumentor = LlamaIndexInstrumentor()
641
- if not instrumentor.is_instrumented_by_opentelemetry:
642
- instrumentor.instrument()
643
- return True
644
- except Exception as e:
645
- module_logger.error(f"Error initializing LlamaIndex instrumentor: {e}")
646
- return False
647
-
648
-
649
- def init_milvus_instrumentor():
650
- try:
651
- if is_package_installed("pymilvus") and is_package_installed(
652
- "opentelemetry-instrumentation-milvus"
653
- ):
654
- from opentelemetry.instrumentation.milvus import MilvusInstrumentor
655
-
656
- instrumentor = MilvusInstrumentor()
657
- if not instrumentor.is_instrumented_by_opentelemetry:
658
- instrumentor.instrument()
659
- return True
660
- except Exception as e:
661
- module_logger.error(f"Error initializing Milvus instrumentor: {e}")
662
- return False
663
-
664
-
665
- def init_requests_instrumentor():
666
- try:
667
- if is_package_installed("requests"):
668
- from opentelemetry.instrumentation.requests import RequestsInstrumentor
669
-
670
- instrumentor = RequestsInstrumentor()
671
- if not instrumentor.is_instrumented_by_opentelemetry:
672
- instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
673
- return True
674
- except Exception as e:
675
- module_logger.error(f"Error initializing Requests instrumentor: {e}")
676
- return False
677
-
678
-
679
- def init_urllib3_instrumentor():
680
- try:
681
- if is_package_installed("urllib3"):
682
- from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
683
-
684
- instrumentor = URLLib3Instrumentor()
685
- if not instrumentor.is_instrumented_by_opentelemetry:
686
- instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
687
- return True
688
- except Exception as e:
689
- module_logger.error(f"Error initializing urllib3 instrumentor: {e}")
690
- return False
691
-
692
-
693
- def init_pymysql_instrumentor():
694
- try:
695
- if is_package_installed("sqlalchemy"):
696
- from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
697
-
698
- instrumentor = SQLAlchemyInstrumentor()
699
- if not instrumentor.is_instrumented_by_opentelemetry:
700
- instrumentor.instrument()
701
- return True
702
- except Exception as e:
703
- module_logger.error(f"Error initializing SQLAlchemy instrumentor: {e}")
704
- return False
705
-
706
-
707
- def init_bedrock_instrumentor(should_enrich_metrics: bool):
708
- try:
709
- if is_package_installed("boto3") and is_package_installed(
710
- "opentelemetry-instrumentation-bedrock"
711
- ):
712
- from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
713
-
714
- instrumentor = BedrockInstrumentor(
715
- enrich_token_usage=should_enrich_metrics,
716
- )
717
- if not instrumentor.is_instrumented_by_opentelemetry:
718
- instrumentor.instrument()
719
- return True
720
- except Exception as e:
721
- module_logger.error(f"Error initializing Bedrock instrumentor: {e}")
722
- return False
723
-
724
-
725
- def init_replicate_instrumentor():
726
- try:
727
- if is_package_installed("replicate") and is_package_installed(
728
- "opentelemetry-instrumentation-replicate"
729
- ):
730
- from opentelemetry.instrumentation.replicate import ReplicateInstrumentor
731
-
732
- instrumentor = ReplicateInstrumentor()
733
- if not instrumentor.is_instrumented_by_opentelemetry:
734
- instrumentor.instrument()
735
- return True
736
- except Exception as e:
737
- module_logger.error(f"Error initializing Replicate instrumentor: {e}")
738
- return False
739
-
740
-
741
- def init_vertexai_instrumentor():
742
- try:
743
- if is_package_installed("vertexai") and is_package_installed(
744
- "opentelemetry-instrumentation-vertexai"
745
- ):
746
- from opentelemetry.instrumentation.vertexai import VertexAIInstrumentor
747
-
748
- instrumentor = VertexAIInstrumentor()
749
- if not instrumentor.is_instrumented_by_opentelemetry:
750
- instrumentor.instrument()
751
- return True
752
- except Exception as e:
753
- module_logger.warning(f"Error initializing Vertex AI instrumentor: {e}")
754
- return False
755
-
756
-
757
- def init_watsonx_instrumentor():
758
- try:
759
- if (
760
- is_package_installed("ibm-watsonx-ai")
761
- or is_package_installed("ibm-watson-machine-learning")
762
- ) and is_package_installed("opentelemetry-instrumentation-watsonx"):
763
- from opentelemetry.instrumentation.watsonx import WatsonxInstrumentor
764
-
765
- instrumentor = WatsonxInstrumentor()
766
- if not instrumentor.is_instrumented_by_opentelemetry:
767
- instrumentor.instrument()
768
- return True
769
- except Exception as e:
770
- module_logger.warning(f"Error initializing Watsonx instrumentor: {e}")
771
- return False
772
-
773
-
774
- def init_weaviate_instrumentor():
775
- try:
776
- if is_package_installed("weaviate") and is_package_installed(
777
- "opentelemetry-instrumentation-weaviate"
778
- ):
779
- from opentelemetry.instrumentation.weaviate import WeaviateInstrumentor
780
-
781
- instrumentor = WeaviateInstrumentor()
782
- if not instrumentor.is_instrumented_by_opentelemetry:
783
- instrumentor.instrument()
784
- return True
785
- except Exception as e:
786
- module_logger.warning(f"Error initializing Weaviate instrumentor: {e}")
787
- return False
788
-
789
-
790
- def init_alephalpha_instrumentor():
791
- try:
792
- if is_package_installed("aleph_alpha_client") and is_package_installed(
793
- "opentelemetry-instrumentation-alephalpha"
794
- ):
795
- from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor
796
-
797
- instrumentor = AlephAlphaInstrumentor()
798
- if not instrumentor.is_instrumented_by_opentelemetry:
799
- instrumentor.instrument()
800
- return True
801
- except Exception as e:
802
- module_logger.error(f"Error initializing Aleph Alpha instrumentor: {e}")
803
- return False
804
-
805
-
806
- def init_marqo_instrumentor():
807
- try:
808
- if is_package_installed("marqo") and is_package_installed(
809
- "opentelemetry-instrumentation-marqo"
810
- ):
811
- from opentelemetry.instrumentation.marqo import MarqoInstrumentor
812
-
813
- instrumentor = MarqoInstrumentor()
814
- if not instrumentor.is_instrumented_by_opentelemetry:
815
- instrumentor.instrument()
816
- return True
817
- except Exception as e:
818
- module_logger.error(f"Error initializing marqo instrumentor: {e}")
819
- return False
820
-
821
-
822
- def init_lancedb_instrumentor():
823
- try:
824
- if is_package_installed("lancedb") and is_package_installed(
825
- "opentelemetry-instrumentation-lancedb"
826
- ):
827
- from opentelemetry.instrumentation.lancedb import LanceInstrumentor
828
-
829
- instrumentor = LanceInstrumentor()
830
- if not instrumentor.is_instrumented_by_opentelemetry:
831
- instrumentor.instrument()
832
- return True
833
- except Exception as e:
834
- module_logger.error(f"Error initializing LanceDB instrumentor: {e}")
835
-
836
-
837
- def init_redis_instrumentor():
838
- try:
839
- if is_package_installed("redis") and is_package_installed(
840
- "opentelemetry-instrumentation-redis"
841
- ):
842
- from opentelemetry.instrumentation.redis import RedisInstrumentor
843
-
844
- instrumentor = RedisInstrumentor()
845
- if not instrumentor.is_instrumented_by_opentelemetry:
846
- instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
847
- return True
848
- except Exception as e:
849
- module_logger.error(f"Error initializing redis instrumentor: {e}")
850
- return False
851
-
852
-
853
- def init_groq_instrumentor():
854
- try:
855
- if is_package_installed("groq") and is_package_installed(
856
- "opentelemetry-instrumentation-groq"
857
- ):
858
- from opentelemetry.instrumentation.groq import GroqInstrumentor
859
-
860
- instrumentor = GroqInstrumentor()
861
- if not instrumentor.is_instrumented_by_opentelemetry:
862
- instrumentor.instrument()
863
- return True
864
- except Exception as e:
865
- module_logger.error(f"Error initializing Groq instrumentor: {e}")
866
- return False
867
-
868
-
869
- def init_sagemaker_instrumentor(should_enrich_metrics: bool):
870
- try:
871
- if is_package_installed("boto3") and is_package_installed(
872
- "opentelemetry-instrumentation-sagemaker"
873
- ):
874
- from opentelemetry.instrumentation.sagemaker import SageMakerInstrumentor
875
-
876
- instrumentor = SageMakerInstrumentor(
877
- enrich_token_usage=should_enrich_metrics,
878
- )
879
- if not instrumentor.is_instrumented_by_opentelemetry:
880
- instrumentor.instrument()
881
- return True
882
- except Exception as e:
883
- module_logger.error(f"Error initializing SageMaker instrumentor: {e}")
884
- return False