openlit 1.6.0__py3-none-any.whl → 1.7.0__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.
openlit/__init__.py CHANGED
@@ -27,6 +27,7 @@ from openlit.instrumentation.haystack import HaystackInstrumentor
27
27
  from openlit.instrumentation.chroma import ChromaInstrumentor
28
28
  from openlit.instrumentation.pinecone import PineconeInstrumentor
29
29
  from openlit.instrumentation.qdrant import QdrantInstrumentor
30
+ from openlit.instrumentation.milvus import MilvusInstrumentor
30
31
  from openlit.instrumentation.transformers import TransformersInstrumentor
31
32
 
32
33
  # Set up logging for error and information messages.
@@ -162,6 +163,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
162
163
  "chroma": "chromadb",
163
164
  "pinecone": "pinecone",
164
165
  "qdrant": "qdrant_client",
166
+ "milvus": "pymilvus",
165
167
  "transformers": "transformers"
166
168
  }
167
169
 
@@ -215,6 +217,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
215
217
  "chroma": ChromaInstrumentor(),
216
218
  "pinecone": PineconeInstrumentor(),
217
219
  "qdrant": QdrantInstrumentor(),
220
+ "milvus": MilvusInstrumentor(),
218
221
  "transformers": TransformersInstrumentor()
219
222
  }
220
223
 
@@ -0,0 +1,94 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of Milvus Functions"""
3
+ from typing import Collection
4
+ import importlib.metadata
5
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
+ from wrapt import wrap_function_wrapper
7
+
8
+ from openlit.instrumentation.milvus.milvus import general_wrap
9
+
10
+ _instruments = ("pymilvus >= 2.4.3",)
11
+
12
+ WRAPPED_METHODS = [
13
+ {
14
+ "package": "pymilvus",
15
+ "object": "MilvusClient.create_collection",
16
+ "endpoint": "milvus.create_collection",
17
+ "wrapper": general_wrap,
18
+ },
19
+ {
20
+ "package": "pymilvus",
21
+ "object": "MilvusClient.drop_collection",
22
+ "endpoint": "milvus.drop_collection",
23
+ "wrapper": general_wrap,
24
+ },
25
+ {
26
+ "package": "pymilvus",
27
+ "object": "MilvusClient.insert",
28
+ "endpoint": "milvus.insert",
29
+ "wrapper": general_wrap,
30
+ },
31
+ {
32
+ "package": "pymilvus",
33
+ "object": "MilvusClient.upsert",
34
+ "endpoint": "milvus.upsert",
35
+ "wrapper": general_wrap,
36
+ },
37
+ {
38
+ "package": "pymilvus",
39
+ "object": "MilvusClient.search",
40
+ "endpoint": "milvus.search",
41
+ "wrapper": general_wrap,
42
+ },
43
+ {
44
+ "package": "pymilvus",
45
+ "object": "MilvusClient.query",
46
+ "endpoint": "milvus.query",
47
+ "wrapper": general_wrap,
48
+ },
49
+ {
50
+ "package": "pymilvus",
51
+ "object": "MilvusClient.get",
52
+ "endpoint": "milvus.get",
53
+ "wrapper": general_wrap,
54
+ },
55
+ {
56
+ "package": "pymilvus",
57
+ "object": "MilvusClient.delete",
58
+ "endpoint": "milvus.delete",
59
+ "wrapper": general_wrap,
60
+ },
61
+ ]
62
+
63
+ class MilvusInstrumentor(BaseInstrumentor):
64
+ """An instrumentor for Milvus's client library."""
65
+
66
+ def instrumentation_dependencies(self) -> Collection[str]:
67
+ return _instruments
68
+
69
+ def _instrument(self, **kwargs):
70
+ application_name = kwargs.get("application_name")
71
+ environment = kwargs.get("environment")
72
+ tracer = kwargs.get("tracer")
73
+ metrics = kwargs.get("metrics_dict")
74
+ pricing_info = kwargs.get("pricing_info")
75
+ trace_content = kwargs.get("trace_content")
76
+ disable_metrics = kwargs.get("disable_metrics")
77
+ version = importlib.metadata.version("pymilvus")
78
+
79
+ for wrapped_method in WRAPPED_METHODS:
80
+ wrap_package = wrapped_method.get("package")
81
+ wrap_object = wrapped_method.get("object")
82
+ gen_ai_endpoint = wrapped_method.get("endpoint")
83
+ wrapper = wrapped_method.get("wrapper")
84
+ wrap_function_wrapper(
85
+ wrap_package,
86
+ wrap_object,
87
+ wrapper(gen_ai_endpoint, version, environment, application_name,
88
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
89
+ )
90
+
91
+
92
+ @staticmethod
93
+ def _uninstrument(self, **kwargs):
94
+ pass
@@ -0,0 +1,179 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment, too-many-branches
2
+ """
3
+ Module for monitoring Milvus.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import handle_exception
10
+ from openlit.semcov import SemanticConvetion
11
+
12
+ # Initialize logger for logging potential issues and operations
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def object_count(obj):
16
+ """
17
+ Counts Length of object if it exists, Else returns None
18
+ """
19
+ try:
20
+ cnt = len(obj)
21
+ # pylint: disable=bare-except
22
+ except:
23
+ cnt = 0
24
+
25
+ return cnt
26
+
27
+ def general_wrap(gen_ai_endpoint, version, environment, application_name,
28
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
29
+ """
30
+ Creates a wrapper around a function call to trace and log its execution metrics.
31
+
32
+ This function wraps any given function to measure its execution time,
33
+ log its operation, and trace its execution using OpenTelemetry.
34
+
35
+ Parameters:
36
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
37
+ - version (str): The version of the Langchain application.
38
+ - environment (str): The deployment environment (e.g., 'production', 'development').
39
+ - application_name (str): Name of the Langchain application.
40
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
41
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
42
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
43
+
44
+ Returns:
45
+ - function: A higher-order function that takes a function 'wrapped' and returns
46
+ a new function that wraps 'wrapped' with additional tracing and logging.
47
+ """
48
+
49
+ def wrapper(wrapped, instance, args, kwargs):
50
+ """
51
+ An inner wrapper function that executes the wrapped function, measures execution
52
+ time, and records trace data using OpenTelemetry.
53
+
54
+ Parameters:
55
+ - wrapped (Callable): The original function that this wrapper will execute.
56
+ - instance (object): The instance to which the wrapped function belongs. This
57
+ is used for instance methods. For static and classmethods,
58
+ this may be None.
59
+ - args (tuple): Positional arguments passed to the wrapped function.
60
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
61
+
62
+ Returns:
63
+ - The result of the wrapped function call.
64
+
65
+ The wrapper initiates a span with the provided tracer, sets various attributes
66
+ on the span based on the function's execution and response, and ensures
67
+ errors are handled and logged appropriately.
68
+ """
69
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
70
+ response = wrapped(*args, **kwargs)
71
+
72
+ try:
73
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
74
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
75
+ gen_ai_endpoint)
76
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
77
+ environment)
78
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
79
+ application_name)
80
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
81
+ SemanticConvetion.GEN_AI_TYPE_VECTORDB)
82
+ span.set_attribute(SemanticConvetion.DB_SYSTEM,
83
+ SemanticConvetion.DB_SYSTEM_MILVUS)
84
+
85
+ if gen_ai_endpoint == "milvus.create_collection":
86
+ db_operation = SemanticConvetion.DB_OPERATION_CREATE_COLLECTION
87
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
88
+ SemanticConvetion.DB_OPERATION_CREATE_COLLECTION)
89
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
90
+ kwargs.get("collection_name", ""))
91
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_DIMENSION,
92
+ kwargs.get("dimension", ""))
93
+
94
+ elif gen_ai_endpoint == "milvus.drop_collection":
95
+ db_operation = SemanticConvetion.DB_OPERATION_DELETE_COLLECTION
96
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
97
+ SemanticConvetion.DB_OPERATION_DELETE_COLLECTION)
98
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
99
+ kwargs.get("collection_name", ""))
100
+
101
+ elif gen_ai_endpoint == "milvus.insert":
102
+ db_operation = SemanticConvetion.DB_OPERATION_ADD
103
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
104
+ SemanticConvetion.DB_OPERATION_ADD)
105
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
106
+ kwargs.get("collection_name", ""))
107
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
108
+ object_count(kwargs.get("data")))
109
+ span.set_attribute(SemanticConvetion.DB_OPERATION_COST,
110
+ response["cost"])
111
+
112
+ elif gen_ai_endpoint == "milvus.search":
113
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
114
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
115
+ SemanticConvetion.DB_OPERATION_QUERY)
116
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
117
+ kwargs.get("collection_name", ""))
118
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
119
+ str(kwargs.get("data")))
120
+
121
+ elif gen_ai_endpoint in ["milvus.query", "milvus.get"]:
122
+ db_operation = SemanticConvetion.DB_OPERATION_QUERY
123
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
124
+ SemanticConvetion.DB_OPERATION_QUERY)
125
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
126
+ kwargs.get("collection_name", ""))
127
+ span.set_attribute(SemanticConvetion.DB_STATEMENT,
128
+ str(kwargs.get("output_fields")))
129
+
130
+ elif gen_ai_endpoint == "milvus.upsert":
131
+ db_operation = SemanticConvetion.DB_OPERATION_ADD
132
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
133
+ SemanticConvetion.DB_OPERATION_UPSERT)
134
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
135
+ kwargs.get("collection_name", ""))
136
+ span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
137
+ object_count(kwargs.get("data")))
138
+ span.set_attribute(SemanticConvetion.DB_OPERATION_COST,
139
+ response["cost"])
140
+
141
+ elif gen_ai_endpoint == "milvus.delete":
142
+ db_operation = SemanticConvetion.DB_OPERATION_DELETE
143
+ span.set_attribute(SemanticConvetion.DB_OPERATION,
144
+ SemanticConvetion.DB_OPERATION_DELETE)
145
+ span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
146
+ kwargs.get("collection_name", ""))
147
+ span.set_attribute(SemanticConvetion.DB_FILTER,
148
+ str(kwargs.get("filter", "")))
149
+
150
+ span.set_status(Status(StatusCode.OK))
151
+
152
+ if disable_metrics is False:
153
+ attributes = {
154
+ TELEMETRY_SDK_NAME:
155
+ "openlit",
156
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
157
+ application_name,
158
+ SemanticConvetion.DB_SYSTEM:
159
+ SemanticConvetion.DB_SYSTEM_MILVUS,
160
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
161
+ environment,
162
+ SemanticConvetion.GEN_AI_TYPE:
163
+ SemanticConvetion.GEN_AI_TYPE_VECTORDB,
164
+ SemanticConvetion.DB_OPERATION:
165
+ db_operation
166
+ }
167
+
168
+ metrics["db_requests"].add(1, attributes)
169
+
170
+ return response
171
+
172
+ except Exception as e:
173
+ handle_exception(span, e)
174
+ logger.error("Error in trace creation: %s", e)
175
+
176
+ # Return original response
177
+ return response
178
+
179
+ return wrapper
@@ -99,6 +99,7 @@ class SemanticConvetion:
99
99
  DB_COLLECTION_NAME = "db.collection.name"
100
100
  DB_OPERATION = "db.operation"
101
101
  DB_OPERATION_STATUS = "db.operation.status"
102
+ DB_OPERATION_COST = "db.operation.cost"
102
103
  DB_OPERATION_CREATE_INDEX = "create_index"
103
104
  DB_OPERATION_CREATE_COLLECTION = "create_collection"
104
105
  DB_OPERATION_UPDATE_COLLECTION = "update_collection"
@@ -123,7 +124,8 @@ class SemanticConvetion:
123
124
  DB_N_RESULTS = "db.n_results"
124
125
  DB_DELETE_ALL = "db.delete_all"
125
126
  DB_INDEX_NAME = "db.index.name"
126
- DB_INDEX_DIMENSION = "db.create_index.dimensions"
127
+ DB_INDEX_DIMENSION = "db.index.dimension"
128
+ DB_COLLECTION_DIMENSION = "db.collection.dimension"
127
129
  DB_INDEX_METRIC = "db.create_index.metric"
128
130
  DB_INDEX_SPEC = "db.create_index.spec"
129
131
  DB_NAMESPACE = "db.query.namespace"
@@ -134,3 +136,4 @@ class SemanticConvetion:
134
136
  DB_SYSTEM_CHROMA = "chroma"
135
137
  DB_SYSTEM_PINECONE = "pinecone"
136
138
  DB_SYSTEM_QDRANT = "qdrant"
139
+ DB_SYSTEM_MILVUS = "milvus"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
5
5
  Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT
@@ -64,6 +64,7 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
64
64
  - [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
65
65
  - [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
66
66
  - [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant)
67
+ - [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus)
67
68
 
68
69
  ### Frameworks
69
70
  - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
@@ -1,5 +1,5 @@
1
1
  openlit/__helpers.py,sha256=EEbLEUKuCiBp0WiieAvUnGcaU5D7grFgNVDCBgMKjQE,4651
2
- openlit/__init__.py,sha256=6D83ebOY_LRaOtppUrgJdJfjosF3Ao4FtomEhH21pYY,9781
2
+ openlit/__init__.py,sha256=NzHt2F8iJh5ljM1wD-HH4pkH2yH0e0ivE49U5LNGlnk,9917
3
3
  openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
4
4
  openlit/instrumentation/anthropic/anthropic.py,sha256=CYBui5eEfWdSfFF0xtCQjh1xO-gCVJc_V9Hli0szVZE,16026
5
5
  openlit/instrumentation/anthropic/async_anthropic.py,sha256=NW84kTQ3BkUx1zZuMRps_J7zTYkmq5BxOrqSjqWInBs,16068
@@ -18,6 +18,8 @@ openlit/instrumentation/langchain/__init__.py,sha256=TW1ZR7I1i9Oig-wDWp3j1gmtQFO
18
18
  openlit/instrumentation/langchain/langchain.py,sha256=G66UytYwWW0DdvChomzkc5_MJ-sjupuDwlxe4KqlGhY,7639
19
19
  openlit/instrumentation/llamaindex/__init__.py,sha256=FwE0iozGbZcd2dWo9uk4EO6qKPAe55byhZBuzuFyxXA,1973
20
20
  openlit/instrumentation/llamaindex/llamaindex.py,sha256=uiIigbwhonSbJWA7LpgOVI1R4kxxPODS1K5wyHIQ4hM,4048
21
+ openlit/instrumentation/milvus/__init__.py,sha256=qi1yfmMrvkDtnrN_6toW8qC9BRL78bq7ayWpObJ8Bq4,2961
22
+ openlit/instrumentation/milvus/milvus.py,sha256=qhKIoggBAJhRctRrBYz69AcvXH-eh7oBn_l9WfxpAjI,9121
21
23
  openlit/instrumentation/mistral/__init__.py,sha256=zJCIpFWRbsYrvooOJYuqwyuKeSOQLWbyXWCObL-Snks,3156
22
24
  openlit/instrumentation/mistral/async_mistral.py,sha256=PXpiLwkonTtAPVOUh9pXMSYeabwH0GFG_HRDWrEKhMM,21361
23
25
  openlit/instrumentation/mistral/mistral.py,sha256=nbAyMlPiuA9hihePkM_nnxAjahZSndT-B-qXRO5VIhk,21212
@@ -40,8 +42,8 @@ openlit/instrumentation/vertexai/async_vertexai.py,sha256=PMHYyLf1J4gZpC_-KZ_ZVx
40
42
  openlit/instrumentation/vertexai/vertexai.py,sha256=UvpNKBHPoV9idVMfGigZnmWuEQiyqSwZn0zK9-U7Lzw,52125
41
43
  openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
42
44
  openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
43
- openlit/semcov/__init__.py,sha256=3Whg8caSmGi-rF2PVkJohpCf5O3QjpgN7ai8r4XBIVI,6204
44
- openlit-1.6.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
45
- openlit-1.6.0.dist-info/METADATA,sha256=4qtHtjElIivkXWyJFXfUt-0_tTaidonqmJbT7Uvq8rc,12213
46
- openlit-1.6.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
47
- openlit-1.6.0.dist-info/RECORD,,
45
+ openlit/semcov/__init__.py,sha256=wcy_1uP6_YxpaHxlo5he91m2GcuD5sfngZbZGgIwNlY,6328
46
+ openlit-1.7.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
47
+ openlit-1.7.0.dist-info/METADATA,sha256=gTob1Bi1ZPwj0i0AxWvnjxdg24xrAspP7_OmOIphCBo,12280
48
+ openlit-1.7.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
49
+ openlit-1.7.0.dist-info/RECORD,,