openlit 1.34.22__py3-none-any.whl → 1.34.23__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.
@@ -0,0 +1,74 @@
1
+ """Initializer of Auto Instrumentation of LangChain Community Functions"""
2
+ from typing import Collection
3
+ import importlib.metadata
4
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
5
+ from wrapt import wrap_function_wrapper
6
+
7
+ from openlit.instrumentation.langchain_community.langchain_community import (
8
+ general_wrap,
9
+ )
10
+ from openlit.instrumentation.langchain_community.async_langchain_community import (
11
+ async_general_wrap,
12
+ )
13
+
14
+ _instruments = ("langchain-community >= 0.2.0",)
15
+
16
+ WRAPPED_METHODS = [
17
+ {
18
+ "package": "langchain_community.document_loaders.base",
19
+ "object": "BaseLoader.load",
20
+ "endpoint": "langchain_community.retrieve.load",
21
+ "wrapper": general_wrap,
22
+ },
23
+ {
24
+ "package": "langchain_community.document_loaders.base",
25
+ "object": "BaseLoader.aload",
26
+ "endpoint": "langchain_community.retrieve.load",
27
+ "wrapper": async_general_wrap,
28
+ },
29
+ {
30
+ "package": "langchain_text_splitters.base",
31
+ "object": "TextSplitter.split_documents",
32
+ "endpoint": "langchain_community.retrieve.split_documents",
33
+ "wrapper": general_wrap,
34
+ },
35
+ {
36
+ "package": "langchain_text_splitters.base",
37
+ "object": "TextSplitter.create_documents",
38
+ "endpoint": "langchain_community.retrieve.create_documents",
39
+ "wrapper": general_wrap,
40
+ },
41
+ ]
42
+
43
+ class LangChainCommunityInstrumentor(BaseInstrumentor):
44
+ """
45
+ An instrumentor for LangChain Community client library.
46
+ """
47
+
48
+ def instrumentation_dependencies(self) -> Collection[str]:
49
+ return _instruments
50
+
51
+ def _instrument(self, **kwargs):
52
+ version = importlib.metadata.version("langchain-community")
53
+ environment = kwargs.get("environment", "default")
54
+ application_name = kwargs.get("application_name", "default")
55
+ tracer = kwargs.get("tracer")
56
+ pricing_info = kwargs.get("pricing_info", {})
57
+ capture_message_content = kwargs.get("capture_message_content", False)
58
+ metrics = kwargs.get("metrics_dict")
59
+ disable_metrics = kwargs.get("disable_metrics")
60
+
61
+ for wrapped_method in WRAPPED_METHODS:
62
+ wrap_package = wrapped_method.get("package")
63
+ wrap_object = wrapped_method.get("object")
64
+ gen_ai_endpoint = wrapped_method.get("endpoint")
65
+ wrapper = wrapped_method.get("wrapper")
66
+ wrap_function_wrapper(
67
+ wrap_package,
68
+ wrap_object,
69
+ wrapper(gen_ai_endpoint, version, environment, application_name,
70
+ tracer, pricing_info, capture_message_content, metrics, disable_metrics),
71
+ )
72
+
73
+ def _uninstrument(self, **kwargs):
74
+ pass
@@ -0,0 +1,49 @@
1
+ """
2
+ Module for monitoring async LangChain Community operations.
3
+ """
4
+
5
+ import logging
6
+ from opentelemetry import trace
7
+ from opentelemetry.trace import Status, StatusCode
8
+
9
+ from openlit.__helpers import handle_exception
10
+ from openlit.instrumentation.langchain_community.utils import process_general_response
11
+
12
+ # Initialize logger for LangChain Community instrumentation
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def async_general_wrap(gen_ai_endpoint, version, environment, application_name, tracer, pricing_info,
16
+ capture_message_content, metrics, disable_metrics):
17
+ """
18
+ Generates a telemetry wrapper for GenAI operations.
19
+ """
20
+
21
+ async def wrapper(wrapped, instance, args, kwargs):
22
+ """
23
+ Wraps the GenAI operation call.
24
+ """
25
+
26
+ # Prepare server address and port
27
+ server_address = "127.0.0.1"
28
+ server_port = "80"
29
+
30
+ # Get the parent span from the tracer
31
+ with tracer.start_as_current_span(gen_ai_endpoint, kind=trace.SpanKind.CLIENT) as span:
32
+ try:
33
+ # Call the original async function
34
+ response = await wrapped(*args, **kwargs)
35
+
36
+ # Process the response using the utility function
37
+ response = process_general_response(
38
+ response, gen_ai_endpoint, server_port, server_address,
39
+ environment, application_name, span, version
40
+ )
41
+
42
+ span.set_status(Status(StatusCode.OK))
43
+
44
+ except Exception as e:
45
+ handle_exception(span, e)
46
+
47
+ return response
48
+
49
+ return wrapper
@@ -0,0 +1,49 @@
1
+ """
2
+ Module for monitoring LangChain Community operations.
3
+ """
4
+
5
+ import logging
6
+ from opentelemetry import trace
7
+ from opentelemetry.trace import Status, StatusCode
8
+
9
+ from openlit.__helpers import handle_exception
10
+ from openlit.instrumentation.langchain_community.utils import process_general_response
11
+
12
+ # Initialize logger for LangChain Community instrumentation
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def general_wrap(gen_ai_endpoint, version, environment, application_name, tracer, pricing_info,
16
+ capture_message_content, metrics, disable_metrics):
17
+ """
18
+ Generates a telemetry wrapper for GenAI operations.
19
+ """
20
+
21
+ def wrapper(wrapped, instance, args, kwargs):
22
+ """
23
+ Wraps the GenAI operation call.
24
+ """
25
+
26
+ # Prepare server address and port
27
+ server_address = "127.0.0.1"
28
+ server_port = "80"
29
+
30
+ # Get the parent span from the tracer
31
+ with tracer.start_as_current_span(gen_ai_endpoint, kind=trace.SpanKind.CLIENT) as span:
32
+ try:
33
+ # Call the original function
34
+ response = wrapped(*args, **kwargs)
35
+
36
+ # Process the response using the utility function
37
+ response = process_general_response(
38
+ response, gen_ai_endpoint, server_port, server_address,
39
+ environment, application_name, span, version
40
+ )
41
+
42
+ span.set_status(Status(StatusCode.OK))
43
+
44
+ except Exception as e:
45
+ handle_exception(span, e)
46
+
47
+ return response
48
+
49
+ return wrapper
@@ -0,0 +1,69 @@
1
+ """
2
+ Utility functions for LangChain Community instrumentation.
3
+ """
4
+
5
+ from opentelemetry.trace import Status, StatusCode
6
+ from openlit.semcov import SemanticConvention
7
+
8
+ def process_general_response(response, gen_ai_endpoint, server_port, server_address,
9
+ environment, application_name, span, version="1.0.0"):
10
+ """
11
+ Process general LangChain Community operations (document loading, text splitting) and generate telemetry.
12
+
13
+ Args:
14
+ response: The response object from the LangChain Community operation
15
+ gen_ai_endpoint: The endpoint identifier for the operation
16
+ server_port: Server port (empty for community operations)
17
+ server_address: Server address (empty for community operations)
18
+ environment: Environment name
19
+ application_name: Application name
20
+ span: OpenTelemetry span
21
+ version: Version string
22
+
23
+ Returns:
24
+ The original response object
25
+ """
26
+
27
+ # Set span attributes for general operations
28
+ span.set_attribute(SemanticConvention.GEN_AI_SYSTEM, SemanticConvention.GEN_AI_SYSTEM_LANGCHAIN)
29
+ span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT, gen_ai_endpoint)
30
+ span.set_attribute(SemanticConvention.GEN_AI_OPERATION, SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
31
+ span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION, version)
32
+ span.set_attribute(SemanticConvention.GEN_AI_ENVIRONMENT, environment)
33
+ span.set_attribute(SemanticConvention.GEN_AI_APPLICATION_NAME, application_name)
34
+
35
+ # Try to extract source information for document loading operations
36
+ if gen_ai_endpoint and "retrieve.load" in gen_ai_endpoint:
37
+ try:
38
+ if hasattr(response, "__iter__") and len(response) > 0:
39
+ # For document loaders, try to get source from first document
40
+ first_doc = response[0]
41
+ if hasattr(first_doc, "metadata") and isinstance(first_doc.metadata, dict):
42
+ source = first_doc.metadata.get("source", "unknown")
43
+ span.set_attribute(SemanticConvention.GEN_AI_RETRIEVAL_SOURCE, source)
44
+
45
+ # Count number of documents loaded
46
+ span.set_attribute("gen_ai.retrieval.documents.count", len(response))
47
+ except (AttributeError, KeyError, IndexError, TypeError):
48
+ # If we cant extract metadata, just continue without it
49
+ pass
50
+
51
+ # For text splitting operations
52
+ elif gen_ai_endpoint and ("split_documents" in gen_ai_endpoint or "create_documents" in gen_ai_endpoint):
53
+ try:
54
+ if hasattr(response, "__iter__") and len(response) > 0:
55
+ # Count number of text chunks created
56
+ span.set_attribute("gen_ai.text_splitter.chunks.count", len(response))
57
+
58
+ # Try to get average chunk size
59
+ total_chars = sum(len(doc.page_content) for doc in response if hasattr(doc, "page_content"))
60
+ if total_chars > 0:
61
+ avg_chunk_size = total_chars // len(response)
62
+ span.set_attribute("gen_ai.text_splitter.avg_chunk_size", avg_chunk_size)
63
+ except (AttributeError, TypeError):
64
+ # If we cant extract chunk information, just continue without it
65
+ pass
66
+
67
+ span.set_status(Status(StatusCode.OK))
68
+
69
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openlit
3
- Version: 1.34.22
3
+ Version: 1.34.23
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
5
5
  License: Apache-2.0
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
@@ -1,5 +1,5 @@
1
1
  openlit/__helpers.py,sha256=UmW0E97r7UUps2rkdQ-S_lXhaeH3Txp-umyAOon45mk,16458
2
- openlit/__init__.py,sha256=ris6-GY0ePSbK_jvawHTXymGClVF7yeKdIT95IRBl18,24086
2
+ openlit/__init__.py,sha256=tYsR2OkDOq7Zf3wBOd3kFfosqUKgZxljMm6mZagMUiI,24296
3
3
  openlit/evals/__init__.py,sha256=nJe99nuLo1b5rf7pt9U9BCdSDedzbVi2Fj96cgl7msM,380
4
4
  openlit/evals/all.py,sha256=oWrue3PotE-rB5WePG3MRYSA-ro6WivkclSHjYlAqGs,7154
5
5
  openlit/evals/bias_detection.py,sha256=mCdsfK7x1vX7S3psC3g641IMlZ-7df3h-V6eiICj5N8,8154
@@ -12,8 +12,10 @@ openlit/guard/prompt_injection.py,sha256=3e4DKxB7QDzM-xPCpwEuureiH_2s_OTJ9BSckkn
12
12
  openlit/guard/restrict_topic.py,sha256=KTuWa7XeMsV4oXxOrD1CYZV0wXWxTfA0H3p_6q_IOsk,6444
13
13
  openlit/guard/sensitive_topic.py,sha256=RgVw_laFERv0nNdzBsAd2_3yLomMOK-gVq-P7oj1bTk,5552
14
14
  openlit/guard/utils.py,sha256=6hE3rCRjFXYjKRQYUo8YsqUSlvod48nOWp8MwoQEYdw,7670
15
- openlit/instrumentation/ag2/__init__.py,sha256=KgyLJBmwAxRWu7Z0S8FDDK4TZ13EFoAAIalvG5Oq4wc,1839
16
- openlit/instrumentation/ag2/ag2.py,sha256=eNQziyeZl4396GsIp5qI1Dne2KcnQMmhftW7joKQvNU,6934
15
+ openlit/instrumentation/ag2/__init__.py,sha256=vHKx7ybxwtNMGoIyU3lPp8t33m3lWyA_B-1HtJoW0v4,1880
16
+ openlit/instrumentation/ag2/ag2.py,sha256=ebsBWrXf7apjLumTB4hWw19-q9V0zacyDcJ-7oZoxew,3955
17
+ openlit/instrumentation/ag2/async_ag2.py,sha256=5OnM7tos-T5O6mmxhOVI1EO3J47wodC_HSJPWpvmauM,4031
18
+ openlit/instrumentation/ag2/utils.py,sha256=HwOqUQE4HqHLDLGf8nIPc_aiOVoV7iz30piw31F9pys,7073
17
19
  openlit/instrumentation/ai21/__init__.py,sha256=tKX643fwxPWPJq1EXEZd0Xpd6B0jl_ViPFmJ87f5B08,2539
18
20
  openlit/instrumentation/ai21/ai21.py,sha256=zyQMfCLcOFG1tQWrZmGeMaVAmj8MtCUeXQtPHmlUAO0,6533
19
21
  openlit/instrumentation/ai21/async_ai21.py,sha256=q1Dhxru4tUJu0U1Px3PptNqrSGW0-VfRGcqkLKFR8vQ,6659
@@ -76,9 +78,14 @@ openlit/instrumentation/haystack/haystack.py,sha256=kPkuCJDrccNgAg3yDAHbvEytzyfM
76
78
  openlit/instrumentation/julep/__init__.py,sha256=g-hwXjvXAb5IDs5DR_P8rKsnD4beB9tupAzuuviQT3k,3216
77
79
  openlit/instrumentation/julep/async_julep.py,sha256=fPUOGAOIxelBt4cw-PGp5zj_B1nfj5ly3Dj0kelw3-s,5327
78
80
  openlit/instrumentation/julep/julep.py,sha256=6rGgDOB7UzisgYsm12vnTy39dl9HAlRVBVByEr2116g,5330
79
- openlit/instrumentation/langchain/__init__.py,sha256=cNlumZ8fwLMlGVFMjNEndOIzooD4FQEOINX9tGVksII,3853
80
- openlit/instrumentation/langchain/async_langchain.py,sha256=rdk3INGcsxsfzZcoJo0yYtc8A0tQbWevF_mzf9IPrqg,18341
81
- openlit/instrumentation/langchain/langchain.py,sha256=zgfzfOIDsaRoVgWl1T4XX2CLO7ttGOD15TagZtYQ-vE,17012
81
+ openlit/instrumentation/langchain/__init__.py,sha256=idjeMAL8tCf1KimrS82D4RERbicSxBj82e8WNuaZWs8,2996
82
+ openlit/instrumentation/langchain/async_langchain.py,sha256=5RtaBLifJoDYBPL3d53dT2GDmDzOh5oqyZeJIXAmWxg,3426
83
+ openlit/instrumentation/langchain/langchain.py,sha256=6jO5QAZz_jYyauEyQ76nbTpiNrTLPwLNPKzXmlBn75Y,3336
84
+ openlit/instrumentation/langchain/utils.py,sha256=ermEFuOY9Djh4Np4EHeh7XRzZc-B24A_CPLqkJhvzpY,10470
85
+ openlit/instrumentation/langchain_community/__init__.py,sha256=DGNxMj6RAMQtTFD0plU826D3G-KupROwexN4GjmAFmk,2717
86
+ openlit/instrumentation/langchain_community/async_langchain_community.py,sha256=BX6ErjSX9-RXBxB5cFwDrhVKpb3OGzwpzzw5VPMpp80,1590
87
+ openlit/instrumentation/langchain_community/langchain_community.py,sha256=J-sN5eGC7r-OkPAU-lnbdG7-b_jtYs0esmFy51xdFIk,1560
88
+ openlit/instrumentation/langchain_community/utils.py,sha256=v_QWgSbGZm4PIiInz6Ul4dz3h0lrWfLOX1Hj9pDERUI,3334
82
89
  openlit/instrumentation/letta/__init__.py,sha256=K8PtRKxuueyqEYE3LzxWJ74IieNKSI6dmk9sNRd8Mt0,3031
83
90
  openlit/instrumentation/letta/letta.py,sha256=SCIpJ4tdB1l1BmeQx4raaTS4MQO5X15pLvS4PepEKBE,8481
84
91
  openlit/instrumentation/litellm/__init__.py,sha256=D47yfDLLEKpkaRAy7_Yif70kj88AGqLQYZAABpTN4sE,2284
@@ -143,7 +150,7 @@ openlit/otel/events.py,sha256=VrMjTpvnLtYRBHCiFwJojTQqqNpRCxoD4yJYeQrtPsk,3560
143
150
  openlit/otel/metrics.py,sha256=GM2PDloBGRhBTkHHkYaqmOwIAQkY124ZhW4sEqW1Fgk,7086
144
151
  openlit/otel/tracing.py,sha256=tjV2bEbEDPUB1Z46gE-UsJsb04sRdFrfbhIDkxViZc0,3103
145
152
  openlit/semcov/__init__.py,sha256=8oIh2VC667NDh8FA3M-ESusHmeus1sgDUD8binx_nAc,13519
146
- openlit-1.34.22.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
147
- openlit-1.34.22.dist-info/METADATA,sha256=ADqRel4c0tZ3_W6h7dUSHh93x56YyU8sHYdjwQZlJVg,23470
148
- openlit-1.34.22.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
149
- openlit-1.34.22.dist-info/RECORD,,
153
+ openlit-1.34.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
154
+ openlit-1.34.23.dist-info/METADATA,sha256=I28zXVmrGZFQxfl8ayXqVX2YSHYTX0R5upGyteI5tLg,23470
155
+ openlit-1.34.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
156
+ openlit-1.34.23.dist-info/RECORD,,