openlit 1.6.0__tar.gz → 1.9.0__tar.gz

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.
Files changed (49) hide show
  1. {openlit-1.6.0 → openlit-1.9.0}/PKG-INFO +74 -56
  2. {openlit-1.6.0 → openlit-1.9.0}/README.md +73 -55
  3. {openlit-1.6.0 → openlit-1.9.0}/pyproject.toml +1 -1
  4. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/__helpers.py +30 -5
  5. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/__init__.py +10 -4
  6. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/cohere/cohere.py +4 -3
  7. openlit-1.9.0/src/openlit/instrumentation/milvus/__init__.py +94 -0
  8. openlit-1.9.0/src/openlit/instrumentation/milvus/milvus.py +179 -0
  9. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/semcov/__init__.py +4 -1
  10. {openlit-1.6.0 → openlit-1.9.0}/LICENSE +0 -0
  11. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  12. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  13. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  14. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  15. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  16. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  17. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  18. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  19. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/groq/__init__.py +0 -0
  20. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  21. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/groq/groq.py +0 -0
  22. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  23. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  24. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  25. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  26. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
  27. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  28. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  29. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  30. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  31. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  32. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  33. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  34. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
  35. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  36. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  37. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  38. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/openai/openai.py +0 -0
  39. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  40. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  41. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  42. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
  43. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  44. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  45. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  46. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  47. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  48. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/otel/metrics.py +0 -0
  49. {openlit-1.6.0 → openlit-1.9.0}/src/openlit/otel/tracing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.6.0
3
+ Version: 1.9.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
@@ -38,6 +38,9 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
38
38
  [![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack&logoColor=white)](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ)
39
39
  [![X](https://img.shields.io/badge/follow-%40OpenLIT-1DA1F2?logo=x&style=social)](https://twitter.com/openlit_io)
40
40
 
41
+ ![OpenLIT Connections Banner](https://github.com/openlit/.github/blob/main/profile/assets/github-readme-connections-banner.png?raw=true)
42
+
43
+
41
44
  </div>
42
45
 
43
46
  OpenLIT Python SDK is an **OpenTelemetry-native** Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects. Designed with simplicity and efficiency, OpenLIT offers the ability to embed observability into your GenAI-driven projects effortlessly using just **a single line of code**.
@@ -46,30 +49,20 @@ Whether you're directly using LLM Libraries like OpenAI, Anthropic or building c
46
49
 
47
50
  This project adheres to the [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai) proposed by the OpenTelemetry community. You can check out the current definitions [here](src/openlit/semcov/__init__.py).
48
51
 
49
- ## What can be Auto Instrumented?
50
-
51
- ### LLMs
52
- - [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai)
53
- - [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama)
54
- - [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic)
55
- - [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere)
56
- - [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral)
57
- - [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai)
58
- - [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface)
59
- - [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock)
60
- - [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai)
61
- - [✅ Groq](https://docs.openlit.io/latest/integrations/groq)
62
-
63
- ### Vector DBs
64
- - [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
65
- - [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
66
- - [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant)
67
-
68
- ### Frameworks
69
- - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
70
- - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
71
- - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
72
- - [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack)
52
+ ## Auto Instrumentation Capabilities
53
+
54
+ | LLMs | Vector DBs | Frameworks |
55
+ |----------------------------------------------------------|----------------------------------------------|----------------------------------------------|
56
+ | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
57
+ | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
58
+ | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
59
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
60
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
61
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
62
+ | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
63
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
64
+ | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
65
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
73
66
 
74
67
  ## Supported Destinations
75
68
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -91,14 +84,16 @@ pip install openlit
91
84
 
92
85
  ## 🚀 Getting Started
93
86
 
94
- ## Step 1: Install OpenLIT SDK
87
+ ### Step 1: Install OpenLIT
88
+
89
+ Open your command line or terminal and run:
95
90
 
96
91
  ```bash
97
92
  pip install openlit
98
93
  ```
99
94
 
100
- ### Step 2: Instrument your Application
101
- Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **one line of code**:
95
+ ### Step 2: Initialize OpenLIT in your Application
96
+ Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **two lines of code**:
102
97
 
103
98
  ```python
104
99
  import openlit
@@ -106,46 +101,68 @@ import openlit
106
101
  openlit.init()
107
102
  ```
108
103
 
109
- By default, OpenLIT directs traces and metrics straight to your console. To forward telemetry data to an HTTP OTLP endpoint, such as the OpenTelemetry Collector, set the `otlp_endpoint` parameter with the desired endpoint. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable as recommended in the OpenTelemetry documentation.
104
+ To forward telemetry data to an HTTP OTLP endpoint, such as the OpenTelemetry Collector, set the `otlp_endpoint` parameter with the desired endpoint. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable as recommended in the OpenTelemetry documentation.
105
+
106
+ > 💡 Info: If you dont provide `otlp_endpoint` function argument or set the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable, OpenLIT directs the trace directly to your console, which can be useful during development.
110
107
 
111
108
  To send telemetry to OpenTelemetry backends requiring authentication, set the `otlp_headers` parameter with its desired value. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_HEADERS` environment variable as recommended in the OpenTelemetry documentation.
112
109
 
113
110
  #### Example
114
111
 
115
- Here is how you can send telemetry from OpenLIT to Grafana Cloud
112
+ ---
116
113
 
117
- ```python
118
- openlit.init(
119
- otlp_endpoint="https://otlp-gateway-prod-us-east-0.grafana.net/otlp",
120
- otlp_headers="Authorization=Basic%20<base64 encoded Instance ID and API Token>"
121
- )
122
- ```
114
+ <details>
115
+ <summary>Initialize using Function Arguments</summary>
116
+
117
+ ---
123
118
 
124
- Alternatively, You can also choose to set these values using `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_EXPORTER_OTLP_HEADERS` environment variables
119
+ Add the following two lines to your application code:
120
+
121
+ ```python
122
+ import openlit
123
+
124
+ openlit.init(
125
+ otlp_endpoint="YOUR_OTEL_ENDPOINT",
126
+ otlp_headers ="YOUR_OTEL_ENDPOINT_AUTH"
127
+ )
128
+ ```
125
129
 
126
- ```python
127
- openlit.init()
128
- ```
130
+ </details>
129
131
 
130
- ```env
131
- export OTEL_EXPORTER_OTLP_ENDPOINT = "https://otlp-gateway-prod-us-east-0.grafana.net/otlp"
132
- export OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic%20<base64 encoded Instance ID and API Token>"
133
- ```
132
+ ---
133
+
134
+ <details>
135
+
136
+ <summary>Initialize using Environment Variables</summary>
137
+
138
+ ---
139
+
140
+ Add the following two lines to your application code:
141
+
142
+ ```python
143
+ import openlit
144
+
145
+ openlit.init()
146
+ ```
147
+
148
+ Then, configure the your OTLP endpoint using environment variable:
149
+
150
+ ```env
151
+ export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"
152
+ export OTEL_EXPORTER_OTLP_HEADERS = "YOUR_OTEL_ENDPOINT_AUTH"
153
+ ```
154
+ </details>
155
+
156
+ ---
134
157
 
135
158
  ### Step 3: Visualize and Optimize!
136
- With the LLM Observability data now being collected and sent to your chosen OpenTelemetry backend, the next step is to visualize and analyze this data to glean insights into your application's performance, behavior, and identify areas of improvement. Here is how you would use the data in Grafana, follow these detailed instructions to explore your LLM application's Telemetry data.
159
+ With the LLM Observability data now being collected and sent to OpenLIT, the next step is to visualize and analyze this data to get insights into your LLM applications performance, behavior, and identify areas of improvement.
137
160
 
138
- - Select the **Explore** option from Grafana's sidebar.
139
- - At the top, ensure the correct Tempo data source is selected from the dropdown menu.
140
- - Use the **Query** field to specify any particular traces you are interested in, or leave it empty to browse through all the available traces.
141
- - You can adjust the time range to focus on specific periods of interest.
142
- - Hit **Run Query** to fetch your trace data. You'll see a visual representation of your traces along with detailed information on particular spans when clicked.
161
+ To begin exploring your LLM Application's performance data within the OpenLIT UI, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
143
162
 
144
- #### Next Steps
163
+ If you want to integrate and send metrics and traces to your existing observability tools, refer to our [Connections Guide](https://docs.openlit.io/latest/connections/intro) for detailed instructions.
145
164
 
146
- - **Create Dashboards:** Beyond just exploring traces, consider creating dashboards in Grafana to monitor key performance indicators (KPIs) and metrics over time. Dashboards can be customized with various panels to display graphs, logs, and single stats that are most relevant to your application's performance and usage patterns.
147
- - **Set Alerts:** Grafana also allows you to set up alerts based on specific thresholds. This feature can be invaluable in proactively managing your application's health by notifying you of potential issues before they impact users.
148
- - **Iterate and Optimize:** Use the insights gained from your observability data to make informed decisions on optimizing your LLM application. This might involve refining model parameters, adjusting scaling strategies, or identifying and resolving bottlenecks.
165
+ ![](https://github.com/openlit/.github/blob/main/profile/assets/openlit-client-1.png?raw=true)
149
166
 
150
167
 
151
168
  ### Configuration
@@ -162,8 +179,9 @@ Below is a detailed overview of the configuration options available, allowing yo
162
179
  | `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No |
163
180
  | `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |
164
181
  | `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
165
- | `disabled_instrumentors`| List of instrumentors to disable. Choices: `["openai", "anthropic", "langchain", "cohere", "mistral", "transformers", "chroma", "pinecone"]`. | `None` | No |
182
+ | `disabled_instrumentors`| List of instrumentors to disable. | `None` | No |
166
183
  | `disable_metrics` | If set, disables the collection of metrics. | `False` | No |
184
+ | `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
167
185
 
168
186
  ## 🌱 Contributing
169
187
 
@@ -182,5 +200,5 @@ Connect with the OpenLIT community and maintainers for support, discussions, and
182
200
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
183
201
  - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) Community for live interactions and questions.
184
202
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
185
- - 𝕏 Follow us on [X](https://twitter.com/openlit) for the latest updates and news.
203
+ - 𝕏 Follow us on [X](https://x.com/openlit_io) for the latest updates and news.
186
204
 
@@ -13,6 +13,9 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
13
13
  [![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack&logoColor=white)](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ)
14
14
  [![X](https://img.shields.io/badge/follow-%40OpenLIT-1DA1F2?logo=x&style=social)](https://twitter.com/openlit_io)
15
15
 
16
+ ![OpenLIT Connections Banner](https://github.com/openlit/.github/blob/main/profile/assets/github-readme-connections-banner.png?raw=true)
17
+
18
+
16
19
  </div>
17
20
 
18
21
  OpenLIT Python SDK is an **OpenTelemetry-native** Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects. Designed with simplicity and efficiency, OpenLIT offers the ability to embed observability into your GenAI-driven projects effortlessly using just **a single line of code**.
@@ -21,30 +24,20 @@ Whether you're directly using LLM Libraries like OpenAI, Anthropic or building c
21
24
 
22
25
  This project adheres to the [Semantic Conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai) proposed by the OpenTelemetry community. You can check out the current definitions [here](src/openlit/semcov/__init__.py).
23
26
 
24
- ## What can be Auto Instrumented?
25
-
26
- ### LLMs
27
- - [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai)
28
- - [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama)
29
- - [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic)
30
- - [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere)
31
- - [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral)
32
- - [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai)
33
- - [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface)
34
- - [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock)
35
- - [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai)
36
- - [✅ Groq](https://docs.openlit.io/latest/integrations/groq)
37
-
38
- ### Vector DBs
39
- - [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
40
- - [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
41
- - [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant)
42
-
43
- ### Frameworks
44
- - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
45
- - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
46
- - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
47
- - [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack)
27
+ ## Auto Instrumentation Capabilities
28
+
29
+ | LLMs | Vector DBs | Frameworks |
30
+ |----------------------------------------------------------|----------------------------------------------|----------------------------------------------|
31
+ | [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai) | [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb) | [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain) |
32
+ | [✅ Ollama](https://docs.openlit.io/latest/integrations/ollama) | [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone) | [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm) |
33
+ | [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic) | [✅ Qdrant](https://docs.openlit.io/latest/integrations/qdrant) | [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index) |
34
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
35
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
36
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
37
+ | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
38
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
39
+ | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
40
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
48
41
 
49
42
  ## Supported Destinations
50
43
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -66,14 +59,16 @@ pip install openlit
66
59
 
67
60
  ## 🚀 Getting Started
68
61
 
69
- ## Step 1: Install OpenLIT SDK
62
+ ### Step 1: Install OpenLIT
63
+
64
+ Open your command line or terminal and run:
70
65
 
71
66
  ```bash
72
67
  pip install openlit
73
68
  ```
74
69
 
75
- ### Step 2: Instrument your Application
76
- Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **one line of code**:
70
+ ### Step 2: Initialize OpenLIT in your Application
71
+ Integrating the OpenLIT into LLM applications is straightforward. Start monitoring for your LLM Application with just **two lines of code**:
77
72
 
78
73
  ```python
79
74
  import openlit
@@ -81,46 +76,68 @@ import openlit
81
76
  openlit.init()
82
77
  ```
83
78
 
84
- By default, OpenLIT directs traces and metrics straight to your console. To forward telemetry data to an HTTP OTLP endpoint, such as the OpenTelemetry Collector, set the `otlp_endpoint` parameter with the desired endpoint. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable as recommended in the OpenTelemetry documentation.
79
+ To forward telemetry data to an HTTP OTLP endpoint, such as the OpenTelemetry Collector, set the `otlp_endpoint` parameter with the desired endpoint. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable as recommended in the OpenTelemetry documentation.
80
+
81
+ > 💡 Info: If you dont provide `otlp_endpoint` function argument or set the `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable, OpenLIT directs the trace directly to your console, which can be useful during development.
85
82
 
86
83
  To send telemetry to OpenTelemetry backends requiring authentication, set the `otlp_headers` parameter with its desired value. Alternatively, you can configure the endpoint by setting the `OTEL_EXPORTER_OTLP_HEADERS` environment variable as recommended in the OpenTelemetry documentation.
87
84
 
88
85
  #### Example
89
86
 
90
- Here is how you can send telemetry from OpenLIT to Grafana Cloud
87
+ ---
91
88
 
92
- ```python
93
- openlit.init(
94
- otlp_endpoint="https://otlp-gateway-prod-us-east-0.grafana.net/otlp",
95
- otlp_headers="Authorization=Basic%20<base64 encoded Instance ID and API Token>"
96
- )
97
- ```
89
+ <details>
90
+ <summary>Initialize using Function Arguments</summary>
91
+
92
+ ---
98
93
 
99
- Alternatively, You can also choose to set these values using `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_EXPORTER_OTLP_HEADERS` environment variables
94
+ Add the following two lines to your application code:
95
+
96
+ ```python
97
+ import openlit
98
+
99
+ openlit.init(
100
+ otlp_endpoint="YOUR_OTEL_ENDPOINT",
101
+ otlp_headers ="YOUR_OTEL_ENDPOINT_AUTH"
102
+ )
103
+ ```
100
104
 
101
- ```python
102
- openlit.init()
103
- ```
105
+ </details>
104
106
 
105
- ```env
106
- export OTEL_EXPORTER_OTLP_ENDPOINT = "https://otlp-gateway-prod-us-east-0.grafana.net/otlp"
107
- export OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic%20<base64 encoded Instance ID and API Token>"
108
- ```
107
+ ---
108
+
109
+ <details>
110
+
111
+ <summary>Initialize using Environment Variables</summary>
112
+
113
+ ---
114
+
115
+ Add the following two lines to your application code:
116
+
117
+ ```python
118
+ import openlit
119
+
120
+ openlit.init()
121
+ ```
122
+
123
+ Then, configure the your OTLP endpoint using environment variable:
124
+
125
+ ```env
126
+ export OTEL_EXPORTER_OTLP_ENDPOINT = "YOUR_OTEL_ENDPOINT"
127
+ export OTEL_EXPORTER_OTLP_HEADERS = "YOUR_OTEL_ENDPOINT_AUTH"
128
+ ```
129
+ </details>
130
+
131
+ ---
109
132
 
110
133
  ### Step 3: Visualize and Optimize!
111
- With the LLM Observability data now being collected and sent to your chosen OpenTelemetry backend, the next step is to visualize and analyze this data to glean insights into your application's performance, behavior, and identify areas of improvement. Here is how you would use the data in Grafana, follow these detailed instructions to explore your LLM application's Telemetry data.
134
+ With the LLM Observability data now being collected and sent to OpenLIT, the next step is to visualize and analyze this data to get insights into your LLM applications performance, behavior, and identify areas of improvement.
112
135
 
113
- - Select the **Explore** option from Grafana's sidebar.
114
- - At the top, ensure the correct Tempo data source is selected from the dropdown menu.
115
- - Use the **Query** field to specify any particular traces you are interested in, or leave it empty to browse through all the available traces.
116
- - You can adjust the time range to focus on specific periods of interest.
117
- - Hit **Run Query** to fetch your trace data. You'll see a visual representation of your traces along with detailed information on particular spans when clicked.
136
+ To begin exploring your LLM Application's performance data within the OpenLIT UI, please see the [Quickstart Guide](https://docs.openlit.io/latest/quickstart).
118
137
 
119
- #### Next Steps
138
+ If you want to integrate and send metrics and traces to your existing observability tools, refer to our [Connections Guide](https://docs.openlit.io/latest/connections/intro) for detailed instructions.
120
139
 
121
- - **Create Dashboards:** Beyond just exploring traces, consider creating dashboards in Grafana to monitor key performance indicators (KPIs) and metrics over time. Dashboards can be customized with various panels to display graphs, logs, and single stats that are most relevant to your application's performance and usage patterns.
122
- - **Set Alerts:** Grafana also allows you to set up alerts based on specific thresholds. This feature can be invaluable in proactively managing your application's health by notifying you of potential issues before they impact users.
123
- - **Iterate and Optimize:** Use the insights gained from your observability data to make informed decisions on optimizing your LLM application. This might involve refining model parameters, adjusting scaling strategies, or identifying and resolving bottlenecks.
140
+ ![](https://github.com/openlit/.github/blob/main/profile/assets/openlit-client-1.png?raw=true)
124
141
 
125
142
 
126
143
  ### Configuration
@@ -137,8 +154,9 @@ Below is a detailed overview of the configuration options available, allowing yo
137
154
  | `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No |
138
155
  | `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |
139
156
  | `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
140
- | `disabled_instrumentors`| List of instrumentors to disable. Choices: `["openai", "anthropic", "langchain", "cohere", "mistral", "transformers", "chroma", "pinecone"]`. | `None` | No |
157
+ | `disabled_instrumentors`| List of instrumentors to disable. | `None` | No |
141
158
  | `disable_metrics` | If set, disables the collection of metrics. | `False` | No |
159
+ | `pricing_json` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
142
160
 
143
161
  ## 🌱 Contributing
144
162
 
@@ -157,4 +175,4 @@ Connect with the OpenLIT community and maintainers for support, discussions, and
157
175
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
158
176
  - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) Community for live interactions and questions.
159
177
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
160
- - 𝕏 Follow us on [X](https://twitter.com/openlit) for the latest updates and news.
178
+ - 𝕏 Follow us on [X](https://x.com/openlit_io) for the latest updates and news.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "1.6.0"
3
+ version = "1.9.0"
4
4
  description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects"
5
5
  authors = ["OpenLIT"]
6
6
  repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
@@ -2,8 +2,9 @@
2
2
  """
3
3
  This module has functions to calculate model costs based on tokens and to fetch pricing information.
4
4
  """
5
-
5
+ import json
6
6
  import logging
7
+ from urllib.parse import urlparse
7
8
  import requests
8
9
  import tiktoken
9
10
  from opentelemetry.trace import Status, StatusCode
@@ -122,11 +123,35 @@ def get_audio_model_cost(model, pricing_info, prompt):
122
123
  cost = 0
123
124
  return cost
124
125
 
125
- def fetch_pricing_info():
126
- """Fetches pricing information from a specified URL."""
127
- pricing_url = "https://raw.githubusercontent.com/openlit/openlit/main/assets/pricing.json"
126
+ def fetch_pricing_info(pricing_json=None):
127
+ """
128
+ Fetches pricing information from a specified URL or File Path.
129
+
130
+ Args:
131
+ pricing_json(str): path or url to the pricing json file
132
+
133
+ Returns:
134
+ dict: The pricing json
135
+ """
136
+ if pricing_json:
137
+ is_url = urlparse(pricing_json).scheme != ""
138
+ if is_url:
139
+ pricing_url = pricing_json
140
+ else:
141
+ try:
142
+ with open(pricing_json, mode='r', encoding='utf-8') as f:
143
+ return json.load(f)
144
+ except FileNotFoundError:
145
+ logger.error("Pricing information file not found: %s", pricing_json)
146
+ except json.JSONDecodeError:
147
+ logger.error("Error decoding JSON from file: %s", pricing_json)
148
+ except Exception as file_err:
149
+ logger.error("Unexpected error occurred while reading file: %s", file_err)
150
+ return {}
151
+ else:
152
+ pricing_url = "https://raw.githubusercontent.com/openlit/openlit/main/assets/pricing.json"
128
153
  try:
129
- # Set a timeout of 10 seconds for both the connection and the read
154
+ # Set a timeout of 10 seconds for both the connection and the read
130
155
  response = requests.get(pricing_url, timeout=20)
131
156
  response.raise_for_status()
132
157
  return response.json()
@@ -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.
@@ -74,7 +75,8 @@ class OpenlitConfig:
74
75
 
75
76
  @classmethod
76
77
  def update_config(cls, environment, application_name, tracer, otlp_endpoint,
77
- otlp_headers, disable_batch, trace_content, metrics_dict, disable_metrics):
78
+ otlp_headers, disable_batch, trace_content, metrics_dict,
79
+ disable_metrics, pricing_json):
78
80
  """
79
81
  Updates the configuration based on provided parameters.
80
82
 
@@ -87,10 +89,11 @@ class OpenlitConfig:
87
89
  otlp_headers (Dict[str, str]): OTLP headers.
88
90
  disable_batch (bool): Disable batch span processing flag.
89
91
  trace_content (bool): Enable or disable content tracing.
92
+ pricing_json(str): path or url to the pricing json file
90
93
  """
91
94
  cls.environment = environment
92
95
  cls.application_name = application_name
93
- cls.pricing_info = fetch_pricing_info()
96
+ cls.pricing_info = fetch_pricing_info(pricing_json)
94
97
  cls.tracer = tracer
95
98
  cls.metrics_dict = metrics_dict
96
99
  cls.otlp_endpoint = otlp_endpoint
@@ -125,7 +128,7 @@ def instrument_if_available(instrumentor_name, instrumentor_instance, config,
125
128
 
126
129
  def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
127
130
  otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
128
- meter=None, disable_metrics=False):
131
+ meter=None, disable_metrics=False, pricing_json=None):
129
132
  """
130
133
  Initializes the openLIT configuration and setups tracing.
131
134
 
@@ -143,6 +146,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
143
146
  trace_content (bool): Flag to trace content (Optional).
144
147
  disabled_instrumentors (List[str]): Optional. List of instrumentor names to disable.
145
148
  disable_metrics (bool): Flag to disable metrics (Optional)
149
+ pricing_json(str): File path or url to the pricing json (Optional)
146
150
  """
147
151
  disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
148
152
  # Check for invalid instrumentor names
@@ -162,6 +166,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
162
166
  "chroma": "chromadb",
163
167
  "pinecone": "pinecone",
164
168
  "qdrant": "qdrant_client",
169
+ "milvus": "pymilvus",
165
170
  "transformers": "transformers"
166
171
  }
167
172
 
@@ -197,7 +202,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
197
202
  # Update global configuration with the provided settings.
198
203
  config.update_config(environment, application_name, tracer, otlp_endpoint,
199
204
  otlp_headers, disable_batch, trace_content,
200
- metrics_dict, disable_metrics)
205
+ metrics_dict, disable_metrics, pricing_json)
201
206
 
202
207
  # Map instrumentor names to their instances
203
208
  instrumentor_instances = {
@@ -215,6 +220,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
215
220
  "chroma": ChromaInstrumentor(),
216
221
  "pinecone": PineconeInstrumentor(),
217
222
  "qdrant": QdrantInstrumentor(),
223
+ "milvus": MilvusInstrumentor(),
218
224
  "transformers": TransformersInstrumentor()
219
225
  }
220
226
 
@@ -203,9 +203,9 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
203
203
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
204
204
  False)
205
205
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
206
- response.response_id)
206
+ response.generation_id)
207
207
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
208
- response.response_id)
208
+ response.finish_reason)
209
209
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
210
210
  response.meta.billed_units.input_tokens)
211
211
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -306,10 +306,11 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
306
306
  # Collect message IDs and aggregated response from events
307
307
  if event.event_type == "stream-end":
308
308
  llmresponse = event.response.text
309
- response_id = event.response.response_id
310
309
  prompt_tokens = event.response.meta.billed_units.input_tokens
311
310
  completion_tokens = event.response.meta.billed_units.output_tokens
312
311
  finish_reason = event.finish_reason
312
+ if event.event_type == "stream-start":
313
+ response_id = event.generation_id
313
314
  yield event
314
315
 
315
316
  # Handling exception ensure observability without disrupting operation
@@ -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"
File without changes