lmnr 0.4.27__py3-none-any.whl → 0.4.29__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 +8 -1
- lmnr/sdk/datasets.py +1 -1
- lmnr/sdk/evaluations.py +33 -12
- lmnr/sdk/laminar.py +66 -1
- lmnr/sdk/types.py +34 -20
- lmnr/sdk/utils.py +5 -5
- lmnr/traceloop_sdk/instruments.py +15 -11
- lmnr/traceloop_sdk/tracing/attributes.py +1 -0
- lmnr/traceloop_sdk/tracing/tracing.py +185 -265
- {lmnr-0.4.27.dist-info → lmnr-0.4.29.dist-info}/METADATA +2 -1
- {lmnr-0.4.27.dist-info → lmnr-0.4.29.dist-info}/RECORD +14 -14
- {lmnr-0.4.27.dist-info → lmnr-0.4.29.dist-info}/LICENSE +0 -0
- {lmnr-0.4.27.dist-info → lmnr-0.4.29.dist-info}/WHEEL +0 -0
- {lmnr-0.4.27.dist-info → lmnr-0.4.29.dist-info}/entry_points.txt +0 -0
@@ -23,9 +23,12 @@ from opentelemetry.trace import get_tracer_provider, ProxyTracerProvider
|
|
23
23
|
from opentelemetry.context import get_value, attach, set_value
|
24
24
|
from opentelemetry.instrumentation.threading import ThreadingInstrumentor
|
25
25
|
|
26
|
-
# from lmnr.traceloop_sdk import Telemetry
|
27
26
|
from lmnr.traceloop_sdk.instruments import Instruments
|
28
|
-
from lmnr.traceloop_sdk.tracing.attributes import
|
27
|
+
from lmnr.traceloop_sdk.tracing.attributes import (
|
28
|
+
ASSOCIATION_PROPERTIES,
|
29
|
+
SPAN_INSTRUMENTATION_SOURCE,
|
30
|
+
SPAN_PATH,
|
31
|
+
)
|
29
32
|
from lmnr.traceloop_sdk.tracing.content_allow_list import ContentAllowList
|
30
33
|
from lmnr.traceloop_sdk.utils import is_notebook
|
31
34
|
from lmnr.traceloop_sdk.utils.package_check import is_package_installed
|
@@ -46,6 +49,7 @@ EXCLUDED_URLS = """
|
|
46
49
|
posthog.com,
|
47
50
|
sentry.io,
|
48
51
|
bedrock-runtime,
|
52
|
+
sagemaker-runtime,
|
49
53
|
googleapis.com,
|
50
54
|
githubusercontent.com,
|
51
55
|
openaipublic.blob.core.windows.net"""
|
@@ -75,27 +79,9 @@ class TracerWrapper(object):
|
|
75
79
|
obj.__resource = Resource(attributes=TracerWrapper.resource_attributes)
|
76
80
|
obj.__tracer_provider = init_tracer_provider(resource=obj.__resource)
|
77
81
|
if processor:
|
78
|
-
# Telemetry().capture("tracer:init", {"processor": "custom"})
|
79
82
|
obj.__spans_processor: SpanProcessor = processor
|
80
83
|
obj.__spans_processor_original_on_start = processor.on_start
|
81
84
|
else:
|
82
|
-
# if exporter:
|
83
|
-
# Telemetry().capture(
|
84
|
-
# "tracer:init",
|
85
|
-
# {
|
86
|
-
# "exporter": "custom",
|
87
|
-
# "processor": "simple" if disable_batch else "batch",
|
88
|
-
# },
|
89
|
-
# )
|
90
|
-
# else:
|
91
|
-
# Telemetry().capture(
|
92
|
-
# "tracer:init",
|
93
|
-
# {
|
94
|
-
# "exporter": TracerWrapper.endpoint,
|
95
|
-
# "processor": "simple" if disable_batch else "batch",
|
96
|
-
# },
|
97
|
-
# )
|
98
|
-
|
99
85
|
obj.__spans_exporter: SpanExporter = (
|
100
86
|
exporter
|
101
87
|
if exporter
|
@@ -122,99 +108,16 @@ class TracerWrapper(object):
|
|
122
108
|
# this makes sure otel context is propagated so we always want it
|
123
109
|
ThreadingInstrumentor().instrument()
|
124
110
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
elif instrument == Instruments.COHERE:
|
136
|
-
if not init_cohere_instrumentor():
|
137
|
-
print("Warning: Cohere library does not exist.")
|
138
|
-
elif instrument == Instruments.PINECONE:
|
139
|
-
if not init_pinecone_instrumentor():
|
140
|
-
print("Warning: Pinecone library does not exist.")
|
141
|
-
elif instrument == Instruments.CHROMA:
|
142
|
-
if not init_chroma_instrumentor():
|
143
|
-
print("Warning: Chroma library does not exist.")
|
144
|
-
elif instrument == Instruments.GOOGLE_GENERATIVEAI:
|
145
|
-
if not init_google_generativeai_instrumentor():
|
146
|
-
print(
|
147
|
-
"Warning: Google Generative AI library does not exist."
|
148
|
-
)
|
149
|
-
elif instrument == Instruments.LANGCHAIN:
|
150
|
-
if not init_langchain_instrumentor():
|
151
|
-
print("Warning: LangChain library does not exist.")
|
152
|
-
elif instrument == Instruments.MISTRAL:
|
153
|
-
if not init_mistralai_instrumentor():
|
154
|
-
print("Warning: MistralAI library does not exist.")
|
155
|
-
elif instrument == Instruments.OLLAMA:
|
156
|
-
if not init_ollama_instrumentor():
|
157
|
-
print("Warning: Ollama library does not exist.")
|
158
|
-
elif instrument == Instruments.LLAMA_INDEX:
|
159
|
-
if not init_llama_index_instrumentor():
|
160
|
-
print("Warning: LlamaIndex library does not exist.")
|
161
|
-
elif instrument == Instruments.MILVUS:
|
162
|
-
if not init_milvus_instrumentor():
|
163
|
-
print("Warning: Milvus library does not exist.")
|
164
|
-
elif instrument == Instruments.TRANSFORMERS:
|
165
|
-
if not init_transformers_instrumentor():
|
166
|
-
print("Warning: Transformers library does not exist.")
|
167
|
-
elif instrument == Instruments.TOGETHER:
|
168
|
-
if not init_together_instrumentor():
|
169
|
-
print("Warning: TogetherAI library does not exist.")
|
170
|
-
elif instrument == Instruments.REQUESTS:
|
171
|
-
if not init_requests_instrumentor():
|
172
|
-
print("Warning: Requests library does not exist.")
|
173
|
-
elif instrument == Instruments.URLLIB3:
|
174
|
-
if not init_urllib3_instrumentor():
|
175
|
-
print("Warning: urllib3 library does not exist.")
|
176
|
-
elif instrument == Instruments.PYMYSQL:
|
177
|
-
if not init_pymysql_instrumentor():
|
178
|
-
print("Warning: PyMySQL library does not exist.")
|
179
|
-
elif instrument == Instruments.BEDROCK:
|
180
|
-
if not init_bedrock_instrumentor(should_enrich_metrics):
|
181
|
-
print("Warning: Bedrock library does not exist.")
|
182
|
-
elif instrument == Instruments.REPLICATE:
|
183
|
-
if not init_replicate_instrumentor():
|
184
|
-
print("Warning: Replicate library does not exist.")
|
185
|
-
elif instrument == Instruments.VERTEXAI:
|
186
|
-
if not init_vertexai_instrumentor():
|
187
|
-
print("Warning: Vertex AI library does not exist.")
|
188
|
-
elif instrument == Instruments.WATSONX:
|
189
|
-
if not init_watsonx_instrumentor():
|
190
|
-
print("Warning: Watsonx library does not exist.")
|
191
|
-
elif instrument == Instruments.WEAVIATE:
|
192
|
-
if not init_weaviate_instrumentor():
|
193
|
-
print("Warning: Weaviate library does not exist.")
|
194
|
-
elif instrument == Instruments.ALEPHALPHA:
|
195
|
-
if not init_alephalpha_instrumentor():
|
196
|
-
print("Warning: Aleph Alpha library does not exist.")
|
197
|
-
elif instrument == Instruments.MARQO:
|
198
|
-
if not init_marqo_instrumentor():
|
199
|
-
print("Warning: marqo library does not exist.")
|
200
|
-
elif instrument == Instruments.LANCEDB:
|
201
|
-
if not init_lancedb_instrumentor():
|
202
|
-
print("Warning: LanceDB library does not exist.")
|
203
|
-
elif instrument == Instruments.REDIS:
|
204
|
-
if not init_redis_instrumentor():
|
205
|
-
print("Warning: redis library does not exist.")
|
206
|
-
|
207
|
-
else:
|
208
|
-
print(
|
209
|
-
"Warning: "
|
210
|
-
+ instrument
|
211
|
-
+ " instrumentation does not exist."
|
212
|
-
)
|
213
|
-
print(
|
214
|
-
"Usage:\n"
|
215
|
-
+ "from lmnr.traceloop_sdk.instruments import Instruments\n"
|
216
|
-
+ 'Traceloop.init(app_name="...", instruments=set([Instruments.OPENAI]))'
|
217
|
-
)
|
111
|
+
instrument_set = init_instrumentations(
|
112
|
+
should_enrich_metrics,
|
113
|
+
instruments,
|
114
|
+
)
|
115
|
+
|
116
|
+
if not instrument_set:
|
117
|
+
logging.warning(
|
118
|
+
"Warning: No valid instruments set. Remove 'instrument' "
|
119
|
+
"argument to use all instruments, or set a valid instrument."
|
120
|
+
)
|
218
121
|
|
219
122
|
obj.__content_allow_list = ContentAllowList()
|
220
123
|
|
@@ -235,6 +138,8 @@ class TracerWrapper(object):
|
|
235
138
|
# the final part of the name to the span on the backend.
|
236
139
|
span.set_attribute(SPAN_PATH, span_path)
|
237
140
|
|
141
|
+
span.set_attribute(SPAN_INSTRUMENTATION_SOURCE, "python")
|
142
|
+
|
238
143
|
association_properties = get_value("association_properties")
|
239
144
|
if association_properties is not None:
|
240
145
|
_set_association_properties_attributes(span, association_properties)
|
@@ -266,10 +171,7 @@ class TracerWrapper(object):
|
|
266
171
|
if hasattr(cls, "instance"):
|
267
172
|
return True
|
268
173
|
|
269
|
-
|
270
|
-
return False
|
271
|
-
|
272
|
-
print("Warning: Laminar not initialized, make sure to initialize")
|
174
|
+
logging.warning("Warning: Laminar not initialized, make sure to initialize")
|
273
175
|
return False
|
274
176
|
|
275
177
|
def flush(self):
|
@@ -361,47 +263,140 @@ def init_tracer_provider(resource: Resource) -> TracerProvider:
|
|
361
263
|
return provider
|
362
264
|
|
363
265
|
|
364
|
-
def init_instrumentations(
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
266
|
+
def init_instrumentations(
|
267
|
+
should_enrich_metrics: bool,
|
268
|
+
instruments: Optional[Set[Instruments]] = None,
|
269
|
+
block_instruments: Optional[Set[Instruments]] = None,
|
270
|
+
):
|
271
|
+
block_instruments = block_instruments or set()
|
272
|
+
# These libraries are not instrumented by default,
|
273
|
+
# but if the user wants, they can manually specify them
|
274
|
+
default_off_instruments = set(
|
275
|
+
[
|
276
|
+
Instruments.REQUESTS,
|
277
|
+
Instruments.URLLIB3,
|
278
|
+
Instruments.REDIS,
|
279
|
+
Instruments.PYMYSQL,
|
280
|
+
]
|
281
|
+
)
|
282
|
+
|
283
|
+
instruments = instruments or (set(Instruments) - default_off_instruments)
|
284
|
+
|
285
|
+
# Remove any instruments that were explicitly blocked
|
286
|
+
instruments = instruments - block_instruments
|
287
|
+
|
288
|
+
instrument_set = False
|
289
|
+
for instrument in instruments:
|
290
|
+
if instrument == Instruments.ALEPHALPHA:
|
291
|
+
if init_alephalpha_instrumentor():
|
292
|
+
instrument_set = True
|
293
|
+
elif instrument == Instruments.ANTHROPIC:
|
294
|
+
if init_anthropic_instrumentor(should_enrich_metrics):
|
295
|
+
instrument_set = True
|
296
|
+
elif instrument == Instruments.BEDROCK:
|
297
|
+
if init_bedrock_instrumentor(should_enrich_metrics):
|
298
|
+
instrument_set = True
|
299
|
+
elif instrument == Instruments.CHROMA:
|
300
|
+
if init_chroma_instrumentor():
|
301
|
+
instrument_set = True
|
302
|
+
elif instrument == Instruments.COHERE:
|
303
|
+
if init_cohere_instrumentor():
|
304
|
+
instrument_set = True
|
305
|
+
elif instrument == Instruments.GOOGLE_GENERATIVEAI:
|
306
|
+
if init_google_generativeai_instrumentor():
|
307
|
+
instrument_set = True
|
308
|
+
elif instrument == Instruments.GROQ:
|
309
|
+
if init_groq_instrumentor():
|
310
|
+
instrument_set = True
|
311
|
+
elif instrument == Instruments.HAYSTACK:
|
312
|
+
if init_haystack_instrumentor():
|
313
|
+
instrument_set = True
|
314
|
+
elif instrument == Instruments.LANCEDB:
|
315
|
+
if init_lancedb_instrumentor():
|
316
|
+
instrument_set = True
|
317
|
+
elif instrument == Instruments.LANGCHAIN:
|
318
|
+
if init_langchain_instrumentor():
|
319
|
+
instrument_set = True
|
320
|
+
elif instrument == Instruments.LLAMA_INDEX:
|
321
|
+
if init_llama_index_instrumentor():
|
322
|
+
instrument_set = True
|
323
|
+
elif instrument == Instruments.MARQO:
|
324
|
+
if init_marqo_instrumentor():
|
325
|
+
instrument_set = True
|
326
|
+
elif instrument == Instruments.MILVUS:
|
327
|
+
if init_milvus_instrumentor():
|
328
|
+
instrument_set = True
|
329
|
+
elif instrument == Instruments.MISTRAL:
|
330
|
+
if init_mistralai_instrumentor():
|
331
|
+
instrument_set = True
|
332
|
+
elif instrument == Instruments.OLLAMA:
|
333
|
+
if init_ollama_instrumentor():
|
334
|
+
instrument_set = True
|
335
|
+
elif instrument == Instruments.OPENAI:
|
336
|
+
if init_openai_instrumentor(should_enrich_metrics):
|
337
|
+
instrument_set = True
|
338
|
+
elif instrument == Instruments.PINECONE:
|
339
|
+
if init_pinecone_instrumentor():
|
340
|
+
instrument_set = True
|
341
|
+
elif instrument == Instruments.PYMYSQL:
|
342
|
+
if init_pymysql_instrumentor():
|
343
|
+
instrument_set = True
|
344
|
+
elif instrument == Instruments.QDRANT:
|
345
|
+
if init_qdrant_instrumentor():
|
346
|
+
instrument_set = True
|
347
|
+
elif instrument == Instruments.REDIS:
|
348
|
+
if init_redis_instrumentor():
|
349
|
+
instrument_set = True
|
350
|
+
elif instrument == Instruments.REPLICATE:
|
351
|
+
if init_replicate_instrumentor():
|
352
|
+
instrument_set = True
|
353
|
+
elif instrument == Instruments.REQUESTS:
|
354
|
+
if init_requests_instrumentor():
|
355
|
+
instrument_set = True
|
356
|
+
elif instrument == Instruments.SAGEMAKER:
|
357
|
+
if init_sagemaker_instrumentor(should_enrich_metrics):
|
358
|
+
instrument_set = True
|
359
|
+
elif instrument == Instruments.TOGETHER:
|
360
|
+
if init_together_instrumentor():
|
361
|
+
instrument_set = True
|
362
|
+
elif instrument == Instruments.TRANSFORMERS:
|
363
|
+
if init_transformers_instrumentor():
|
364
|
+
instrument_set = True
|
365
|
+
elif instrument == Instruments.URLLIB3:
|
366
|
+
if init_urllib3_instrumentor():
|
367
|
+
instrument_set = True
|
368
|
+
elif instrument == Instruments.VERTEXAI:
|
369
|
+
if init_vertexai_instrumentor():
|
370
|
+
instrument_set = True
|
371
|
+
elif instrument == Instruments.WATSONX:
|
372
|
+
if init_watsonx_instrumentor():
|
373
|
+
instrument_set = True
|
374
|
+
elif instrument == Instruments.WEAVIATE:
|
375
|
+
if init_weaviate_instrumentor():
|
376
|
+
instrument_set = True
|
377
|
+
else:
|
378
|
+
logging.warning(f"Warning: {instrument} instrumentation does not exist.")
|
379
|
+
logging.warning(
|
380
|
+
"Usage:\n"
|
381
|
+
"from lmnr import Laminar, Instruments\n"
|
382
|
+
"Laminar.init(instruments=set([Instruments.OPENAI]))"
|
383
|
+
)
|
384
|
+
|
385
|
+
if not instrument_set:
|
386
|
+
logging.warning(
|
387
|
+
"Warning: No valid instruments set. "
|
388
|
+
+ "Specify instruments or remove 'instruments' argument to use all instruments."
|
389
|
+
)
|
390
|
+
|
391
|
+
return instrument_set
|
395
392
|
|
396
393
|
|
397
394
|
def init_openai_instrumentor(should_enrich_metrics: bool):
|
398
395
|
try:
|
399
396
|
if is_package_installed("openai"):
|
400
|
-
# Telemetry().capture("instrumentation:openai:init")
|
401
397
|
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
|
402
398
|
|
403
399
|
instrumentor = OpenAIInstrumentor(
|
404
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
405
400
|
enrich_assistant=should_enrich_metrics,
|
406
401
|
enrich_token_usage=should_enrich_metrics,
|
407
402
|
)
|
@@ -411,18 +406,15 @@ def init_openai_instrumentor(should_enrich_metrics: bool):
|
|
411
406
|
|
412
407
|
except Exception as e:
|
413
408
|
logging.error(f"Error initializing OpenAI instrumentor: {e}")
|
414
|
-
# Telemetry().log_exception(e)
|
415
409
|
return False
|
416
410
|
|
417
411
|
|
418
412
|
def init_anthropic_instrumentor(should_enrich_metrics: bool):
|
419
413
|
try:
|
420
414
|
if is_package_installed("anthropic"):
|
421
|
-
# Telemetry().capture("instrumentation:anthropic:init")
|
422
415
|
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
|
423
416
|
|
424
417
|
instrumentor = AnthropicInstrumentor(
|
425
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
426
418
|
enrich_token_usage=should_enrich_metrics,
|
427
419
|
upload_base64_image=None,
|
428
420
|
)
|
@@ -431,244 +423,193 @@ def init_anthropic_instrumentor(should_enrich_metrics: bool):
|
|
431
423
|
return True
|
432
424
|
except Exception as e:
|
433
425
|
logging.error(f"Error initializing Anthropic instrumentor: {e}")
|
434
|
-
# Telemetry().log_exception(e)
|
435
426
|
return False
|
436
427
|
|
437
428
|
|
438
429
|
def init_cohere_instrumentor():
|
439
430
|
try:
|
440
431
|
if is_package_installed("cohere"):
|
441
|
-
# Telemetry().capture("instrumentation:cohere:init")
|
442
432
|
from opentelemetry.instrumentation.cohere import CohereInstrumentor
|
443
433
|
|
444
|
-
instrumentor = CohereInstrumentor(
|
445
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
446
|
-
)
|
434
|
+
instrumentor = CohereInstrumentor()
|
447
435
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
448
436
|
instrumentor.instrument()
|
449
437
|
return True
|
450
438
|
except Exception as e:
|
451
439
|
logging.error(f"Error initializing Cohere instrumentor: {e}")
|
452
|
-
# Telemetry().log_exception(e)
|
453
440
|
return False
|
454
441
|
|
455
442
|
|
456
443
|
def init_pinecone_instrumentor():
|
457
444
|
try:
|
458
445
|
if is_package_installed("pinecone"):
|
459
|
-
# Telemetry().capture("instrumentation:pinecone:init")
|
460
446
|
from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
|
461
447
|
|
462
|
-
instrumentor = PineconeInstrumentor(
|
463
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
464
|
-
)
|
448
|
+
instrumentor = PineconeInstrumentor()
|
465
449
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
466
450
|
instrumentor.instrument()
|
467
451
|
return True
|
468
452
|
except Exception as e:
|
469
453
|
logging.error(f"Error initializing Pinecone instrumentor: {e}")
|
470
|
-
# Telemetry().log_exception(e)
|
471
454
|
return False
|
472
455
|
|
473
456
|
|
474
457
|
def init_qdrant_instrumentor():
|
475
458
|
try:
|
476
459
|
if is_package_installed("qdrant_client"):
|
477
|
-
# Telemetry().capture("instrumentation:qdrant:init")
|
478
460
|
from opentelemetry.instrumentation.qdrant import QdrantInstrumentor
|
479
461
|
|
480
|
-
instrumentor = QdrantInstrumentor(
|
481
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
482
|
-
)
|
462
|
+
instrumentor = QdrantInstrumentor()
|
483
463
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
484
464
|
instrumentor.instrument()
|
485
465
|
except Exception as e:
|
486
466
|
logging.error(f"Error initializing Qdrant instrumentor: {e}")
|
487
|
-
# Telemetry().log_exception(e)
|
488
467
|
return False
|
489
468
|
|
490
469
|
|
491
470
|
def init_chroma_instrumentor():
|
492
471
|
try:
|
493
472
|
if is_package_installed("chromadb"):
|
494
|
-
# Telemetry().capture("instrumentation:chromadb:init")
|
495
473
|
from opentelemetry.instrumentation.chromadb import ChromaInstrumentor
|
496
474
|
|
497
|
-
instrumentor = ChromaInstrumentor(
|
498
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
499
|
-
)
|
475
|
+
instrumentor = ChromaInstrumentor()
|
500
476
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
501
477
|
instrumentor.instrument()
|
502
478
|
return True
|
503
479
|
except Exception as e:
|
504
480
|
logging.error(f"Error initializing Chroma instrumentor: {e}")
|
505
|
-
# Telemetry().log_exception(e)
|
506
481
|
return False
|
507
482
|
|
508
483
|
|
509
484
|
def init_google_generativeai_instrumentor():
|
510
485
|
try:
|
511
486
|
if is_package_installed("google.generativeai"):
|
512
|
-
# Telemetry().capture("instrumentation:gemini:init")
|
513
487
|
from opentelemetry.instrumentation.google_generativeai import (
|
514
488
|
GoogleGenerativeAiInstrumentor,
|
515
489
|
)
|
516
490
|
|
517
|
-
instrumentor = GoogleGenerativeAiInstrumentor(
|
518
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
519
|
-
)
|
491
|
+
instrumentor = GoogleGenerativeAiInstrumentor()
|
520
492
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
521
493
|
instrumentor.instrument()
|
522
494
|
return True
|
523
495
|
except Exception as e:
|
524
496
|
logging.error(f"Error initializing Gemini instrumentor: {e}")
|
525
|
-
# Telemetry().log_exception(e)
|
526
497
|
return False
|
527
498
|
|
528
499
|
|
529
500
|
def init_haystack_instrumentor():
|
530
501
|
try:
|
531
502
|
if is_package_installed("haystack"):
|
532
|
-
# Telemetry().capture("instrumentation:haystack:init")
|
533
503
|
from opentelemetry.instrumentation.haystack import HaystackInstrumentor
|
534
504
|
|
535
|
-
instrumentor = HaystackInstrumentor(
|
536
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
537
|
-
)
|
505
|
+
instrumentor = HaystackInstrumentor()
|
538
506
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
539
507
|
instrumentor.instrument()
|
540
508
|
return True
|
541
509
|
except Exception as e:
|
542
510
|
logging.error(f"Error initializing Haystack instrumentor: {e}")
|
543
|
-
# Telemetry().log_exception(e)
|
544
511
|
return False
|
545
512
|
|
546
513
|
|
547
514
|
def init_langchain_instrumentor():
|
548
515
|
try:
|
549
516
|
if is_package_installed("langchain"):
|
550
|
-
# Telemetry().capture("instrumentation:langchain:init")
|
551
517
|
from opentelemetry.instrumentation.langchain import LangchainInstrumentor
|
552
518
|
|
553
|
-
instrumentor = LangchainInstrumentor(
|
554
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
555
|
-
)
|
519
|
+
instrumentor = LangchainInstrumentor()
|
556
520
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
557
521
|
instrumentor.instrument()
|
558
522
|
return True
|
559
523
|
except Exception as e:
|
560
|
-
|
561
|
-
|
524
|
+
# FIXME: silencing this error temporarily, it appears to not be critical
|
525
|
+
if str(e) != "No module named 'langchain_community'":
|
526
|
+
logging.error(f"Error initializing LangChain instrumentor: {e}")
|
562
527
|
return False
|
563
528
|
|
564
529
|
|
565
530
|
def init_mistralai_instrumentor():
|
566
531
|
try:
|
567
532
|
if is_package_installed("mistralai"):
|
568
|
-
# Telemetry().capture("instrumentation:mistralai:init")
|
569
533
|
from opentelemetry.instrumentation.mistralai import MistralAiInstrumentor
|
570
534
|
|
571
|
-
instrumentor = MistralAiInstrumentor(
|
572
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
573
|
-
)
|
535
|
+
instrumentor = MistralAiInstrumentor()
|
574
536
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
575
537
|
instrumentor.instrument()
|
576
538
|
return True
|
577
539
|
except Exception as e:
|
578
540
|
logging.error(f"Error initializing MistralAI instrumentor: {e}")
|
579
|
-
# Telemetry().log_exception(e)
|
580
541
|
return False
|
581
542
|
|
582
543
|
|
583
544
|
def init_ollama_instrumentor():
|
584
545
|
try:
|
585
546
|
if is_package_installed("ollama"):
|
586
|
-
# Telemetry().capture("instrumentation:ollama:init")
|
587
547
|
from opentelemetry.instrumentation.ollama import OllamaInstrumentor
|
588
548
|
|
589
|
-
instrumentor = OllamaInstrumentor(
|
590
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
591
|
-
)
|
549
|
+
instrumentor = OllamaInstrumentor()
|
592
550
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
593
551
|
instrumentor.instrument()
|
594
552
|
return True
|
595
553
|
except Exception as e:
|
596
554
|
logging.error(f"Error initializing Ollama instrumentor: {e}")
|
597
|
-
# Telemetry().log_exception(e)
|
598
555
|
return False
|
599
556
|
|
600
557
|
|
601
558
|
def init_transformers_instrumentor():
|
602
559
|
try:
|
603
560
|
if is_package_installed("transformers"):
|
604
|
-
# Telemetry().capture("instrumentation:transformers:init")
|
605
561
|
from opentelemetry.instrumentation.transformers import (
|
606
562
|
TransformersInstrumentor,
|
607
563
|
)
|
608
564
|
|
609
|
-
instrumentor = TransformersInstrumentor(
|
610
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
611
|
-
)
|
565
|
+
instrumentor = TransformersInstrumentor()
|
612
566
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
613
567
|
instrumentor.instrument()
|
614
568
|
return True
|
615
569
|
except Exception as e:
|
616
570
|
logging.error(f"Error initializing Transformers instrumentor: {e}")
|
617
|
-
# Telemetry().log_exception(e)
|
618
571
|
return False
|
619
572
|
|
620
573
|
|
621
574
|
def init_together_instrumentor():
|
622
575
|
try:
|
623
576
|
if is_package_installed("together"):
|
624
|
-
# Telemetry().capture("instrumentation:together:init")
|
625
577
|
from opentelemetry.instrumentation.together import TogetherAiInstrumentor
|
626
578
|
|
627
|
-
instrumentor = TogetherAiInstrumentor(
|
628
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
629
|
-
)
|
579
|
+
instrumentor = TogetherAiInstrumentor()
|
630
580
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
631
581
|
instrumentor.instrument()
|
632
582
|
return True
|
633
583
|
except Exception as e:
|
634
584
|
logging.error(f"Error initializing TogetherAI instrumentor: {e}")
|
635
|
-
# Telemetry().log_exception(e)
|
636
585
|
return False
|
637
586
|
|
638
587
|
|
639
588
|
def init_llama_index_instrumentor():
|
640
589
|
try:
|
641
590
|
if is_package_installed("llama-index") or is_package_installed("llama_index"):
|
642
|
-
# Telemetry().capture("instrumentation:llamaindex:init")
|
643
591
|
from opentelemetry.instrumentation.llamaindex import LlamaIndexInstrumentor
|
644
592
|
|
645
|
-
instrumentor = LlamaIndexInstrumentor(
|
646
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
647
|
-
)
|
593
|
+
instrumentor = LlamaIndexInstrumentor()
|
648
594
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
649
595
|
instrumentor.instrument()
|
650
596
|
return True
|
651
597
|
except Exception as e:
|
652
598
|
logging.error(f"Error initializing LlamaIndex instrumentor: {e}")
|
653
|
-
# Telemetry().log_exception(e)
|
654
599
|
return False
|
655
600
|
|
656
601
|
|
657
602
|
def init_milvus_instrumentor():
|
658
603
|
try:
|
659
604
|
if is_package_installed("pymilvus"):
|
660
|
-
# Telemetry().capture("instrumentation:milvus:init")
|
661
605
|
from opentelemetry.instrumentation.milvus import MilvusInstrumentor
|
662
606
|
|
663
|
-
instrumentor = MilvusInstrumentor(
|
664
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
665
|
-
)
|
607
|
+
instrumentor = MilvusInstrumentor()
|
666
608
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
667
609
|
instrumentor.instrument()
|
668
610
|
return True
|
669
611
|
except Exception as e:
|
670
612
|
logging.error(f"Error initializing Milvus instrumentor: {e}")
|
671
|
-
# Telemetry().log_exception(e)
|
672
613
|
return False
|
673
614
|
|
674
615
|
|
@@ -683,7 +624,6 @@ def init_requests_instrumentor():
|
|
683
624
|
return True
|
684
625
|
except Exception as e:
|
685
626
|
logging.error(f"Error initializing Requests instrumentor: {e}")
|
686
|
-
# Telemetry().log_exception(e)
|
687
627
|
return False
|
688
628
|
|
689
629
|
|
@@ -698,7 +638,6 @@ def init_urllib3_instrumentor():
|
|
698
638
|
return True
|
699
639
|
except Exception as e:
|
700
640
|
logging.error(f"Error initializing urllib3 instrumentor: {e}")
|
701
|
-
# Telemetry().log_exception(e)
|
702
641
|
return False
|
703
642
|
|
704
643
|
|
@@ -713,7 +652,6 @@ def init_pymysql_instrumentor():
|
|
713
652
|
return True
|
714
653
|
except Exception as e:
|
715
654
|
logging.error(f"Error initializing SQLAlchemy instrumentor: {e}")
|
716
|
-
# Telemetry().log_exception(e)
|
717
655
|
return False
|
718
656
|
|
719
657
|
|
@@ -723,7 +661,6 @@ def init_bedrock_instrumentor(should_enrich_metrics: bool):
|
|
723
661
|
from opentelemetry.instrumentation.bedrock import BedrockInstrumentor
|
724
662
|
|
725
663
|
instrumentor = BedrockInstrumentor(
|
726
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
727
664
|
enrich_token_usage=should_enrich_metrics,
|
728
665
|
)
|
729
666
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
@@ -731,43 +668,34 @@ def init_bedrock_instrumentor(should_enrich_metrics: bool):
|
|
731
668
|
return True
|
732
669
|
except Exception as e:
|
733
670
|
logging.error(f"Error initializing Bedrock instrumentor: {e}")
|
734
|
-
# Telemetry().log_exception(e)
|
735
671
|
return False
|
736
672
|
|
737
673
|
|
738
674
|
def init_replicate_instrumentor():
|
739
675
|
try:
|
740
676
|
if is_package_installed("replicate"):
|
741
|
-
# Telemetry().capture("instrumentation:replicate:init")
|
742
677
|
from opentelemetry.instrumentation.replicate import ReplicateInstrumentor
|
743
678
|
|
744
|
-
instrumentor = ReplicateInstrumentor(
|
745
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
746
|
-
)
|
679
|
+
instrumentor = ReplicateInstrumentor()
|
747
680
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
748
681
|
instrumentor.instrument()
|
749
682
|
return True
|
750
683
|
except Exception as e:
|
751
684
|
logging.error(f"Error initializing Replicate instrumentor: {e}")
|
752
|
-
# Telemetry().log_exception(e)
|
753
685
|
return False
|
754
686
|
|
755
687
|
|
756
688
|
def init_vertexai_instrumentor():
|
757
689
|
try:
|
758
690
|
if is_package_installed("vertexai"):
|
759
|
-
# Telemetry().capture("instrumentation:vertexai:init")
|
760
691
|
from opentelemetry.instrumentation.vertexai import VertexAIInstrumentor
|
761
692
|
|
762
|
-
instrumentor = VertexAIInstrumentor(
|
763
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
764
|
-
)
|
693
|
+
instrumentor = VertexAIInstrumentor()
|
765
694
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
766
695
|
instrumentor.instrument()
|
767
696
|
return True
|
768
697
|
except Exception as e:
|
769
698
|
logging.warning(f"Error initializing Vertex AI instrumentor: {e}")
|
770
|
-
# Telemetry().log_exception(e)
|
771
699
|
return False
|
772
700
|
|
773
701
|
|
@@ -776,84 +704,65 @@ def init_watsonx_instrumentor():
|
|
776
704
|
if is_package_installed("ibm-watsonx-ai") or is_package_installed(
|
777
705
|
"ibm-watson-machine-learning"
|
778
706
|
):
|
779
|
-
# Telemetry().capture("instrumentation:watsonx:init")
|
780
707
|
from opentelemetry.instrumentation.watsonx import WatsonxInstrumentor
|
781
708
|
|
782
|
-
instrumentor = WatsonxInstrumentor(
|
783
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
784
|
-
)
|
709
|
+
instrumentor = WatsonxInstrumentor()
|
785
710
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
786
711
|
instrumentor.instrument()
|
787
712
|
return True
|
788
713
|
except Exception as e:
|
789
714
|
logging.warning(f"Error initializing Watsonx instrumentor: {e}")
|
790
|
-
# Telemetry().log_exception(e)
|
791
715
|
return False
|
792
716
|
|
793
717
|
|
794
718
|
def init_weaviate_instrumentor():
|
795
719
|
try:
|
796
720
|
if is_package_installed("weaviate"):
|
797
|
-
# Telemetry().capture("instrumentation:weaviate:init")
|
798
721
|
from opentelemetry.instrumentation.weaviate import WeaviateInstrumentor
|
799
722
|
|
800
|
-
instrumentor = WeaviateInstrumentor(
|
801
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
802
|
-
)
|
723
|
+
instrumentor = WeaviateInstrumentor()
|
803
724
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
804
725
|
instrumentor.instrument()
|
805
726
|
return True
|
806
727
|
except Exception as e:
|
807
728
|
logging.warning(f"Error initializing Weaviate instrumentor: {e}")
|
808
|
-
# Telemetry().log_exception(e)
|
809
729
|
return False
|
810
730
|
|
811
731
|
|
812
732
|
def init_alephalpha_instrumentor():
|
813
733
|
try:
|
814
734
|
if is_package_installed("aleph_alpha_client"):
|
815
|
-
# Telemetry().capture("instrumentation:alephalpha:init")
|
816
735
|
from opentelemetry.instrumentation.alephalpha import AlephAlphaInstrumentor
|
817
736
|
|
818
|
-
instrumentor = AlephAlphaInstrumentor(
|
819
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
820
|
-
)
|
737
|
+
instrumentor = AlephAlphaInstrumentor()
|
821
738
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
822
739
|
instrumentor.instrument()
|
823
740
|
return True
|
824
741
|
except Exception as e:
|
825
742
|
logging.error(f"Error initializing Aleph Alpha instrumentor: {e}")
|
826
|
-
# Telemetry().log_exception(e)
|
827
743
|
return False
|
828
744
|
|
829
745
|
|
830
746
|
def init_marqo_instrumentor():
|
831
747
|
try:
|
832
748
|
if is_package_installed("marqo"):
|
833
|
-
# Telemetry().capture("instrumentation:marqo:init")
|
834
749
|
from opentelemetry.instrumentation.marqo import MarqoInstrumentor
|
835
750
|
|
836
|
-
instrumentor = MarqoInstrumentor(
|
837
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
838
|
-
)
|
751
|
+
instrumentor = MarqoInstrumentor()
|
839
752
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
840
753
|
instrumentor.instrument()
|
841
754
|
return True
|
842
755
|
except Exception as e:
|
843
756
|
logging.error(f"Error initializing marqo instrumentor: {e}")
|
844
|
-
# Telemetry().log_exception(e)
|
845
757
|
return False
|
846
758
|
|
847
759
|
|
848
760
|
def init_lancedb_instrumentor():
|
849
761
|
try:
|
850
762
|
if is_package_installed("lancedb"):
|
851
|
-
# Telemetry().capture("instrumentation:lancedb:init")
|
852
763
|
from opentelemetry.instrumentation.lancedb import LanceInstrumentor
|
853
764
|
|
854
|
-
instrumentor = LanceInstrumentor(
|
855
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
856
|
-
)
|
765
|
+
instrumentor = LanceInstrumentor()
|
857
766
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
858
767
|
instrumentor.instrument()
|
859
768
|
return True
|
@@ -872,23 +781,34 @@ def init_redis_instrumentor():
|
|
872
781
|
return True
|
873
782
|
except Exception as e:
|
874
783
|
logging.error(f"Error initializing redis instrumentor: {e}")
|
875
|
-
# Telemetry().log_exception(e)
|
876
784
|
return False
|
877
785
|
|
878
786
|
|
879
787
|
def init_groq_instrumentor():
|
880
788
|
try:
|
881
789
|
if is_package_installed("groq"):
|
882
|
-
# Telemetry().capture("instrumentation:groq:init")
|
883
790
|
from opentelemetry.instrumentation.groq import GroqInstrumentor
|
884
791
|
|
885
|
-
instrumentor = GroqInstrumentor(
|
886
|
-
# exception_logger=lambda e: Telemetry().log_exception(e),
|
887
|
-
)
|
792
|
+
instrumentor = GroqInstrumentor()
|
888
793
|
if not instrumentor.is_instrumented_by_opentelemetry:
|
889
794
|
instrumentor.instrument()
|
890
795
|
return True
|
891
796
|
except Exception as e:
|
892
797
|
logging.error(f"Error initializing Groq instrumentor: {e}")
|
893
|
-
|
798
|
+
return False
|
799
|
+
|
800
|
+
|
801
|
+
def init_sagemaker_instrumentor(should_enrich_metrics: bool):
|
802
|
+
try:
|
803
|
+
if is_package_installed("boto3"):
|
804
|
+
from opentelemetry.instrumentation.sagemaker import SageMakerInstrumentor
|
805
|
+
|
806
|
+
instrumentor = SageMakerInstrumentor(
|
807
|
+
enrich_token_usage=should_enrich_metrics,
|
808
|
+
)
|
809
|
+
if not instrumentor.is_instrumented_by_opentelemetry:
|
810
|
+
instrumentor.instrument()
|
811
|
+
return True
|
812
|
+
except Exception as e:
|
813
|
+
logging.error(f"Error initializing SageMaker instrumentor: {e}")
|
894
814
|
return False
|