openlit 1.9.0__tar.gz → 1.11.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 (53) hide show
  1. {openlit-1.9.0 → openlit-1.11.0}/PKG-INFO +12 -11
  2. {openlit-1.9.0 → openlit-1.11.0}/README.md +11 -10
  3. {openlit-1.9.0 → openlit-1.11.0}/pyproject.toml +1 -1
  4. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/__init__.py +6 -0
  5. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/chroma/chroma.py +23 -21
  6. openlit-1.11.0/src/openlit/instrumentation/embedchain/__init__.py +55 -0
  7. openlit-1.11.0/src/openlit/instrumentation/embedchain/embedchain.py +165 -0
  8. openlit-1.11.0/src/openlit/instrumentation/gpt4all/__init__.py +52 -0
  9. openlit-1.11.0/src/openlit/instrumentation/gpt4all/gpt4all.py +352 -0
  10. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/llamaindex/__init__.py +1 -1
  11. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/qdrant/qdrant.py +5 -5
  12. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/semcov/__init__.py +8 -0
  13. {openlit-1.9.0 → openlit-1.11.0}/LICENSE +0 -0
  14. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/__helpers.py +0 -0
  15. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  16. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  17. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  18. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  19. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  20. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  21. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  22. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/cohere/cohere.py +0 -0
  23. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/groq/__init__.py +0 -0
  24. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  25. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/groq/groq.py +0 -0
  26. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  27. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  28. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  29. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  30. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  31. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  32. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  33. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  34. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  35. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  36. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  37. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  38. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  39. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
  40. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  41. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  42. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  43. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/openai/openai.py +0 -0
  44. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  45. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  46. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  47. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  48. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  49. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  50. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  51. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  52. {openlit-1.9.0 → openlit-1.11.0}/src/openlit/otel/metrics.py +0 -0
  53. {openlit-1.9.0 → openlit-1.11.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.9.0
3
+ Version: 1.11.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
@@ -51,18 +51,19 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
51
51
 
52
52
  ## Auto Instrumentation Capabilities
53
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) | |
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
+ | [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
60
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) |
61
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
62
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
62
63
  | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
63
- | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
64
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
64
65
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
65
- | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
66
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) |
66
67
 
67
68
  ## Supported Destinations
68
69
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -26,18 +26,19 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
26
26
 
27
27
  ## Auto Instrumentation Capabilities
28
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) | |
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
+ | [✅ GPT4All](https://docs.openlit.io/latest/integrations/gpt4all) | [✅ Milvus](https://docs.openlit.io/latest/integrations/milvus) | [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack) |
35
+ | [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere) | | [✅ EmbedChain](https://docs.openlit.io/latest/integrations/embedchain) |
36
+ | [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral) | |
37
+ | [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai) | |
37
38
  | [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface) | |
38
- | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
39
+ | [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock) | |
39
40
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | |
40
- | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | |
41
+ | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) |
41
42
 
42
43
  ## Supported Destinations
43
44
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "1.9.0"
3
+ version = "1.11.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"
@@ -21,9 +21,11 @@ from openlit.instrumentation.bedrock import BedrockInstrumentor
21
21
  from openlit.instrumentation.vertexai import VertexAIInstrumentor
22
22
  from openlit.instrumentation.groq import GroqInstrumentor
23
23
  from openlit.instrumentation.ollama import OllamaInstrumentor
24
+ from openlit.instrumentation.gpt4all import GPT4AllInstrumentor
24
25
  from openlit.instrumentation.langchain import LangChainInstrumentor
25
26
  from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
26
27
  from openlit.instrumentation.haystack import HaystackInstrumentor
28
+ from openlit.instrumentation.embedchain import EmbedChainInstrumentor
27
29
  from openlit.instrumentation.chroma import ChromaInstrumentor
28
30
  from openlit.instrumentation.pinecone import PineconeInstrumentor
29
31
  from openlit.instrumentation.qdrant import QdrantInstrumentor
@@ -160,9 +162,11 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
160
162
  "vertexai": "vertexai",
161
163
  "groq": "groq",
162
164
  "ollama": "ollama",
165
+ "gpt4all": "gpt4all",
163
166
  "langchain": "langchain",
164
167
  "llama_index": "llama_index",
165
168
  "haystack": "haystack",
169
+ "embedchain": "embedchain",
166
170
  "chroma": "chromadb",
167
171
  "pinecone": "pinecone",
168
172
  "qdrant": "qdrant_client",
@@ -214,9 +218,11 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
214
218
  "vertexai": VertexAIInstrumentor(),
215
219
  "groq": GroqInstrumentor(),
216
220
  "ollama": OllamaInstrumentor(),
221
+ "gpt4all": GPT4AllInstrumentor(),
217
222
  "langchain": LangChainInstrumentor(),
218
223
  "llama_index": LlamaIndexInstrumentor(),
219
224
  "haystack": HaystackInstrumentor(),
225
+ "embedchain": EmbedChainInstrumentor(),
220
226
  "chroma": ChromaInstrumentor(),
221
227
  "pinecone": PineconeInstrumentor(),
222
228
  "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,
@@ -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
@@ -0,0 +1,52 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of GPT4All Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.gpt4all.gpt4all import (
10
+ embed, generate
11
+ )
12
+
13
+ _instruments = ("gpt4all >= 2.6.0",)
14
+
15
+ class GPT4AllInstrumentor(BaseInstrumentor):
16
+ """
17
+ An instrumentor for GPT4All's client library.
18
+ """
19
+
20
+ def instrumentation_dependencies(self) -> Collection[str]:
21
+ return _instruments
22
+
23
+ def _instrument(self, **kwargs):
24
+ application_name = kwargs.get("application_name", "default_application")
25
+ environment = kwargs.get("environment", "default_environment")
26
+ tracer = kwargs.get("tracer")
27
+ metrics = kwargs.get("metrics_dict")
28
+ pricing_info = kwargs.get("pricing_info", {})
29
+ trace_content = kwargs.get("trace_content", False)
30
+ disable_metrics = kwargs.get("disable_metrics")
31
+ version = importlib.metadata.version("gpt4all")
32
+
33
+ # generate
34
+ wrap_function_wrapper(
35
+ "gpt4all",
36
+ "GPT4All.generate",
37
+ generate("gpt4all.generate", version, environment, application_name,
38
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
39
+ )
40
+
41
+ # embed
42
+ wrap_function_wrapper(
43
+ "gpt4all",
44
+ "Embed4All.embed",
45
+ embed("gpt4all.embed", version, environment, application_name,
46
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
47
+ )
48
+
49
+
50
+ def _uninstrument(self, **kwargs):
51
+ # Proper uninstrumentation logic to revert patched methods
52
+ pass
@@ -0,0 +1,352 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
+ """
3
+ Module for monitoring GPT4All API calls.
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, general_tokens
10
+ from openlit.semcov import SemanticConvetion
11
+
12
+ # Initialize logger for logging potential issues and operations
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def generate(gen_ai_endpoint, version, environment, application_name,
16
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
17
+ """
18
+ Generates a telemetry wrapper for generate to collect metrics.
19
+
20
+ Args:
21
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
22
+ version: Version of the monitoring package.
23
+ environment: Deployment environment (e.g., production, staging).
24
+ application_name: Name of the application using the GPT4All API.
25
+ tracer: OpenTelemetry tracer for creating spans.
26
+ pricing_info: Information used for calculating the cost of GPT4All usage.
27
+ trace_content: Flag indicating whether to trace the actual content.
28
+
29
+ Returns:
30
+ A function that wraps the generate method to add telemetry.
31
+ """
32
+
33
+ def wrapper(wrapped, instance, args, kwargs):
34
+ """
35
+ Wraps the 'generate' API call to add telemetry.
36
+
37
+ This collects metrics such as execution time, cost, and token usage, and handles errors
38
+ gracefully, adding details to the trace for observability.
39
+
40
+ Args:
41
+ wrapped: The original 'generate' method to be wrapped.
42
+ instance: The instance of the class where the original method is defined.
43
+ args: Positional arguments for the 'generate' method.
44
+ kwargs: Keyword arguments for the 'generate' method.
45
+
46
+ Returns:
47
+ The response from the original 'generate' method.
48
+ """
49
+
50
+ # Check if streaming is enabled for the API call
51
+ streaming = kwargs.get("streaming", False)
52
+
53
+ # pylint: disable=no-else-return
54
+ if streaming:
55
+ # Special handling for streaming response to accommodate the nature of data flow
56
+ def stream_generator():
57
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
58
+ # Placeholder for aggregating streaming response
59
+ llmresponse = ""
60
+
61
+ # Loop through streaming events capturing relevant details
62
+ for chunk in wrapped(*args, **kwargs):
63
+ # Collect aggregated response from events
64
+ llmresponse += chunk
65
+
66
+ yield chunk
67
+
68
+ # Handling exception ensure observability without disrupting operation
69
+ try:
70
+ # Calculate cost of the operation
71
+ cost = 0
72
+
73
+ # pylint: disable=line-too-long
74
+ model = str(instance.model.model_path).rsplit('/', maxsplit=1)[-1] or "orca-mini-3b-gguf2-q4_0.gguf"
75
+ prompt = kwargs.get("prompt") or args[0] or ""
76
+
77
+ # Calculate cost of the operation
78
+ cost = 0
79
+ prompt_tokens = general_tokens(prompt)
80
+ completion_tokens = general_tokens(llmresponse)
81
+ total_tokens = prompt_tokens + completion_tokens
82
+
83
+ # Set base span attribues
84
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
85
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
86
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
87
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
88
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
89
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
90
+ gen_ai_endpoint)
91
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
92
+ environment)
93
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
94
+ application_name)
95
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
96
+ model)
97
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
98
+ kwargs.get("top_k", 40))
99
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
100
+ kwargs.get("top_p", 0.4))
101
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
102
+ kwargs.get("max_tokens", 200))
103
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
104
+ kwargs.get("temperature", 0.7))
105
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
106
+ kwargs.get("frequency_penalty", 1.18))
107
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
108
+ True)
109
+ if trace_content:
110
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
111
+ prompt)
112
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
113
+ llmresponse)
114
+
115
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
116
+ prompt_tokens)
117
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
118
+ completion_tokens)
119
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
120
+ total_tokens)
121
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
122
+ cost)
123
+
124
+ span.set_status(Status(StatusCode.OK))
125
+
126
+ if disable_metrics is False:
127
+ attributes = {
128
+ TELEMETRY_SDK_NAME:
129
+ "openlit",
130
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
131
+ application_name,
132
+ SemanticConvetion.GEN_AI_SYSTEM:
133
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
134
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
135
+ environment,
136
+ SemanticConvetion.GEN_AI_TYPE:
137
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
138
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
139
+ model
140
+ }
141
+
142
+ metrics["genai_requests"].add(1, attributes)
143
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
144
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
145
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
146
+ metrics["genai_cost"].record(cost, attributes)
147
+
148
+ except Exception as e:
149
+ handle_exception(span, e)
150
+ logger.error("Error in trace creation: %s", e)
151
+
152
+ return stream_generator()
153
+
154
+ # Handling for non-streaming responses
155
+ else:
156
+ # pylint: disable=line-too-long
157
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
158
+ response = wrapped(*args, **kwargs)
159
+
160
+ # pylint: disable=line-too-long
161
+ model = str(instance.model.model_path).rsplit('/', maxsplit=1)[-1] or "orca-mini-3b-gguf2-q4_0.gguf"
162
+ prompt = kwargs.get("prompt") or args[0] or ""
163
+
164
+ # Calculate cost of the operation
165
+ cost = 0
166
+ prompt_tokens = general_tokens(prompt)
167
+ completion_tokens = general_tokens(response)
168
+ total_tokens = prompt_tokens + completion_tokens
169
+
170
+ try:
171
+ # Set base span attribues
172
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
173
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
174
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
175
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
176
+ SemanticConvetion.GEN_AI_TYPE_CHAT)
177
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
178
+ gen_ai_endpoint)
179
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
180
+ environment)
181
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
182
+ application_name)
183
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
184
+ model)
185
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
186
+ kwargs.get("top_k", 40))
187
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
188
+ kwargs.get("top_p", 0.4))
189
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
190
+ kwargs.get("max_tokens", 200))
191
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
192
+ kwargs.get("temperature", 0.7))
193
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
194
+ kwargs.get("frequency_penalty", 1.18))
195
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
196
+ False)
197
+ if trace_content:
198
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
199
+ prompt)
200
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
201
+ response)
202
+
203
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
204
+ prompt_tokens)
205
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
206
+ completion_tokens)
207
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
208
+ total_tokens)
209
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
210
+ cost)
211
+
212
+ span.set_status(Status(StatusCode.OK))
213
+
214
+ if disable_metrics is False:
215
+ attributes = {
216
+ TELEMETRY_SDK_NAME:
217
+ "openlit",
218
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
219
+ application_name,
220
+ SemanticConvetion.GEN_AI_SYSTEM:
221
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
222
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
223
+ environment,
224
+ SemanticConvetion.GEN_AI_TYPE:
225
+ SemanticConvetion.GEN_AI_TYPE_CHAT,
226
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
227
+ model
228
+ }
229
+
230
+ metrics["genai_requests"].add(1, attributes)
231
+ metrics["genai_total_tokens"].add(total_tokens, attributes)
232
+ metrics["genai_completion_tokens"].add(completion_tokens, attributes)
233
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
234
+ metrics["genai_cost"].record(cost, attributes)
235
+
236
+ # Return original response
237
+ return response
238
+
239
+ except Exception as e:
240
+ handle_exception(span, e)
241
+ logger.error("Error in trace creation: %s", e)
242
+
243
+ # Return original response
244
+ return response
245
+
246
+ return wrapper
247
+
248
+ def embed(gen_ai_endpoint, version, environment, application_name,
249
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
250
+ """
251
+ Generates a telemetry wrapper for embeddings to collect metrics.
252
+
253
+ Args:
254
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
255
+ version: Version of the monitoring package.
256
+ environment: Deployment environment (e.g., production, staging).
257
+ application_name: Name of the application using the GPT4All API.
258
+ tracer: OpenTelemetry tracer for creating spans.
259
+ pricing_info: Information used for calculating the cost of GPT4All usage.
260
+ trace_content: Flag indicating whether to trace the actual content.
261
+
262
+ Returns:
263
+ A function that wraps the embeddings method to add telemetry.
264
+ """
265
+
266
+ def wrapper(wrapped, instance, args, kwargs):
267
+ """
268
+ Wraps the 'embeddings' API call to add telemetry.
269
+
270
+ This collects metrics such as execution time, cost, and token usage, and handles errors
271
+ gracefully, adding details to the trace for observability.
272
+
273
+ Args:
274
+ wrapped: The original 'embeddings' method to be wrapped.
275
+ instance: The instance of the class where the original method is defined.
276
+ args: Positional arguments for the 'embeddings' method.
277
+ kwargs: Keyword arguments for the 'embeddings' method.
278
+
279
+ Returns:
280
+ The response from the original 'embeddings' method.
281
+ """
282
+
283
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
284
+ response = wrapped(*args, **kwargs)
285
+
286
+ try:
287
+ # pylint: disable=line-too-long
288
+ model = str(instance.gpt4all.model.model_path).rsplit('/', maxsplit=1)[-1] or "all-MiniLM-L6-v2.gguf2.f16.gguf"
289
+ prompt = kwargs.get("prompt") or args[0] or ""
290
+
291
+ # Calculate cost of the operation
292
+ cost = 0
293
+ prompt_tokens = general_tokens(prompt)
294
+
295
+ # Set Span attributes
296
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
297
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
298
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL)
299
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
300
+ SemanticConvetion.GEN_AI_TYPE_EMBEDDING)
301
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
302
+ gen_ai_endpoint)
303
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
304
+ environment)
305
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
306
+ application_name)
307
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
308
+ model)
309
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
310
+ prompt_tokens)
311
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
312
+ prompt_tokens)
313
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
314
+ cost)
315
+ if trace_content:
316
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
317
+ prompt)
318
+
319
+ span.set_status(Status(StatusCode.OK))
320
+
321
+ if disable_metrics is False:
322
+ attributes = {
323
+ TELEMETRY_SDK_NAME:
324
+ "openlit",
325
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
326
+ application_name,
327
+ SemanticConvetion.GEN_AI_SYSTEM:
328
+ SemanticConvetion.GEN_AI_SYSTEM_GPT4ALL,
329
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
330
+ environment,
331
+ SemanticConvetion.GEN_AI_TYPE:
332
+ SemanticConvetion.GEN_AI_TYPE_EMBEDDING,
333
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
334
+ model
335
+ }
336
+
337
+ metrics["genai_requests"].add(1, attributes)
338
+ metrics["genai_total_tokens"].add(prompt_tokens, attributes)
339
+ metrics["genai_prompt_tokens"].add(prompt_tokens, attributes)
340
+ metrics["genai_cost"].record(cost, attributes)
341
+
342
+ # Return original response
343
+ return response
344
+
345
+ except Exception as e:
346
+ handle_exception(span, e)
347
+ logger.error("Error in trace creation: %s", e)
348
+
349
+ # Return original response
350
+ return response
351
+
352
+ 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"
@@ -89,9 +95,11 @@ class SemanticConvetion:
89
95
  GEN_AI_SYSTEM_VERTEXAI = "vertexai"
90
96
  GEN_AI_SYSTEM_GROQ = "groq"
91
97
  GEN_AI_SYSTEM_OLLAMA = "ollama"
98
+ GEN_AI_SYSTEM_GPT4ALL = "gpt4all"
92
99
  GEN_AI_SYSTEM_LANGCHAIN = "langchain"
93
100
  GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
94
101
  GEN_AI_SYSTEM_HAYSTACK = "haystack"
102
+ GEN_AI_SYSTEM_EMBEDCHAIN = "embedchain"
95
103
 
96
104
  # Vector DB
97
105
  DB_REQUESTS = "db.total.requests"
File without changes