lmnr 0.5.1a0__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lmnr/__init__.py +2 -10
- lmnr/cli.py +10 -8
- lmnr/{openllmetry_sdk → opentelemetry_lib}/__init__.py +8 -36
- lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/base.py +27 -20
- lmnr/{openllmetry_sdk → opentelemetry_lib}/instruments.py +2 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/__init__.py +454 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/config.py +9 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/utils.py +216 -0
- lmnr/opentelemetry_lib/tracing/__init__.py +1 -0
- lmnr/opentelemetry_lib/tracing/context_manager.py +13 -0
- lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/tracing.py +253 -257
- lmnr/sdk/browser/browser_use_otel.py +20 -3
- lmnr/sdk/browser/patchright_otel.py +177 -0
- lmnr/sdk/browser/playwright_otel.py +55 -62
- lmnr/sdk/browser/pw_utils.py +122 -116
- lmnr/sdk/browser/rrweb/rrweb.umd.min.cjs +98 -0
- lmnr/sdk/client/asynchronous/async_client.py +0 -34
- lmnr/sdk/client/asynchronous/resources/__init__.py +0 -4
- lmnr/sdk/client/asynchronous/resources/agent.py +115 -6
- lmnr/sdk/client/synchronous/resources/__init__.py +1 -3
- lmnr/sdk/client/synchronous/resources/agent.py +112 -6
- lmnr/sdk/client/synchronous/sync_client.py +0 -36
- lmnr/sdk/decorators.py +19 -5
- lmnr/sdk/eval_control.py +3 -2
- lmnr/sdk/evaluations.py +8 -14
- lmnr/sdk/laminar.py +10 -10
- lmnr/sdk/types.py +86 -170
- lmnr/sdk/utils.py +8 -1
- lmnr/version.py +1 -1
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/METADATA +58 -58
- lmnr-0.5.3.dist-info/RECORD +55 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/WHEEL +1 -1
- lmnr/openllmetry_sdk/tracing/__init__.py +0 -0
- lmnr/sdk/browser/rrweb/rrweb.min.js +0 -18
- lmnr/sdk/client/asynchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/asynchronous/resources/semantic_search.py +0 -60
- lmnr/sdk/client/synchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/synchronous/resources/semantic_search.py +0 -60
- lmnr-0.5.1a0.dist-info/RECORD +0 -54
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/.flake8 +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/config/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/attributes.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/content_allow_list.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/in_memory_span_exporter.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/json_encoder.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/package_check.py +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/LICENSE +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/entry_points.txt +0 -0
@@ -4,9 +4,11 @@ import logging
|
|
4
4
|
import uuid
|
5
5
|
|
6
6
|
from contextvars import Context
|
7
|
+
from lmnr.sdk.client.asynchronous.async_client import AsyncLaminarClient
|
8
|
+
from lmnr.sdk.client.synchronous.sync_client import LaminarClient
|
7
9
|
from lmnr.sdk.log import VerboseColorfulFormatter
|
8
|
-
from lmnr.
|
9
|
-
from lmnr.
|
10
|
+
from lmnr.opentelemetry_lib.instruments import Instruments
|
11
|
+
from lmnr.opentelemetry_lib.tracing.attributes import (
|
10
12
|
ASSOCIATION_PROPERTIES,
|
11
13
|
SPAN_IDS_PATH,
|
12
14
|
SPAN_INSTRUMENTATION_SOURCE,
|
@@ -15,9 +17,9 @@ from lmnr.openllmetry_sdk.tracing.attributes import (
|
|
15
17
|
SPAN_PATH,
|
16
18
|
TRACING_LEVEL,
|
17
19
|
)
|
18
|
-
from lmnr.
|
19
|
-
from lmnr.
|
20
|
-
from lmnr.
|
20
|
+
from lmnr.opentelemetry_lib.tracing.content_allow_list import ContentAllowList
|
21
|
+
from lmnr.opentelemetry_lib.utils import is_notebook
|
22
|
+
from lmnr.opentelemetry_lib.utils.package_check import is_package_installed
|
21
23
|
from opentelemetry import trace
|
22
24
|
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
23
25
|
OTLPSpanExporter as HTTPExporter,
|
@@ -25,8 +27,8 @@ from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
|
25
27
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
|
26
28
|
OTLPSpanExporter as GRPCExporter,
|
27
29
|
)
|
28
|
-
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
29
30
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import Compression
|
31
|
+
from opentelemetry.instrumentation.threading import ThreadingInstrumentor
|
30
32
|
from opentelemetry.context import get_value, attach, get_current, set_value
|
31
33
|
from opentelemetry.propagate import set_global_textmap
|
32
34
|
from opentelemetry.propagators.textmap import TextMapPropagator
|
@@ -37,7 +39,7 @@ from opentelemetry.sdk.trace.export import (
|
|
37
39
|
SimpleSpanProcessor,
|
38
40
|
BatchSpanProcessor,
|
39
41
|
)
|
40
|
-
from opentelemetry.trace import ProxyTracerProvider
|
42
|
+
from opentelemetry.trace import get_tracer_provider, ProxyTracerProvider
|
41
43
|
|
42
44
|
from typing import Dict, Optional, Set
|
43
45
|
|
@@ -69,14 +71,24 @@ EXCLUDED_URLS = """
|
|
69
71
|
openaipublic.blob.core.windows.net"""
|
70
72
|
|
71
73
|
MAX_EVENTS_OR_ATTRIBUTES_PER_SPAN = 5000
|
72
|
-
instrumentors: dict[str, BaseInstrumentor] = {}
|
73
74
|
|
74
75
|
|
75
76
|
class TracerWrapper(object):
|
77
|
+
resource_attributes: dict = {}
|
78
|
+
enable_content_tracing: bool = True
|
79
|
+
endpoint: str = None
|
80
|
+
headers: Dict[str, str] = {}
|
76
81
|
__tracer_provider: TracerProvider = None
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
__logger: logging.Logger = None
|
83
|
+
__span_id_to_path: dict[int, list[str]] = {}
|
84
|
+
__span_id_lists: dict[int, list[str]] = {}
|
85
|
+
__client: LaminarClient = None
|
86
|
+
__async_client: AsyncLaminarClient = None
|
87
|
+
__spans_processor: SpanProcessor = None
|
88
|
+
__spans_exporter: SpanExporter = None
|
89
|
+
|
90
|
+
def __new__(
|
91
|
+
cls,
|
80
92
|
disable_batch=False,
|
81
93
|
processor: Optional[SpanProcessor] = None,
|
82
94
|
propagator: Optional[TextMapPropagator] = None,
|
@@ -86,73 +98,82 @@ class TracerWrapper(object):
|
|
86
98
|
base_http_url: Optional[str] = None,
|
87
99
|
project_api_key: Optional[str] = None,
|
88
100
|
max_export_batch_size: Optional[int] = None,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
self.__span_id_to_path = {}
|
104
|
-
self.__span_id_lists = {}
|
105
|
-
|
106
|
-
if not self.endpoint:
|
107
|
-
return
|
108
|
-
|
109
|
-
self.__resource = Resource(attributes=self.resource_attributes)
|
110
|
-
self.__tracer_provider = init_tracer_provider(resource=self.__resource)
|
111
|
-
if processor:
|
112
|
-
self.__spans_processor = processor
|
113
|
-
self.__spans_processor_original_on_start = processor.on_start
|
114
|
-
else:
|
115
|
-
self.__spans_exporter = (
|
116
|
-
exporter
|
117
|
-
if exporter
|
118
|
-
else init_spans_exporter(self.endpoint, self.headers)
|
101
|
+
) -> "TracerWrapper":
|
102
|
+
cls._initialize_logger(cls)
|
103
|
+
if not hasattr(cls, "instance"):
|
104
|
+
obj = cls.instance = super(TracerWrapper, cls).__new__(cls)
|
105
|
+
if not TracerWrapper.endpoint:
|
106
|
+
return obj
|
107
|
+
|
108
|
+
obj.__client = LaminarClient(
|
109
|
+
base_url=base_http_url,
|
110
|
+
project_api_key=project_api_key,
|
111
|
+
)
|
112
|
+
obj.__async_client = AsyncLaminarClient(
|
113
|
+
base_url=base_http_url,
|
114
|
+
project_api_key=project_api_key,
|
119
115
|
)
|
120
|
-
|
121
|
-
|
116
|
+
|
117
|
+
obj.__resource = Resource(attributes=TracerWrapper.resource_attributes)
|
118
|
+
obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
|
119
|
+
if processor:
|
120
|
+
obj.__spans_processor = processor
|
121
|
+
obj.__spans_processor_original_on_start = processor.on_start
|
122
122
|
else:
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
obj.__spans_exporter = (
|
124
|
+
exporter
|
125
|
+
if exporter
|
126
|
+
else init_spans_exporter(
|
127
|
+
TracerWrapper.endpoint, TracerWrapper.headers
|
128
|
+
)
|
126
129
|
)
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
if disable_batch or is_notebook():
|
131
|
+
obj.__spans_processor = SimpleSpanProcessor(obj.__spans_exporter)
|
132
|
+
else:
|
133
|
+
obj.__spans_processor = BatchSpanProcessor(
|
134
|
+
obj.__spans_exporter,
|
135
|
+
max_export_batch_size=max_export_batch_size,
|
136
|
+
)
|
137
|
+
obj.__spans_processor_original_on_start = None
|
138
|
+
|
139
|
+
obj.__spans_processor.on_start = obj._span_processor_on_start
|
140
|
+
obj.__tracer_provider.add_span_processor(obj.__spans_processor)
|
141
|
+
|
142
|
+
if propagator:
|
143
|
+
set_global_textmap(propagator)
|
144
|
+
|
145
|
+
# this makes sure otel context is propagated so we always want it
|
146
|
+
ThreadingInstrumentor().instrument()
|
147
|
+
|
148
|
+
instrument_set = init_instrumentations(
|
149
|
+
should_enrich_metrics,
|
150
|
+
instruments,
|
151
|
+
client=obj.__client,
|
152
|
+
async_client=obj.__async_client,
|
153
|
+
)
|
134
154
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
base_http_url=base_http_url,
|
141
|
-
)
|
155
|
+
if not instrument_set:
|
156
|
+
cls.__logger.info(
|
157
|
+
"No instruments set through Laminar. "
|
158
|
+
"Only enabling basic OpenTelemetry tracing."
|
159
|
+
)
|
142
160
|
|
143
|
-
|
144
|
-
self.__logger.info(
|
145
|
-
"No instruments set through Laminar. "
|
146
|
-
"Only enabling basic OpenTelemetry tracing."
|
147
|
-
)
|
161
|
+
obj.__content_allow_list = ContentAllowList()
|
148
162
|
|
149
|
-
|
163
|
+
# Force flushes for debug environments (e.g. local development)
|
164
|
+
atexit.register(obj.exit_handler)
|
150
165
|
|
151
|
-
|
152
|
-
atexit.register(self.exit_handler)
|
166
|
+
return cls.instance
|
153
167
|
|
154
168
|
def exit_handler(self):
|
155
|
-
self.
|
169
|
+
self.__span_id_to_path = {}
|
170
|
+
self.flush()
|
171
|
+
|
172
|
+
def _initialize_logger(self):
|
173
|
+
self.__logger = logging.getLogger(__name__)
|
174
|
+
console_log_handler = logging.StreamHandler()
|
175
|
+
console_log_handler.setFormatter(VerboseColorfulFormatter())
|
176
|
+
self.__logger.addHandler(console_log_handler)
|
156
177
|
|
157
178
|
def _span_processor_on_start(
|
158
179
|
self, span: Span, parent_context: Optional[Context] = None
|
@@ -193,24 +214,30 @@ class TracerWrapper(object):
|
|
193
214
|
if self.__spans_processor_original_on_start:
|
194
215
|
self.__spans_processor_original_on_start(span, parent_context)
|
195
216
|
|
196
|
-
|
217
|
+
@staticmethod
|
218
|
+
def set_static_params(
|
219
|
+
resource_attributes: dict,
|
220
|
+
enable_content_tracing: bool,
|
221
|
+
endpoint: str,
|
222
|
+
headers: Dict[str, str],
|
223
|
+
) -> None:
|
224
|
+
TracerWrapper.resource_attributes = resource_attributes
|
225
|
+
TracerWrapper.enable_content_tracing = enable_content_tracing
|
226
|
+
TracerWrapper.endpoint = endpoint
|
227
|
+
TracerWrapper.headers = headers
|
228
|
+
|
229
|
+
@classmethod
|
230
|
+
def verify_initialized(cls) -> bool:
|
231
|
+
return hasattr(cls, "instance")
|
232
|
+
|
233
|
+
@classmethod
|
234
|
+
def clear(cls):
|
197
235
|
# Any state cleanup. Now used in between tests
|
198
|
-
|
199
|
-
|
236
|
+
cls.__span_id_to_path = {}
|
237
|
+
cls.__span_id_lists = {}
|
200
238
|
|
201
239
|
def shutdown(self):
|
202
|
-
|
203
|
-
self.__spans_processor.force_flush(timeout_millis=30000)
|
204
|
-
for v in instrumentors.values():
|
205
|
-
try:
|
206
|
-
v.uninstrument()
|
207
|
-
except Exception:
|
208
|
-
self.__logger.debug("Error uninstrumenting instrumentor", exc_info=True)
|
209
|
-
instrumentors = {}
|
210
|
-
self.__spans_processor.shutdown()
|
211
|
-
|
212
|
-
# Clean up attributes
|
213
|
-
self.clear_state()
|
240
|
+
self.__tracer_provider.shutdown()
|
214
241
|
|
215
242
|
def flush(self):
|
216
243
|
return self.__spans_processor.force_flush()
|
@@ -285,9 +312,11 @@ def init_spans_exporter(api_endpoint: str, headers: Dict[str, str]) -> SpanExpor
|
|
285
312
|
)
|
286
313
|
|
287
314
|
|
315
|
+
# TODO: check if it's safer to use the default tracer provider obtained from
|
316
|
+
# get_tracer_provider()
|
288
317
|
def init_tracer_provider(resource: Resource) -> TracerProvider:
|
289
318
|
provider: TracerProvider = None
|
290
|
-
default_provider: TracerProvider =
|
319
|
+
default_provider: TracerProvider = get_tracer_provider()
|
291
320
|
|
292
321
|
if isinstance(default_provider, ProxyTracerProvider):
|
293
322
|
provider = TracerProvider(resource=resource)
|
@@ -307,9 +336,8 @@ def init_instrumentations(
|
|
307
336
|
should_enrich_metrics: bool,
|
308
337
|
instruments: Optional[Set[Instruments]] = None,
|
309
338
|
block_instruments: Optional[Set[Instruments]] = None,
|
310
|
-
|
311
|
-
|
312
|
-
base_http_url: Optional[str] = None,
|
339
|
+
client: Optional[LaminarClient] = None,
|
340
|
+
async_client: Optional[AsyncLaminarClient] = None,
|
313
341
|
):
|
314
342
|
block_instruments = block_instruments or set()
|
315
343
|
# These libraries are not instrumented by default,
|
@@ -335,109 +363,103 @@ def init_instrumentations(
|
|
335
363
|
instrument_set = False
|
336
364
|
for instrument in instruments:
|
337
365
|
if instrument == Instruments.ALEPHALPHA:
|
338
|
-
if init_alephalpha_instrumentor(
|
366
|
+
if init_alephalpha_instrumentor():
|
339
367
|
instrument_set = True
|
340
368
|
elif instrument == Instruments.ANTHROPIC:
|
341
|
-
if init_anthropic_instrumentor(
|
342
|
-
should_enrich_metrics, tracer_provider=tracer_provider
|
343
|
-
):
|
369
|
+
if init_anthropic_instrumentor(should_enrich_metrics):
|
344
370
|
instrument_set = True
|
345
371
|
elif instrument == Instruments.BEDROCK:
|
346
|
-
if init_bedrock_instrumentor(
|
347
|
-
should_enrich_metrics, tracer_provider=tracer_provider
|
348
|
-
):
|
372
|
+
if init_bedrock_instrumentor(should_enrich_metrics):
|
349
373
|
instrument_set = True
|
350
374
|
elif instrument == Instruments.CHROMA:
|
351
|
-
if init_chroma_instrumentor(
|
375
|
+
if init_chroma_instrumentor():
|
352
376
|
instrument_set = True
|
353
377
|
elif instrument == Instruments.COHERE:
|
354
|
-
if init_cohere_instrumentor(
|
378
|
+
if init_cohere_instrumentor():
|
355
379
|
instrument_set = True
|
356
380
|
elif instrument == Instruments.GOOGLE_GENERATIVEAI:
|
357
|
-
if init_google_generativeai_instrumentor(
|
381
|
+
if init_google_generativeai_instrumentor():
|
382
|
+
instrument_set = True
|
383
|
+
elif instrument == Instruments.GOOGLE_GENAI:
|
384
|
+
if init_google_genai_instrumentor():
|
358
385
|
instrument_set = True
|
359
386
|
elif instrument == Instruments.GROQ:
|
360
|
-
if init_groq_instrumentor(
|
387
|
+
if init_groq_instrumentor():
|
361
388
|
instrument_set = True
|
362
389
|
elif instrument == Instruments.HAYSTACK:
|
363
|
-
if init_haystack_instrumentor(
|
390
|
+
if init_haystack_instrumentor():
|
364
391
|
instrument_set = True
|
365
392
|
elif instrument == Instruments.LANCEDB:
|
366
|
-
if init_lancedb_instrumentor(
|
393
|
+
if init_lancedb_instrumentor():
|
367
394
|
instrument_set = True
|
368
395
|
elif instrument == Instruments.LANGCHAIN:
|
369
|
-
if init_langchain_instrumentor(
|
396
|
+
if init_langchain_instrumentor():
|
370
397
|
instrument_set = True
|
371
398
|
elif instrument == Instruments.LLAMA_INDEX:
|
372
|
-
if init_llama_index_instrumentor(
|
399
|
+
if init_llama_index_instrumentor():
|
373
400
|
instrument_set = True
|
374
401
|
elif instrument == Instruments.MARQO:
|
375
|
-
if init_marqo_instrumentor(
|
402
|
+
if init_marqo_instrumentor():
|
376
403
|
instrument_set = True
|
377
404
|
elif instrument == Instruments.MILVUS:
|
378
|
-
if init_milvus_instrumentor(
|
405
|
+
if init_milvus_instrumentor():
|
379
406
|
instrument_set = True
|
380
407
|
elif instrument == Instruments.MISTRAL:
|
381
|
-
if init_mistralai_instrumentor(
|
408
|
+
if init_mistralai_instrumentor():
|
382
409
|
instrument_set = True
|
383
410
|
elif instrument == Instruments.OLLAMA:
|
384
|
-
if init_ollama_instrumentor(
|
411
|
+
if init_ollama_instrumentor():
|
385
412
|
instrument_set = True
|
386
413
|
elif instrument == Instruments.OPENAI:
|
387
|
-
if init_openai_instrumentor(
|
388
|
-
should_enrich_metrics, tracer_provider=tracer_provider
|
389
|
-
):
|
414
|
+
if init_openai_instrumentor(should_enrich_metrics):
|
390
415
|
instrument_set = True
|
391
416
|
elif instrument == Instruments.PINECONE:
|
392
|
-
if init_pinecone_instrumentor(
|
417
|
+
if init_pinecone_instrumentor():
|
393
418
|
instrument_set = True
|
394
419
|
elif instrument == Instruments.PYMYSQL:
|
395
|
-
if init_pymysql_instrumentor(
|
420
|
+
if init_pymysql_instrumentor():
|
396
421
|
instrument_set = True
|
397
422
|
elif instrument == Instruments.QDRANT:
|
398
|
-
if init_qdrant_instrumentor(
|
423
|
+
if init_qdrant_instrumentor():
|
399
424
|
instrument_set = True
|
400
425
|
elif instrument == Instruments.REDIS:
|
401
|
-
if init_redis_instrumentor(
|
426
|
+
if init_redis_instrumentor():
|
402
427
|
instrument_set = True
|
403
428
|
elif instrument == Instruments.REPLICATE:
|
404
|
-
if init_replicate_instrumentor(
|
429
|
+
if init_replicate_instrumentor():
|
405
430
|
instrument_set = True
|
406
431
|
elif instrument == Instruments.REQUESTS:
|
407
|
-
if init_requests_instrumentor(
|
432
|
+
if init_requests_instrumentor():
|
408
433
|
instrument_set = True
|
409
434
|
elif instrument == Instruments.SAGEMAKER:
|
410
|
-
if init_sagemaker_instrumentor(
|
411
|
-
should_enrich_metrics, tracer_provider=tracer_provider
|
412
|
-
):
|
435
|
+
if init_sagemaker_instrumentor(should_enrich_metrics):
|
413
436
|
instrument_set = True
|
414
437
|
elif instrument == Instruments.TOGETHER:
|
415
|
-
if init_together_instrumentor(
|
438
|
+
if init_together_instrumentor():
|
416
439
|
instrument_set = True
|
417
440
|
elif instrument == Instruments.TRANSFORMERS:
|
418
|
-
if init_transformers_instrumentor(
|
441
|
+
if init_transformers_instrumentor():
|
419
442
|
instrument_set = True
|
420
443
|
elif instrument == Instruments.URLLIB3:
|
421
|
-
if init_urllib3_instrumentor(
|
444
|
+
if init_urllib3_instrumentor():
|
422
445
|
instrument_set = True
|
423
446
|
elif instrument == Instruments.VERTEXAI:
|
424
|
-
if init_vertexai_instrumentor(
|
447
|
+
if init_vertexai_instrumentor():
|
425
448
|
instrument_set = True
|
426
449
|
elif instrument == Instruments.WATSONX:
|
427
|
-
if init_watsonx_instrumentor(
|
450
|
+
if init_watsonx_instrumentor():
|
428
451
|
instrument_set = True
|
429
452
|
elif instrument == Instruments.WEAVIATE:
|
430
|
-
if init_weaviate_instrumentor(
|
453
|
+
if init_weaviate_instrumentor():
|
431
454
|
instrument_set = True
|
432
455
|
elif instrument == Instruments.PLAYWRIGHT:
|
433
|
-
if init_playwright_instrumentor(
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
):
|
456
|
+
if init_playwright_instrumentor(client, async_client):
|
457
|
+
instrument_set = True
|
458
|
+
elif instrument == Instruments.PATCHRIGHT:
|
459
|
+
if init_patchright_instrumentor(client, async_client):
|
438
460
|
instrument_set = True
|
439
461
|
elif instrument == Instruments.BROWSER_USE:
|
440
|
-
if init_browser_use_instrumentor(
|
462
|
+
if init_browser_use_instrumentor():
|
441
463
|
instrument_set = True
|
442
464
|
else:
|
443
465
|
module_logger.warning(
|
@@ -452,38 +474,50 @@ def init_instrumentations(
|
|
452
474
|
return instrument_set
|
453
475
|
|
454
476
|
|
455
|
-
def init_browser_use_instrumentor(
|
456
|
-
global instrumentors
|
477
|
+
def init_browser_use_instrumentor():
|
457
478
|
try:
|
458
479
|
if is_package_installed("browser-use"):
|
459
480
|
from lmnr.sdk.browser.browser_use_otel import BrowserUseInstrumentor
|
460
481
|
|
461
482
|
instrumentor = BrowserUseInstrumentor()
|
462
|
-
instrumentor.instrument(
|
463
|
-
instrumentors["browser_use"] = instrumentor
|
483
|
+
instrumentor.instrument()
|
464
484
|
return True
|
465
485
|
except Exception as e:
|
466
486
|
module_logger.error(f"Error initializing BrowserUse instrumentor: {e}")
|
467
487
|
return False
|
468
488
|
|
469
489
|
|
470
|
-
def init_playwright_instrumentor(
|
471
|
-
|
490
|
+
def init_playwright_instrumentor(
|
491
|
+
client: LaminarClient, async_client: AsyncLaminarClient
|
492
|
+
):
|
472
493
|
try:
|
473
494
|
if is_package_installed("playwright"):
|
474
495
|
from lmnr.sdk.browser.playwright_otel import PlaywrightInstrumentor
|
475
496
|
|
476
|
-
instrumentor = PlaywrightInstrumentor()
|
477
|
-
instrumentor.instrument(
|
478
|
-
instrumentors["playwright"] = instrumentor
|
497
|
+
instrumentor = PlaywrightInstrumentor(client, async_client)
|
498
|
+
instrumentor.instrument()
|
479
499
|
return True
|
480
500
|
except Exception as e:
|
481
501
|
module_logger.error(f"Error initializing Playwright instrumentor: {e}")
|
482
502
|
return False
|
483
503
|
|
484
504
|
|
485
|
-
def
|
486
|
-
|
505
|
+
def init_patchright_instrumentor(
|
506
|
+
client: LaminarClient, async_client: AsyncLaminarClient
|
507
|
+
):
|
508
|
+
try:
|
509
|
+
if is_package_installed("patchright"):
|
510
|
+
from lmnr.sdk.browser.patchright_otel import PatchrightInstrumentor
|
511
|
+
|
512
|
+
instrumentor = PatchrightInstrumentor(client, async_client)
|
513
|
+
instrumentor.instrument()
|
514
|
+
return True
|
515
|
+
except Exception as e:
|
516
|
+
module_logger.error(f"Error initializing patchright instrumentor: {e}")
|
517
|
+
return False
|
518
|
+
|
519
|
+
|
520
|
+
def init_openai_instrumentor(should_enrich_metrics: bool):
|
487
521
|
try:
|
488
522
|
if is_package_installed("openai") and is_package_installed(
|
489
523
|
"opentelemetry-instrumentation-openai"
|
@@ -499,8 +533,7 @@ def init_openai_instrumentor(should_enrich_metrics: bool, **kwargs):
|
|
499
533
|
upload_base64_image=None,
|
500
534
|
)
|
501
535
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
502
|
-
instrumentor.instrument(
|
503
|
-
instrumentors["openai"] = instrumentor
|
536
|
+
instrumentor.instrument()
|
504
537
|
return True
|
505
538
|
|
506
539
|
except Exception as e:
|
@@ -508,8 +541,7 @@ def init_openai_instrumentor(should_enrich_metrics: bool, **kwargs):
|
|
508
541
|
return False
|
509
542
|
|
510
543
|
|
511
|
-
def init_anthropic_instrumentor(should_enrich_metrics: bool
|
512
|
-
global instrumentors
|
544
|
+
def init_anthropic_instrumentor(should_enrich_metrics: bool):
|
513
545
|
try:
|
514
546
|
if is_package_installed("anthropic") and is_package_installed(
|
515
547
|
"opentelemetry-instrumentation-anthropic"
|
@@ -521,16 +553,14 @@ def init_anthropic_instrumentor(should_enrich_metrics: bool, **kwargs):
|
|
521
553
|
upload_base64_image=None,
|
522
554
|
)
|
523
555
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
524
|
-
instrumentor.instrument(
|
525
|
-
instrumentors["anthropic"] = instrumentor
|
556
|
+
instrumentor.instrument()
|
526
557
|
return True
|
527
558
|
except Exception as e:
|
528
559
|
module_logger.error(f"Error initializing Anthropic instrumentor: {e}")
|
529
560
|
return False
|
530
561
|
|
531
562
|
|
532
|
-
def init_cohere_instrumentor(
|
533
|
-
global instrumentors
|
563
|
+
def init_cohere_instrumentor():
|
534
564
|
try:
|
535
565
|
if is_package_installed("cohere") and is_package_installed(
|
536
566
|
"opentelemetry-instrumentation-cohere"
|
@@ -539,16 +569,14 @@ def init_cohere_instrumentor(**kwargs):
|
|
539
569
|
|
540
570
|
instrumentor = CohereInstrumentor()
|
541
571
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
542
|
-
instrumentor.instrument(
|
543
|
-
instrumentors["cohere"] = instrumentor
|
572
|
+
instrumentor.instrument()
|
544
573
|
return True
|
545
574
|
except Exception as e:
|
546
575
|
module_logger.error(f"Error initializing Cohere instrumentor: {e}")
|
547
576
|
return False
|
548
577
|
|
549
578
|
|
550
|
-
def init_pinecone_instrumentor(
|
551
|
-
global instrumentors
|
579
|
+
def init_pinecone_instrumentor():
|
552
580
|
try:
|
553
581
|
if is_package_installed("pinecone") and is_package_installed(
|
554
582
|
"opentelemetry-instrumentation-pinecone"
|
@@ -557,16 +585,14 @@ def init_pinecone_instrumentor(**kwargs):
|
|
557
585
|
|
558
586
|
instrumentor = PineconeInstrumentor()
|
559
587
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
560
|
-
instrumentor.instrument(
|
561
|
-
instrumentors["pinecone"] = instrumentor
|
588
|
+
instrumentor.instrument()
|
562
589
|
return True
|
563
590
|
except Exception as e:
|
564
591
|
module_logger.error(f"Error initializing Pinecone instrumentor: {e}")
|
565
592
|
return False
|
566
593
|
|
567
594
|
|
568
|
-
def init_qdrant_instrumentor(
|
569
|
-
global instrumentors
|
595
|
+
def init_qdrant_instrumentor():
|
570
596
|
try:
|
571
597
|
if is_package_installed("qdrant_client") and is_package_installed(
|
572
598
|
"opentelemetry-instrumentation-qdrant"
|
@@ -575,16 +601,13 @@ def init_qdrant_instrumentor(**kwargs):
|
|
575
601
|
|
576
602
|
instrumentor = QdrantInstrumentor()
|
577
603
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
578
|
-
instrumentor.instrument(
|
579
|
-
instrumentors["qdrant"] = instrumentor
|
580
|
-
return True
|
604
|
+
instrumentor.instrument()
|
581
605
|
except Exception as e:
|
582
606
|
module_logger.error(f"Error initializing Qdrant instrumentor: {e}")
|
583
607
|
return False
|
584
608
|
|
585
609
|
|
586
|
-
def init_chroma_instrumentor(
|
587
|
-
global instrumentors
|
610
|
+
def init_chroma_instrumentor():
|
588
611
|
try:
|
589
612
|
if is_package_installed("chromadb") and is_package_installed(
|
590
613
|
"opentelemetry-instrumentation-chromadb"
|
@@ -593,16 +616,14 @@ def init_chroma_instrumentor(**kwargs):
|
|
593
616
|
|
594
617
|
instrumentor = ChromaInstrumentor()
|
595
618
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
596
|
-
instrumentor.instrument(
|
597
|
-
instrumentors["chroma"] = instrumentor
|
619
|
+
instrumentor.instrument()
|
598
620
|
return True
|
599
621
|
except Exception as e:
|
600
622
|
module_logger.error(f"Error initializing Chroma instrumentor: {e}")
|
601
623
|
return False
|
602
624
|
|
603
625
|
|
604
|
-
def init_google_generativeai_instrumentor(
|
605
|
-
global instrumentors
|
626
|
+
def init_google_generativeai_instrumentor():
|
606
627
|
try:
|
607
628
|
if is_package_installed("google-generativeai") and is_package_installed(
|
608
629
|
"opentelemetry-instrumentation-google-generativeai"
|
@@ -613,16 +634,35 @@ def init_google_generativeai_instrumentor(**kwargs):
|
|
613
634
|
|
614
635
|
instrumentor = GoogleGenerativeAiInstrumentor()
|
615
636
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
616
|
-
instrumentor.instrument(
|
617
|
-
instrumentors["google_generativeai"] = instrumentor
|
637
|
+
instrumentor.instrument()
|
618
638
|
return True
|
619
639
|
except Exception as e:
|
620
640
|
module_logger.error(f"Error initializing Gemini instrumentor: {e}")
|
621
641
|
return False
|
622
642
|
|
623
643
|
|
624
|
-
def
|
625
|
-
|
644
|
+
def init_google_genai_instrumentor():
|
645
|
+
try:
|
646
|
+
if is_package_installed("google-genai"):
|
647
|
+
# TODO: uncomment this once we migrate to the contrib package
|
648
|
+
# and is_package_installed(
|
649
|
+
# "opentelemetry-instrumentation-google-genai"
|
650
|
+
# ):
|
651
|
+
# from opentelemetry.instrumentation.google_genai import (
|
652
|
+
from ..opentelemetry.instrumentation.google_genai import (
|
653
|
+
GoogleGenAiSdkInstrumentor,
|
654
|
+
)
|
655
|
+
|
656
|
+
instrumentor = GoogleGenAiSdkInstrumentor()
|
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 Google GenAI instrumentor: {e}")
|
662
|
+
return False
|
663
|
+
|
664
|
+
|
665
|
+
def init_haystack_instrumentor():
|
626
666
|
try:
|
627
667
|
if is_package_installed("haystack") and is_package_installed(
|
628
668
|
"opentelemetry-instrumentation-haystack"
|
@@ -631,16 +671,14 @@ def init_haystack_instrumentor(**kwargs):
|
|
631
671
|
|
632
672
|
instrumentor = HaystackInstrumentor()
|
633
673
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
634
|
-
instrumentor.instrument(
|
635
|
-
instrumentors["haystack"] = instrumentor
|
674
|
+
instrumentor.instrument()
|
636
675
|
return True
|
637
676
|
except Exception as e:
|
638
677
|
module_logger.error(f"Error initializing Haystack instrumentor: {e}")
|
639
678
|
return False
|
640
679
|
|
641
680
|
|
642
|
-
def init_langchain_instrumentor(
|
643
|
-
global instrumentors
|
681
|
+
def init_langchain_instrumentor():
|
644
682
|
try:
|
645
683
|
if is_package_installed("langchain") and is_package_installed(
|
646
684
|
"opentelemetry-instrumentation-langchain"
|
@@ -650,7 +688,6 @@ def init_langchain_instrumentor(**kwargs):
|
|
650
688
|
instrumentor = LangchainInstrumentor()
|
651
689
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
652
690
|
instrumentor.instrument()
|
653
|
-
instrumentors["langchain"] = instrumentor
|
654
691
|
return True
|
655
692
|
except Exception as e:
|
656
693
|
# FIXME: silencing this error temporarily, it appears to not be critical
|
@@ -659,8 +696,7 @@ def init_langchain_instrumentor(**kwargs):
|
|
659
696
|
return False
|
660
697
|
|
661
698
|
|
662
|
-
def init_mistralai_instrumentor(
|
663
|
-
global instrumentors
|
699
|
+
def init_mistralai_instrumentor():
|
664
700
|
try:
|
665
701
|
if is_package_installed("mistralai") and is_package_installed(
|
666
702
|
"opentelemetry-instrumentation-mistralai"
|
@@ -669,16 +705,14 @@ def init_mistralai_instrumentor(**kwargs):
|
|
669
705
|
|
670
706
|
instrumentor = MistralAiInstrumentor()
|
671
707
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
672
|
-
instrumentor.instrument(
|
673
|
-
instrumentors["mistralai"] = instrumentor
|
708
|
+
instrumentor.instrument()
|
674
709
|
return True
|
675
710
|
except Exception as e:
|
676
711
|
module_logger.error(f"Error initializing MistralAI instrumentor: {e}")
|
677
712
|
return False
|
678
713
|
|
679
714
|
|
680
|
-
def init_ollama_instrumentor(
|
681
|
-
global instrumentors
|
715
|
+
def init_ollama_instrumentor():
|
682
716
|
try:
|
683
717
|
if is_package_installed("ollama") and is_package_installed(
|
684
718
|
"opentelemetry-instrumentation-ollama"
|
@@ -687,16 +721,14 @@ def init_ollama_instrumentor(**kwargs):
|
|
687
721
|
|
688
722
|
instrumentor = OllamaInstrumentor()
|
689
723
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
690
|
-
instrumentor.instrument(
|
691
|
-
instrumentors["ollama"] = instrumentor
|
724
|
+
instrumentor.instrument()
|
692
725
|
return True
|
693
726
|
except Exception as e:
|
694
727
|
module_logger.error(f"Error initializing Ollama instrumentor: {e}")
|
695
728
|
return False
|
696
729
|
|
697
730
|
|
698
|
-
def init_transformers_instrumentor(
|
699
|
-
global instrumentors
|
731
|
+
def init_transformers_instrumentor():
|
700
732
|
try:
|
701
733
|
if is_package_installed("transformers") and is_package_installed(
|
702
734
|
"opentelemetry-instrumentation-transformers"
|
@@ -707,16 +739,14 @@ def init_transformers_instrumentor(**kwargs):
|
|
707
739
|
|
708
740
|
instrumentor = TransformersInstrumentor()
|
709
741
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
710
|
-
instrumentor.instrument(
|
711
|
-
instrumentors["transformers"] = instrumentor
|
742
|
+
instrumentor.instrument()
|
712
743
|
return True
|
713
744
|
except Exception as e:
|
714
745
|
module_logger.error(f"Error initializing Transformers instrumentor: {e}")
|
715
746
|
return False
|
716
747
|
|
717
748
|
|
718
|
-
def init_together_instrumentor(
|
719
|
-
global instrumentors
|
749
|
+
def init_together_instrumentor():
|
720
750
|
try:
|
721
751
|
if is_package_installed("together") and is_package_installed(
|
722
752
|
"opentelemetry-instrumentation-together"
|
@@ -725,16 +755,14 @@ def init_together_instrumentor(**kwargs):
|
|
725
755
|
|
726
756
|
instrumentor = TogetherAiInstrumentor()
|
727
757
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
728
|
-
instrumentor.instrument(
|
729
|
-
instrumentors["together"] = instrumentor
|
758
|
+
instrumentor.instrument()
|
730
759
|
return True
|
731
760
|
except Exception as e:
|
732
761
|
module_logger.error(f"Error initializing TogetherAI instrumentor: {e}")
|
733
762
|
return False
|
734
763
|
|
735
764
|
|
736
|
-
def init_llama_index_instrumentor(
|
737
|
-
global instrumentors
|
765
|
+
def init_llama_index_instrumentor():
|
738
766
|
try:
|
739
767
|
if (
|
740
768
|
is_package_installed("llama-index") or is_package_installed("llama_index")
|
@@ -743,16 +771,14 @@ def init_llama_index_instrumentor(**kwargs):
|
|
743
771
|
|
744
772
|
instrumentor = LlamaIndexInstrumentor()
|
745
773
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
746
|
-
instrumentor.instrument(
|
747
|
-
instrumentors["llama_index"] = instrumentor
|
774
|
+
instrumentor.instrument()
|
748
775
|
return True
|
749
776
|
except Exception as e:
|
750
777
|
module_logger.error(f"Error initializing LlamaIndex instrumentor: {e}")
|
751
778
|
return False
|
752
779
|
|
753
780
|
|
754
|
-
def init_milvus_instrumentor(
|
755
|
-
global instrumentors
|
781
|
+
def init_milvus_instrumentor():
|
756
782
|
try:
|
757
783
|
if is_package_installed("pymilvus") and is_package_installed(
|
758
784
|
"opentelemetry-instrumentation-milvus"
|
@@ -761,64 +787,56 @@ def init_milvus_instrumentor(**kwargs):
|
|
761
787
|
|
762
788
|
instrumentor = MilvusInstrumentor()
|
763
789
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
764
|
-
instrumentor.instrument(
|
765
|
-
instrumentors["milvus"] = instrumentor
|
790
|
+
instrumentor.instrument()
|
766
791
|
return True
|
767
792
|
except Exception as e:
|
768
793
|
module_logger.error(f"Error initializing Milvus instrumentor: {e}")
|
769
794
|
return False
|
770
795
|
|
771
796
|
|
772
|
-
def init_requests_instrumentor(
|
773
|
-
global instrumentors
|
797
|
+
def init_requests_instrumentor():
|
774
798
|
try:
|
775
799
|
if is_package_installed("requests"):
|
776
800
|
from opentelemetry.instrumentation.requests import RequestsInstrumentor
|
777
801
|
|
778
802
|
instrumentor = RequestsInstrumentor()
|
779
803
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
780
|
-
instrumentor.instrument(excluded_urls=EXCLUDED_URLS
|
781
|
-
instrumentors["requests"] = instrumentor
|
804
|
+
instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
|
782
805
|
return True
|
783
806
|
except Exception as e:
|
784
807
|
module_logger.error(f"Error initializing Requests instrumentor: {e}")
|
785
808
|
return False
|
786
809
|
|
787
810
|
|
788
|
-
def init_urllib3_instrumentor(
|
789
|
-
global instrumentors
|
811
|
+
def init_urllib3_instrumentor():
|
790
812
|
try:
|
791
813
|
if is_package_installed("urllib3"):
|
792
814
|
from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor
|
793
815
|
|
794
816
|
instrumentor = URLLib3Instrumentor()
|
795
817
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
796
|
-
instrumentor.instrument(excluded_urls=EXCLUDED_URLS
|
797
|
-
instrumentors["urllib3"] = instrumentor
|
818
|
+
instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
|
798
819
|
return True
|
799
820
|
except Exception as e:
|
800
821
|
module_logger.error(f"Error initializing urllib3 instrumentor: {e}")
|
801
822
|
return False
|
802
823
|
|
803
824
|
|
804
|
-
def init_pymysql_instrumentor(
|
805
|
-
global instrumentors
|
825
|
+
def init_pymysql_instrumentor():
|
806
826
|
try:
|
807
827
|
if is_package_installed("sqlalchemy"):
|
808
828
|
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
|
809
829
|
|
810
830
|
instrumentor = SQLAlchemyInstrumentor()
|
811
831
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
812
|
-
instrumentor.instrument(
|
813
|
-
instrumentors["sqlalchemy"] = instrumentor
|
832
|
+
instrumentor.instrument()
|
814
833
|
return True
|
815
834
|
except Exception as e:
|
816
835
|
module_logger.error(f"Error initializing SQLAlchemy instrumentor: {e}")
|
817
836
|
return False
|
818
837
|
|
819
838
|
|
820
|
-
def init_bedrock_instrumentor(should_enrich_metrics: bool
|
821
|
-
global instrumentors
|
839
|
+
def init_bedrock_instrumentor(should_enrich_metrics: bool):
|
822
840
|
try:
|
823
841
|
if is_package_installed("boto3") and is_package_installed(
|
824
842
|
"opentelemetry-instrumentation-bedrock"
|
@@ -829,16 +847,14 @@ def init_bedrock_instrumentor(should_enrich_metrics: bool, **kwargs):
|
|
829
847
|
enrich_token_usage=should_enrich_metrics,
|
830
848
|
)
|
831
849
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
832
|
-
instrumentor.instrument(
|
833
|
-
instrumentors["bedrock"] = instrumentor
|
850
|
+
instrumentor.instrument()
|
834
851
|
return True
|
835
852
|
except Exception as e:
|
836
853
|
module_logger.error(f"Error initializing Bedrock instrumentor: {e}")
|
837
854
|
return False
|
838
855
|
|
839
856
|
|
840
|
-
def init_replicate_instrumentor(
|
841
|
-
global instrumentors
|
857
|
+
def init_replicate_instrumentor():
|
842
858
|
try:
|
843
859
|
if is_package_installed("replicate") and is_package_installed(
|
844
860
|
"opentelemetry-instrumentation-replicate"
|
@@ -847,16 +863,14 @@ def init_replicate_instrumentor(**kwargs):
|
|
847
863
|
|
848
864
|
instrumentor = ReplicateInstrumentor()
|
849
865
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
850
|
-
instrumentor.instrument(
|
851
|
-
instrumentors["replicate"] = instrumentor
|
866
|
+
instrumentor.instrument()
|
852
867
|
return True
|
853
868
|
except Exception as e:
|
854
869
|
module_logger.error(f"Error initializing Replicate instrumentor: {e}")
|
855
870
|
return False
|
856
871
|
|
857
872
|
|
858
|
-
def init_vertexai_instrumentor(
|
859
|
-
global instrumentors
|
873
|
+
def init_vertexai_instrumentor():
|
860
874
|
try:
|
861
875
|
if is_package_installed("vertexai") and is_package_installed(
|
862
876
|
"opentelemetry-instrumentation-vertexai"
|
@@ -865,16 +879,14 @@ def init_vertexai_instrumentor(**kwargs):
|
|
865
879
|
|
866
880
|
instrumentor = VertexAIInstrumentor()
|
867
881
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
868
|
-
instrumentor.instrument(
|
869
|
-
instrumentors["vertexai"] = instrumentor
|
882
|
+
instrumentor.instrument()
|
870
883
|
return True
|
871
884
|
except Exception as e:
|
872
885
|
module_logger.warning(f"Error initializing Vertex AI instrumentor: {e}")
|
873
886
|
return False
|
874
887
|
|
875
888
|
|
876
|
-
def init_watsonx_instrumentor(
|
877
|
-
global instrumentors
|
889
|
+
def init_watsonx_instrumentor():
|
878
890
|
try:
|
879
891
|
if (
|
880
892
|
is_package_installed("ibm-watsonx-ai")
|
@@ -884,16 +896,14 @@ def init_watsonx_instrumentor(**kwargs):
|
|
884
896
|
|
885
897
|
instrumentor = WatsonxInstrumentor()
|
886
898
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
887
|
-
instrumentor.instrument(
|
888
|
-
instrumentors["watsonx"] = instrumentor
|
899
|
+
instrumentor.instrument()
|
889
900
|
return True
|
890
901
|
except Exception as e:
|
891
902
|
module_logger.warning(f"Error initializing Watsonx instrumentor: {e}")
|
892
903
|
return False
|
893
904
|
|
894
905
|
|
895
|
-
def init_weaviate_instrumentor(
|
896
|
-
global instrumentors
|
906
|
+
def init_weaviate_instrumentor():
|
897
907
|
try:
|
898
908
|
if is_package_installed("weaviate") and is_package_installed(
|
899
909
|
"opentelemetry-instrumentation-weaviate"
|
@@ -902,16 +912,14 @@ def init_weaviate_instrumentor(**kwargs):
|
|
902
912
|
|
903
913
|
instrumentor = WeaviateInstrumentor()
|
904
914
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
905
|
-
instrumentor.instrument(
|
906
|
-
instrumentors["weaviate"] = instrumentor
|
915
|
+
instrumentor.instrument()
|
907
916
|
return True
|
908
917
|
except Exception as e:
|
909
918
|
module_logger.warning(f"Error initializing Weaviate instrumentor: {e}")
|
910
919
|
return False
|
911
920
|
|
912
921
|
|
913
|
-
def init_alephalpha_instrumentor(
|
914
|
-
global instrumentors
|
922
|
+
def init_alephalpha_instrumentor():
|
915
923
|
try:
|
916
924
|
if is_package_installed("aleph_alpha_client") and is_package_installed(
|
917
925
|
"opentelemetry-instrumentation-alephalpha"
|
@@ -920,16 +928,14 @@ def init_alephalpha_instrumentor(**kwargs):
|
|
920
928
|
|
921
929
|
instrumentor = AlephAlphaInstrumentor()
|
922
930
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
923
|
-
instrumentor.instrument(
|
924
|
-
instrumentors["alephalpha"] = instrumentor
|
931
|
+
instrumentor.instrument()
|
925
932
|
return True
|
926
933
|
except Exception as e:
|
927
934
|
module_logger.error(f"Error initializing Aleph Alpha instrumentor: {e}")
|
928
935
|
return False
|
929
936
|
|
930
937
|
|
931
|
-
def init_marqo_instrumentor(
|
932
|
-
global instrumentors
|
938
|
+
def init_marqo_instrumentor():
|
933
939
|
try:
|
934
940
|
if is_package_installed("marqo") and is_package_installed(
|
935
941
|
"opentelemetry-instrumentation-marqo"
|
@@ -938,16 +944,14 @@ def init_marqo_instrumentor(**kwargs):
|
|
938
944
|
|
939
945
|
instrumentor = MarqoInstrumentor()
|
940
946
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
941
|
-
instrumentor.instrument(
|
942
|
-
instrumentors["marqo"] = instrumentor
|
947
|
+
instrumentor.instrument()
|
943
948
|
return True
|
944
949
|
except Exception as e:
|
945
950
|
module_logger.error(f"Error initializing marqo instrumentor: {e}")
|
946
951
|
return False
|
947
952
|
|
948
953
|
|
949
|
-
def init_lancedb_instrumentor(
|
950
|
-
global instrumentors
|
954
|
+
def init_lancedb_instrumentor():
|
951
955
|
try:
|
952
956
|
if is_package_installed("lancedb") and is_package_installed(
|
953
957
|
"opentelemetry-instrumentation-lancedb"
|
@@ -956,16 +960,13 @@ def init_lancedb_instrumentor(**kwargs):
|
|
956
960
|
|
957
961
|
instrumentor = LanceInstrumentor()
|
958
962
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
959
|
-
instrumentor.instrument(
|
960
|
-
instrumentors["lancedb"] = instrumentor
|
963
|
+
instrumentor.instrument()
|
961
964
|
return True
|
962
965
|
except Exception as e:
|
963
966
|
module_logger.error(f"Error initializing LanceDB instrumentor: {e}")
|
964
|
-
return False
|
965
967
|
|
966
968
|
|
967
|
-
def init_redis_instrumentor(
|
968
|
-
global instrumentors
|
969
|
+
def init_redis_instrumentor():
|
969
970
|
try:
|
970
971
|
if is_package_installed("redis") and is_package_installed(
|
971
972
|
"opentelemetry-instrumentation-redis"
|
@@ -974,16 +975,14 @@ def init_redis_instrumentor(**kwargs):
|
|
974
975
|
|
975
976
|
instrumentor = RedisInstrumentor()
|
976
977
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
977
|
-
instrumentor.instrument(excluded_urls=EXCLUDED_URLS
|
978
|
-
instrumentors["redis"] = instrumentor
|
978
|
+
instrumentor.instrument(excluded_urls=EXCLUDED_URLS)
|
979
979
|
return True
|
980
980
|
except Exception as e:
|
981
981
|
module_logger.error(f"Error initializing redis instrumentor: {e}")
|
982
982
|
return False
|
983
983
|
|
984
984
|
|
985
|
-
def init_groq_instrumentor(
|
986
|
-
global instrumentors
|
985
|
+
def init_groq_instrumentor():
|
987
986
|
try:
|
988
987
|
if is_package_installed("groq") and is_package_installed(
|
989
988
|
"opentelemetry-instrumentation-groq"
|
@@ -992,16 +991,14 @@ def init_groq_instrumentor(**kwargs):
|
|
992
991
|
|
993
992
|
instrumentor = GroqInstrumentor()
|
994
993
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
995
|
-
instrumentor.instrument(
|
996
|
-
instrumentors["groq"] = instrumentor
|
994
|
+
instrumentor.instrument()
|
997
995
|
return True
|
998
996
|
except Exception as e:
|
999
997
|
module_logger.error(f"Error initializing Groq instrumentor: {e}")
|
1000
998
|
return False
|
1001
999
|
|
1002
1000
|
|
1003
|
-
def init_sagemaker_instrumentor(should_enrich_metrics: bool
|
1004
|
-
global instrumentors
|
1001
|
+
def init_sagemaker_instrumentor(should_enrich_metrics: bool):
|
1005
1002
|
try:
|
1006
1003
|
if is_package_installed("boto3") and is_package_installed(
|
1007
1004
|
"opentelemetry-instrumentation-sagemaker"
|
@@ -1012,8 +1009,7 @@ def init_sagemaker_instrumentor(should_enrich_metrics: bool, **kwargs):
|
|
1012
1009
|
enrich_token_usage=should_enrich_metrics,
|
1013
1010
|
)
|
1014
1011
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
1015
|
-
instrumentor.instrument(
|
1016
|
-
instrumentors["sagemaker"] = instrumentor
|
1012
|
+
instrumentor.instrument()
|
1017
1013
|
return True
|
1018
1014
|
except Exception as e:
|
1019
1015
|
module_logger.error(f"Error initializing SageMaker instrumentor: {e}")
|