lmnr 0.5.1__py3-none-any.whl → 0.5.1a0__py3-none-any.whl

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