openlit 1.7.0__tar.gz → 1.10.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 (51) hide show
  1. {openlit-1.7.0 → openlit-1.10.0}/PKG-INFO +74 -57
  2. {openlit-1.7.0 → openlit-1.10.0}/README.md +73 -56
  3. {openlit-1.7.0 → openlit-1.10.0}/pyproject.toml +1 -1
  4. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/__helpers.py +30 -5
  5. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/__init__.py +10 -4
  6. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/chroma/chroma.py +23 -21
  7. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/cohere/cohere.py +4 -3
  8. openlit-1.10.0/src/openlit/instrumentation/embedchain/__init__.py +55 -0
  9. openlit-1.10.0/src/openlit/instrumentation/embedchain/embedchain.py +165 -0
  10. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/llamaindex/__init__.py +1 -1
  11. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/qdrant/qdrant.py +5 -5
  12. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/semcov/__init__.py +7 -0
  13. {openlit-1.7.0 → openlit-1.10.0}/LICENSE +0 -0
  14. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  15. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  16. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  17. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  18. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  19. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  20. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  21. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/__init__.py +0 -0
  22. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  23. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/groq/groq.py +0 -0
  24. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  25. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  26. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  27. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  28. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  29. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  30. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  31. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  32. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  33. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  34. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  35. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  36. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  37. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
  38. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  39. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  40. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  41. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/openai/openai.py +0 -0
  42. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  43. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  44. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  45. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  46. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  47. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  48. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  49. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  50. {openlit-1.7.0 → openlit-1.10.0}/src/openlit/otel/metrics.py +0 -0
  51. {openlit-1.7.0 → openlit-1.10.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.7.0
3
+ Version: 1.10.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,31 +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
- - [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus)
68
-
69
- ### Frameworks
70
- - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
71
- - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
72
- - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
73
- - [✅ 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) | |
74
66
 
75
67
  ## Supported Destinations
76
68
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -92,14 +84,16 @@ pip install openlit
92
84
 
93
85
  ## 🚀 Getting Started
94
86
 
95
- ## Step 1: Install OpenLIT SDK
87
+ ### Step 1: Install OpenLIT
88
+
89
+ Open your command line or terminal and run:
96
90
 
97
91
  ```bash
98
92
  pip install openlit
99
93
  ```
100
94
 
101
- ### Step 2: Instrument your Application
102
- 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**:
103
97
 
104
98
  ```python
105
99
  import openlit
@@ -107,46 +101,68 @@ import openlit
107
101
  openlit.init()
108
102
  ```
109
103
 
110
- 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.
111
107
 
112
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.
113
109
 
114
110
  #### Example
115
111
 
116
- Here is how you can send telemetry from OpenLIT to Grafana Cloud
112
+ ---
117
113
 
118
- ```python
119
- openlit.init(
120
- otlp_endpoint="https://otlp-gateway-prod-us-east-0.grafana.net/otlp",
121
- otlp_headers="Authorization=Basic%20<base64 encoded Instance ID and API Token>"
122
- )
123
- ```
114
+ <details>
115
+ <summary>Initialize using Function Arguments</summary>
116
+
117
+ ---
124
118
 
125
- 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
+ ```
126
129
 
127
- ```python
128
- openlit.init()
129
- ```
130
+ </details>
130
131
 
131
- ```env
132
- export OTEL_EXPORTER_OTLP_ENDPOINT = "https://otlp-gateway-prod-us-east-0.grafana.net/otlp"
133
- export OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic%20<base64 encoded Instance ID and API Token>"
134
- ```
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
+ ---
135
157
 
136
158
  ### Step 3: Visualize and Optimize!
137
- 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.
138
160
 
139
- - Select the **Explore** option from Grafana's sidebar.
140
- - At the top, ensure the correct Tempo data source is selected from the dropdown menu.
141
- - Use the **Query** field to specify any particular traces you are interested in, or leave it empty to browse through all the available traces.
142
- - You can adjust the time range to focus on specific periods of interest.
143
- - 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).
144
162
 
145
- #### 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.
146
164
 
147
- - **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.
148
- - **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.
149
- - **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)
150
166
 
151
167
 
152
168
  ### Configuration
@@ -163,8 +179,9 @@ Below is a detailed overview of the configuration options available, allowing yo
163
179
  | `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No |
164
180
  | `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |
165
181
  | `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
166
- | `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 |
167
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 |
168
185
 
169
186
  ## 🌱 Contributing
170
187
 
@@ -183,5 +200,5 @@ Connect with the OpenLIT community and maintainers for support, discussions, and
183
200
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
184
201
  - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) Community for live interactions and questions.
185
202
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
186
- - 𝕏 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.
187
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,31 +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
- - [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus)
43
-
44
- ### Frameworks
45
- - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
46
- - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
47
- - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
48
- - [✅ 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) | |
49
41
 
50
42
  ## Supported Destinations
51
43
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -67,14 +59,16 @@ pip install openlit
67
59
 
68
60
  ## 🚀 Getting Started
69
61
 
70
- ## Step 1: Install OpenLIT SDK
62
+ ### Step 1: Install OpenLIT
63
+
64
+ Open your command line or terminal and run:
71
65
 
72
66
  ```bash
73
67
  pip install openlit
74
68
  ```
75
69
 
76
- ### Step 2: Instrument your Application
77
- 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**:
78
72
 
79
73
  ```python
80
74
  import openlit
@@ -82,46 +76,68 @@ import openlit
82
76
  openlit.init()
83
77
  ```
84
78
 
85
- 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.
86
82
 
87
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.
88
84
 
89
85
  #### Example
90
86
 
91
- Here is how you can send telemetry from OpenLIT to Grafana Cloud
87
+ ---
92
88
 
93
- ```python
94
- openlit.init(
95
- otlp_endpoint="https://otlp-gateway-prod-us-east-0.grafana.net/otlp",
96
- otlp_headers="Authorization=Basic%20<base64 encoded Instance ID and API Token>"
97
- )
98
- ```
89
+ <details>
90
+ <summary>Initialize using Function Arguments</summary>
91
+
92
+ ---
99
93
 
100
- 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
+ ```
101
104
 
102
- ```python
103
- openlit.init()
104
- ```
105
+ </details>
105
106
 
106
- ```env
107
- export OTEL_EXPORTER_OTLP_ENDPOINT = "https://otlp-gateway-prod-us-east-0.grafana.net/otlp"
108
- export OTEL_EXPORTER_OTLP_HEADERS = "Authorization=Basic%20<base64 encoded Instance ID and API Token>"
109
- ```
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
+ ---
110
132
 
111
133
  ### Step 3: Visualize and Optimize!
112
- 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.
113
135
 
114
- - Select the **Explore** option from Grafana's sidebar.
115
- - At the top, ensure the correct Tempo data source is selected from the dropdown menu.
116
- - Use the **Query** field to specify any particular traces you are interested in, or leave it empty to browse through all the available traces.
117
- - You can adjust the time range to focus on specific periods of interest.
118
- - 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).
119
137
 
120
- #### 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.
121
139
 
122
- - **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.
123
- - **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.
124
- - **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)
125
141
 
126
142
 
127
143
  ### Configuration
@@ -138,8 +154,9 @@ Below is a detailed overview of the configuration options available, allowing yo
138
154
  | `otlp_headers` | Defines headers for the OTLP exporter, useful for backends requiring authentication. | `None` | No |
139
155
  | `disable_batch` | A flag to disable batch span processing, favoring immediate dispatch. | `False` | No |
140
156
  | `trace_content` | Enables tracing of content for deeper insights. | `True` | No |
141
- | `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 |
142
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 |
143
160
 
144
161
  ## 🌱 Contributing
145
162
 
@@ -158,4 +175,4 @@ Connect with the OpenLIT community and maintainers for support, discussions, and
158
175
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
159
176
  - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) Community for live interactions and questions.
160
177
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
161
- - 𝕏 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.7.0"
3
+ version = "1.10.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()
@@ -24,6 +24,7 @@ from openlit.instrumentation.ollama import OllamaInstrumentor
24
24
  from openlit.instrumentation.langchain import LangChainInstrumentor
25
25
  from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
26
26
  from openlit.instrumentation.haystack import HaystackInstrumentor
27
+ from openlit.instrumentation.embedchain import EmbedChainInstrumentor
27
28
  from openlit.instrumentation.chroma import ChromaInstrumentor
28
29
  from openlit.instrumentation.pinecone import PineconeInstrumentor
29
30
  from openlit.instrumentation.qdrant import QdrantInstrumentor
@@ -75,7 +76,8 @@ class OpenlitConfig:
75
76
 
76
77
  @classmethod
77
78
  def update_config(cls, environment, application_name, tracer, otlp_endpoint,
78
- otlp_headers, disable_batch, trace_content, metrics_dict, disable_metrics):
79
+ otlp_headers, disable_batch, trace_content, metrics_dict,
80
+ disable_metrics, pricing_json):
79
81
  """
80
82
  Updates the configuration based on provided parameters.
81
83
 
@@ -88,10 +90,11 @@ class OpenlitConfig:
88
90
  otlp_headers (Dict[str, str]): OTLP headers.
89
91
  disable_batch (bool): Disable batch span processing flag.
90
92
  trace_content (bool): Enable or disable content tracing.
93
+ pricing_json(str): path or url to the pricing json file
91
94
  """
92
95
  cls.environment = environment
93
96
  cls.application_name = application_name
94
- cls.pricing_info = fetch_pricing_info()
97
+ cls.pricing_info = fetch_pricing_info(pricing_json)
95
98
  cls.tracer = tracer
96
99
  cls.metrics_dict = metrics_dict
97
100
  cls.otlp_endpoint = otlp_endpoint
@@ -126,7 +129,7 @@ def instrument_if_available(instrumentor_name, instrumentor_instance, config,
126
129
 
127
130
  def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
128
131
  otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
129
- meter=None, disable_metrics=False):
132
+ meter=None, disable_metrics=False, pricing_json=None):
130
133
  """
131
134
  Initializes the openLIT configuration and setups tracing.
132
135
 
@@ -144,6 +147,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
144
147
  trace_content (bool): Flag to trace content (Optional).
145
148
  disabled_instrumentors (List[str]): Optional. List of instrumentor names to disable.
146
149
  disable_metrics (bool): Flag to disable metrics (Optional)
150
+ pricing_json(str): File path or url to the pricing json (Optional)
147
151
  """
148
152
  disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
149
153
  # Check for invalid instrumentor names
@@ -160,6 +164,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
160
164
  "langchain": "langchain",
161
165
  "llama_index": "llama_index",
162
166
  "haystack": "haystack",
167
+ "embedchain": "embedchain",
163
168
  "chroma": "chromadb",
164
169
  "pinecone": "pinecone",
165
170
  "qdrant": "qdrant_client",
@@ -199,7 +204,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
199
204
  # Update global configuration with the provided settings.
200
205
  config.update_config(environment, application_name, tracer, otlp_endpoint,
201
206
  otlp_headers, disable_batch, trace_content,
202
- metrics_dict, disable_metrics)
207
+ metrics_dict, disable_metrics, pricing_json)
203
208
 
204
209
  # Map instrumentor names to their instances
205
210
  instrumentor_instances = {
@@ -214,6 +219,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
214
219
  "langchain": LangChainInstrumentor(),
215
220
  "llama_index": LlamaIndexInstrumentor(),
216
221
  "haystack": HaystackInstrumentor(),
222
+ "embedchain": EmbedChainInstrumentor(),
217
223
  "chroma": ChromaInstrumentor(),
218
224
  "pinecone": PineconeInstrumentor(),
219
225
  "qdrant": QdrantInstrumentor(),
@@ -16,11 +16,13 @@ def object_count(obj):
16
16
  """
17
17
  Counts Length of object if it exists, Else returns None
18
18
  """
19
+ try:
20
+ cnt = len(obj)
21
+ # pylint: disable=bare-except
22
+ except:
23
+ cnt = 0
19
24
 
20
- if obj:
21
- return len(obj)
22
-
23
- return None
25
+ return cnt
24
26
 
25
27
  def general_wrap(gen_ai_endpoint, version, environment, application_name,
26
28
  tracer, pricing_info, trace_content, metrics, disable_metrics):
@@ -87,24 +89,24 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
87
89
  span.set_attribute(SemanticConvetion.DB_OPERATION,
88
90
  SemanticConvetion.DB_OPERATION_ADD)
89
91
  span.set_attribute(SemanticConvetion.DB_ID_COUNT,
90
- object_count(kwargs.get("ids")))
92
+ object_count(kwargs.get("ids", [])))
91
93
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
92
- object_count(kwargs.get("embeddings")))
94
+ object_count(kwargs.get("embeddings", [])))
93
95
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
94
- object_count(kwargs.get("metadatas")))
96
+ object_count(kwargs.get("metadatas", [])))
95
97
  span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
96
- object_count(kwargs.get("documents")))
98
+ object_count(kwargs.get("documents", [])))
97
99
 
98
100
  elif gen_ai_endpoint == "chroma.get":
99
101
  db_operation = SemanticConvetion.DB_OPERATION_GET
100
102
  span.set_attribute(SemanticConvetion.DB_OPERATION,
101
103
  SemanticConvetion.DB_OPERATION_GET)
102
104
  span.set_attribute(SemanticConvetion.DB_ID_COUNT,
103
- object_count(kwargs.get("ids")))
105
+ object_count(kwargs.get("ids", [])))
104
106
  span.set_attribute(SemanticConvetion.DB_QUERY_LIMIT,
105
- kwargs.get("limit"))
107
+ kwargs.get("limit", ""))
106
108
  span.set_attribute(SemanticConvetion.DB_OFFSET,
107
- kwargs.get("offset"))
109
+ kwargs.get("offset", ""))
108
110
  span.set_attribute(SemanticConvetion.DB_WHERE_DOCUMENT,
109
111
  str(kwargs.get("where_document", "")))
110
112
 
@@ -113,7 +115,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
113
115
  span.set_attribute(SemanticConvetion.DB_OPERATION,
114
116
  SemanticConvetion.DB_OPERATION_QUERY)
115
117
  span.set_attribute(SemanticConvetion.DB_STATEMENT,
116
- str(kwargs.get("query_texts")))
118
+ str(kwargs.get("query_texts", "")))
117
119
  span.set_attribute(SemanticConvetion.DB_N_RESULTS,
118
120
  kwargs.get("n_results", ""))
119
121
  span.set_attribute(SemanticConvetion.DB_FILTER,
@@ -126,33 +128,33 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
126
128
  span.set_attribute(SemanticConvetion.DB_OPERATION,
127
129
  SemanticConvetion.DB_OPERATION_UPDATE)
128
130
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
129
- object_count(kwargs.get("embeddings")))
131
+ object_count(kwargs.get("embeddings", [])))
130
132
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
131
- object_count(kwargs.get("metadatas")))
133
+ object_count(kwargs.get("metadatas", [])))
132
134
  span.set_attribute(SemanticConvetion.DB_ID_COUNT,
133
- object_count(kwargs.get("ids")))
135
+ object_count(kwargs.get("ids", [])))
134
136
  span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
135
- object_count(kwargs.get("documents")))
137
+ object_count(kwargs.get("documents", [])))
136
138
 
137
139
  elif gen_ai_endpoint == "chroma.upsert":
138
140
  db_operation = SemanticConvetion.DB_OPERATION_UPSERT
139
141
  span.set_attribute(SemanticConvetion.DB_OPERATION,
140
142
  SemanticConvetion.DB_OPERATION_UPSERT)
141
143
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
142
- object_count(kwargs.get("embeddings")))
144
+ object_count(kwargs.get("embeddings", [])))
143
145
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
144
- object_count(kwargs.get("metadatas")))
146
+ object_count(kwargs.get("metadatas", [])))
145
147
  span.set_attribute(SemanticConvetion.DB_ID_COUNT,
146
- object_count(kwargs.get("ids")))
148
+ object_count(kwargs.get("ids", [])))
147
149
  span.set_attribute(SemanticConvetion.DB_DOCUMENTS_COUNT,
148
- object_count(kwargs.get("documents")))
150
+ object_count(kwargs.get("documents", [])))
149
151
 
150
152
  elif gen_ai_endpoint == "chroma.delete":
151
153
  db_operation = SemanticConvetion.DB_OPERATION_DELETE
152
154
  span.set_attribute(SemanticConvetion.DB_OPERATION,
153
155
  SemanticConvetion.DB_OPERATION_DELETE)
154
156
  span.set_attribute(SemanticConvetion.DB_ID_COUNT,
155
- object_count(kwargs.get("ids")))
157
+ object_count(kwargs.get("ids", [])))
156
158
  span.set_attribute(SemanticConvetion.DB_FILTER,
157
159
  str(kwargs.get("where", "")))
158
160
  span.set_attribute(SemanticConvetion.DB_DELETE_ALL,
@@ -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,55 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of EmbedChain 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.embedchain.embedchain import evaluate, get_data_sources
9
+
10
+ _instruments = ("embedchain >= 0.1.104",)
11
+
12
+ WRAPPED_METHODS = [
13
+ {
14
+ "package": "embedchain",
15
+ "object": "App.evaluate",
16
+ "endpoint": "embedchain.evaluate",
17
+ "wrapper": evaluate,
18
+ },
19
+ {
20
+ "package": "embedchain",
21
+ "object": "App.get_data_sources",
22
+ "endpoint": "embedchain.get_data_sources",
23
+ "wrapper": get_data_sources,
24
+ },
25
+ ]
26
+
27
+ class EmbedChainInstrumentor(BaseInstrumentor):
28
+ """An instrumentor for EmbedChain's client library."""
29
+
30
+ def instrumentation_dependencies(self) -> Collection[str]:
31
+ return _instruments
32
+
33
+ def _instrument(self, **kwargs):
34
+ application_name = kwargs.get("application_name")
35
+ environment = kwargs.get("environment")
36
+ tracer = kwargs.get("tracer")
37
+ pricing_info = kwargs.get("pricing_info")
38
+ trace_content = kwargs.get("trace_content")
39
+ version = importlib.metadata.version("embedchain")
40
+
41
+ for wrapped_method in WRAPPED_METHODS:
42
+ wrap_package = wrapped_method.get("package")
43
+ wrap_object = wrapped_method.get("object")
44
+ gen_ai_endpoint = wrapped_method.get("endpoint")
45
+ wrapper = wrapped_method.get("wrapper")
46
+ wrap_function_wrapper(
47
+ wrap_package,
48
+ wrap_object,
49
+ wrapper(gen_ai_endpoint, version, environment, application_name,
50
+ tracer, pricing_info, trace_content),
51
+ )
52
+
53
+ @staticmethod
54
+ def _uninstrument(self, **kwargs):
55
+ pass
@@ -0,0 +1,165 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
2
+ """
3
+ Module for monitoring EmbedChain applications.
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 evaluate(gen_ai_endpoint, version, environment, application_name,
16
+ tracer, pricing_info, trace_content):
17
+ """
18
+ Creates a wrapper around a function call to trace and log its execution metrics.
19
+
20
+ This function wraps any given function to measure its execution time,
21
+ log its operation, and trace its execution using OpenTelemetry.
22
+
23
+ Parameters:
24
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
25
+ - version (str): The version of the EmbedChain application.
26
+ - environment (str): The deployment environment (e.g., 'production', 'development').
27
+ - application_name (str): Name of the EmbedChain application.
28
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
29
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
30
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
31
+
32
+ Returns:
33
+ - function: A higher-order function that takes a function 'wrapped' and returns
34
+ a new function that wraps 'wrapped' with additional tracing and logging.
35
+ """
36
+
37
+ def wrapper(wrapped, instance, args, kwargs):
38
+ """
39
+ An inner wrapper function that executes the wrapped function, measures execution
40
+ time, and records trace data using OpenTelemetry.
41
+
42
+ Parameters:
43
+ - wrapped (Callable): The original function that this wrapper will execute.
44
+ - instance (object): The instance to which the wrapped function belongs. This
45
+ is used for instance methods. For static and classmethods,
46
+ this may be None.
47
+ - args (tuple): Positional arguments passed to the wrapped function.
48
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
49
+
50
+ Returns:
51
+ - The result of the wrapped function call.
52
+
53
+ The wrapper initiates a span with the provided tracer, sets various attributes
54
+ on the span based on the function's execution and response, and ensures
55
+ errors are handled and logged appropriately.
56
+ """
57
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
58
+ response = wrapped(*args, **kwargs)
59
+
60
+ try:
61
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
62
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
63
+ SemanticConvetion.GEN_AI_SYSTEM_EMBEDCHAIN)
64
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
65
+ gen_ai_endpoint)
66
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
67
+ environment)
68
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
69
+ SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
70
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
71
+ application_name)
72
+ span.set_attribute(SemanticConvetion.GEN_AI_EVAL_CONTEXT_RELEVANCY,
73
+ response["context_relevancy"])
74
+ span.set_attribute(SemanticConvetion.GEN_AI_EVAL_ANSWER_RELEVANCY,
75
+ response["answer_relevancy"])
76
+ span.set_attribute(SemanticConvetion.GEN_AI_EVAL_GROUNDEDNESS,
77
+ response["groundedness"])
78
+
79
+ span.set_status(Status(StatusCode.OK))
80
+
81
+ # Return original response
82
+ return response
83
+
84
+ except Exception as e:
85
+ handle_exception(span, e)
86
+ logger.error("Error in trace creation: %s", e)
87
+
88
+ # Return original response
89
+ return response
90
+
91
+ return wrapper
92
+
93
+ def get_data_sources(gen_ai_endpoint, version, environment, application_name,
94
+ tracer, pricing_info, trace_content):
95
+ """
96
+ Creates a wrapper around a function call to trace and log its execution metrics.
97
+
98
+ This function wraps any given function to measure its execution time,
99
+ log its operation, and trace its execution using OpenTelemetry.
100
+
101
+ Parameters:
102
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
103
+ - version (str): The version of the EmbedChain application.
104
+ - environment (str): The deployment environment (e.g., 'production', 'development').
105
+ - application_name (str): Name of the EmbedChain application.
106
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
107
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
108
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
109
+
110
+ Returns:
111
+ - function: A higher-order function that takes a function 'wrapped' and returns
112
+ a new function that wraps 'wrapped' with additional tracing and logging.
113
+ """
114
+
115
+ def wrapper(wrapped, instance, args, kwargs):
116
+ """
117
+ An inner wrapper function that executes the wrapped function, measures execution
118
+ time, and records trace data using OpenTelemetry.
119
+
120
+ Parameters:
121
+ - wrapped (Callable): The original function that this wrapper will execute.
122
+ - instance (object): The instance to which the wrapped function belongs. This
123
+ is used for instance methods. For static and classmethods,
124
+ this may be None.
125
+ - args (tuple): Positional arguments passed to the wrapped function.
126
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
127
+
128
+ Returns:
129
+ - The result of the wrapped function call.
130
+
131
+ The wrapper initiates a span with the provided tracer, sets various attributes
132
+ on the span based on the function's execution and response, and ensures
133
+ errors are handled and logged appropriately.
134
+ """
135
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
136
+ response = wrapped(*args, **kwargs)
137
+
138
+ try:
139
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
140
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
141
+ SemanticConvetion.GEN_AI_SYSTEM_EMBEDCHAIN)
142
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
143
+ gen_ai_endpoint)
144
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
145
+ environment)
146
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
147
+ SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
148
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
149
+ application_name)
150
+ span.set_attribute(SemanticConvetion.GEN_AI_DATA_SOURCES,
151
+ len(response))
152
+
153
+ span.set_status(Status(StatusCode.OK))
154
+
155
+ # Return original response
156
+ return response
157
+
158
+ except Exception as e:
159
+ handle_exception(span, e)
160
+ logger.error("Error in trace creation: %s", e)
161
+
162
+ # Return original response
163
+ return response
164
+
165
+ return wrapper
@@ -25,7 +25,7 @@ WRAPPED_METHODS = [
25
25
  ]
26
26
 
27
27
  class LlamaIndexInstrumentor(BaseInstrumentor):
28
- """An instrumentor for Cohere's client library."""
28
+ """An instrumentor for LlamaIndex's client library."""
29
29
 
30
30
  def instrumentation_dependencies(self) -> Collection[str]:
31
31
  return _instruments
@@ -119,9 +119,9 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
119
119
  span.set_attribute(SemanticConvetion.DB_OPERATION_STATUS,
120
120
  response.status)
121
121
  span.set_attribute(SemanticConvetion.DB_VECTOR_COUNT,
122
- object_count(kwargs.get("points")))
122
+ object_count(kwargs.get("points", [])))
123
123
  span.set_attribute(SemanticConvetion.DB_PAYLOAD_COUNT,
124
- object_count(kwargs.get("payload")))
124
+ object_count(kwargs.get("payload", [])))
125
125
 
126
126
  elif gen_ai_endpoint == "qdrant.retrieve":
127
127
  db_operation = SemanticConvetion.DB_OPERATION_QUERY
@@ -130,7 +130,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
130
130
  span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
131
131
  kwargs.get("collection_name", ""))
132
132
  span.set_attribute(SemanticConvetion.DB_STATEMENT,
133
- str(kwargs.get("ids")))
133
+ str(kwargs.get("ids", "")))
134
134
 
135
135
  elif gen_ai_endpoint == "qdrant.scroll":
136
136
  db_operation = SemanticConvetion.DB_OPERATION_QUERY
@@ -139,7 +139,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
139
139
  span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
140
140
  kwargs.get("collection_name", ""))
141
141
  span.set_attribute(SemanticConvetion.DB_STATEMENT,
142
- str(kwargs.get("scroll_filter")))
142
+ str(kwargs.get("scroll_filter", "")))
143
143
 
144
144
  elif gen_ai_endpoint in ["qdrant.search", "qdrant.search_groups"]:
145
145
  db_operation = SemanticConvetion.DB_OPERATION_QUERY
@@ -148,7 +148,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
148
148
  span.set_attribute(SemanticConvetion.DB_COLLECTION_NAME,
149
149
  kwargs.get("collection_name", ""))
150
150
  span.set_attribute(SemanticConvetion.DB_STATEMENT,
151
- str(kwargs.get("query_vector")))
151
+ str(kwargs.get("query_vector", "")))
152
152
 
153
153
  elif gen_ai_endpoint == "qdrant.recommend":
154
154
  db_operation = SemanticConvetion.DB_OPERATION_QUERY
@@ -26,6 +26,7 @@ class SemanticConvetion:
26
26
  GEN_AI_HUB_REPO = "gen_ai.hub.repo"
27
27
  GEN_AI_RETRIEVAL_SOURCE = "gen_ai.retrieval.source"
28
28
  GEN_AI_REQUESTS = "gen_ai.total.requests"
29
+ GEN_AI_DATA_SOURCES = "gen_ai.data_source_count"
29
30
 
30
31
  # GenAI Request
31
32
  GEN_AI_REQUEST_MODEL = "gen_ai.request.model"
@@ -71,6 +72,11 @@ class SemanticConvetion:
71
72
  GEN_AI_CONTENT_COMPLETION = "gen_ai.content.completion"
72
73
  GEN_AI_CONTENT_REVISED_PROMPT = "gen_ai.content.revised_prompt"
73
74
 
75
+ # GenAI Evaluation Metrics
76
+ GEN_AI_EVAL_CONTEXT_RELEVANCY = "gen_ai.eval.context_relevancy"
77
+ GEN_AI_EVAL_ANSWER_RELEVANCY = "gen_ai.eval.answer_relevancy"
78
+ GEN_AI_EVAL_GROUNDEDNESS = "gen_ai.eval.groundedness"
79
+
74
80
  GEN_AI_TYPE_CHAT = "chat"
75
81
  GEN_AI_TYPE_EMBEDDING = "embedding"
76
82
  GEN_AI_TYPE_IMAGE = "image"
@@ -92,6 +98,7 @@ class SemanticConvetion:
92
98
  GEN_AI_SYSTEM_LANGCHAIN = "langchain"
93
99
  GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
94
100
  GEN_AI_SYSTEM_HAYSTACK = "haystack"
101
+ GEN_AI_SYSTEM_EMBEDCHAIN = "embedchain"
95
102
 
96
103
  # Vector DB
97
104
  DB_REQUESTS = "db.total.requests"
File without changes