openlit 1.1.3__tar.gz → 1.3.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 (39) hide show
  1. {openlit-1.1.3 → openlit-1.3.0}/PKG-INFO +25 -19
  2. {openlit-1.1.3 → openlit-1.3.0}/README.md +24 -18
  3. {openlit-1.1.3 → openlit-1.3.0}/pyproject.toml +1 -1
  4. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/__init__.py +9 -1
  5. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/anthropic/anthropic.py +1 -1
  6. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/anthropic/async_anthropic.py +1 -1
  7. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/chroma/chroma.py +1 -1
  8. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/cohere/cohere.py +1 -1
  9. openlit-1.3.0/src/openlit/instrumentation/haystack/__init__.py +49 -0
  10. openlit-1.3.0/src/openlit/instrumentation/haystack/haystack.py +84 -0
  11. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/langchain/langchain.py +1 -1
  12. openlit-1.3.0/src/openlit/instrumentation/llamaindex/__init__.py +55 -0
  13. openlit-1.3.0/src/openlit/instrumentation/llamaindex/llamaindex.py +86 -0
  14. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/mistral/async_mistral.py +1 -1
  15. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/mistral/mistral.py +1 -1
  16. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/pinecone/pinecone.py +1 -1
  17. openlit-1.3.0/src/openlit/instrumentation/vertexai/__init__.py +147 -0
  18. openlit-1.3.0/src/openlit/instrumentation/vertexai/async_vertexai.py +1047 -0
  19. openlit-1.3.0/src/openlit/instrumentation/vertexai/vertexai.py +1047 -0
  20. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/semcov/__init__.py +3 -0
  21. {openlit-1.1.3 → openlit-1.3.0}/LICENSE +0 -0
  22. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/__helpers.py +0 -0
  23. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  24. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  25. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  26. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  27. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  28. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  29. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  30. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/openai/__init__.py +0 -0
  31. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  32. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  33. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  34. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/openai/openai.py +0 -0
  35. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  36. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  37. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  38. {openlit-1.1.3 → openlit-1.3.0}/src/openlit/otel/metrics.py +0 -0
  39. {openlit-1.1.3 → openlit-1.3.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.1.3
3
+ Version: 1.3.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
@@ -49,30 +49,36 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
49
49
  ## What can be Auto Instrumented?
50
50
 
51
51
  ### LLMs
52
- - ✅ OpenAI
53
- - ✅ Anthropic
54
- - ✅ Cohere
55
- - ✅ Mistral
56
- - ✅ Azure OpenAI
57
- - ✅ HuggingFace Transformers
52
+ - [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai)
53
+ - [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic)
54
+ - [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere)
55
+ - [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral)
56
+ - [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai)
57
+ - [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface)
58
+ - [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock)
59
+ - [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai)
58
60
 
59
61
  ### Vector DBs
60
- - ✅ ChromaDB
61
- - ✅ Pinecone
62
+ - [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
63
+ - [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
62
64
 
63
65
  ### Frameworks
64
- - ✅ Langchain
65
- - ✅ LiteLLM
66
+ - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
67
+ - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
68
+ - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
69
+ - [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack)
66
70
 
67
71
  ## Supported Destinations
68
- - ✅ OpenTelemetry Collector
69
- - ✅ Grafana Cloud
70
- - ✅ Grafana Tempo
71
- - ✅ DataDog
72
- - ✅ New Relic
73
- - ✅ SigNoz
74
- - ✅ Dynatrace
75
- - ✅ OpenObserve
72
+ - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
73
+ - [Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
74
+ - [Prometheus + Jaeger](https://docs.openlit.io/latest/connections/prometheus-jaeger)
75
+ - [Grafana Cloud](https://docs.openlit.io/latest/connections/grafanacloud)
76
+ - [DataDog](https://docs.openlit.io/latest/connections/datadog)
77
+ - [New Relic](https://docs.openlit.io/latest/connections/new-relic)
78
+ - [SigNoz](https://docs.openlit.io/latest/connections/signoz)
79
+ - [Dynatrace](https://docs.openlit.io/latest/connections/dynatrace)
80
+ - [✅ OpenObserve](https://docs.openlit.io/latest/connections/openobserve)
81
+ - [✅ Highlight.io](https://docs.openlit.io/latest/connections/highlight)
76
82
 
77
83
  ## 💿 Installation
78
84
 
@@ -24,30 +24,36 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
24
24
  ## What can be Auto Instrumented?
25
25
 
26
26
  ### LLMs
27
- - ✅ OpenAI
28
- - ✅ Anthropic
29
- - ✅ Cohere
30
- - ✅ Mistral
31
- - ✅ Azure OpenAI
32
- - ✅ HuggingFace Transformers
27
+ - [✅ OpenAI](https://docs.openlit.io/latest/integrations/openai)
28
+ - [✅ Anthropic](https://docs.openlit.io/latest/integrations/anthropic)
29
+ - [✅ Cohere](https://docs.openlit.io/latest/integrations/cohere)
30
+ - [✅ Mistral](https://docs.openlit.io/latest/integrations/mistral)
31
+ - [✅ Azure OpenAI](https://docs.openlit.io/latest/integrations/azure-openai)
32
+ - [✅ HuggingFace Transformers](https://docs.openlit.io/latest/integrations/huggingface)
33
+ - [✅ Amazon Bedrock](https://docs.openlit.io/latest/integrations/bedrock)
34
+ - [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai)
33
35
 
34
36
  ### Vector DBs
35
- - ✅ ChromaDB
36
- - ✅ Pinecone
37
+ - [✅ ChromaDB](https://docs.openlit.io/latest/integrations/chromadb)
38
+ - [✅ Pinecone](https://docs.openlit.io/latest/integrations/pinecone)
37
39
 
38
40
  ### Frameworks
39
- - ✅ Langchain
40
- - ✅ LiteLLM
41
+ - [✅ Langchain](https://docs.openlit.io/latest/integrations/langchain)
42
+ - [✅ LiteLLM](https://docs.openlit.io/latest/integrations/litellm)
43
+ - [✅ LlamaIndex](https://docs.openlit.io/latest/integrations/llama-index)
44
+ - [✅ Haystack](https://docs.openlit.io/latest/integrations/haystack)
41
45
 
42
46
  ## Supported Destinations
43
- - ✅ OpenTelemetry Collector
44
- - ✅ Grafana Cloud
45
- - ✅ Grafana Tempo
46
- - ✅ DataDog
47
- - ✅ New Relic
48
- - ✅ SigNoz
49
- - ✅ Dynatrace
50
- - ✅ OpenObserve
47
+ - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
48
+ - [Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
49
+ - [Prometheus + Jaeger](https://docs.openlit.io/latest/connections/prometheus-jaeger)
50
+ - [Grafana Cloud](https://docs.openlit.io/latest/connections/grafanacloud)
51
+ - [DataDog](https://docs.openlit.io/latest/connections/datadog)
52
+ - [New Relic](https://docs.openlit.io/latest/connections/new-relic)
53
+ - [SigNoz](https://docs.openlit.io/latest/connections/signoz)
54
+ - [Dynatrace](https://docs.openlit.io/latest/connections/dynatrace)
55
+ - [✅ OpenObserve](https://docs.openlit.io/latest/connections/openobserve)
56
+ - [✅ Highlight.io](https://docs.openlit.io/latest/connections/highlight)
51
57
 
52
58
  ## 💿 Installation
53
59
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "1.1.3"
3
+ version = "1.3.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"
@@ -18,7 +18,10 @@ from openlit.instrumentation.anthropic import AnthropicInstrumentor
18
18
  from openlit.instrumentation.cohere import CohereInstrumentor
19
19
  from openlit.instrumentation.mistral import MistralInstrumentor
20
20
  from openlit.instrumentation.bedrock import BedrockInstrumentor
21
+ from openlit.instrumentation.vertexai import VertexAIInstrumentor
21
22
  from openlit.instrumentation.langchain import LangChainInstrumentor
23
+ from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
24
+ from openlit.instrumentation.haystack import HaystackInstrumentor
22
25
  from openlit.instrumentation.chroma import ChromaInstrumentor
23
26
  from openlit.instrumentation.pinecone import PineconeInstrumentor
24
27
  from openlit.instrumentation.transformers import TransformersInstrumentor
@@ -139,7 +142,6 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
139
142
  disable_metrics (bool): Flag to disable metrics (Optional)
140
143
  """
141
144
  disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
142
-
143
145
  # Check for invalid instrumentor names
144
146
 
145
147
  module_name_map = {
@@ -148,7 +150,10 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
148
150
  "cohere": "cohere",
149
151
  "mistral": "mistralai",
150
152
  "bedrock": "boto3",
153
+ "vertexai": "vertexai",
151
154
  "langchain": "langchain",
155
+ "llama_index": "llama_index",
156
+ "haystack": "haystack",
152
157
  "chroma": "chromadb",
153
158
  "pinecone": "pinecone",
154
159
  "transformers": "transformers"
@@ -195,7 +200,10 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
195
200
  "cohere": CohereInstrumentor(),
196
201
  "mistral": MistralInstrumentor(),
197
202
  "bedrock": BedrockInstrumentor(),
203
+ "vertexai": VertexAIInstrumentor(),
198
204
  "langchain": LangChainInstrumentor(),
205
+ "llama_index": LlamaIndexInstrumentor(),
206
+ "haystack": HaystackInstrumentor(),
199
207
  "chroma": ChromaInstrumentor(),
200
208
  "pinecone": PineconeInstrumentor(),
201
209
  "transformers": TransformersInstrumentor()
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Anthropic API calls.
4
4
  """
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Anthropic API calls.
4
4
  """
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring ChromaDB.
4
4
  """
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Cohere API calls.
4
4
  """
@@ -0,0 +1,49 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of Haystack 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.haystack.haystack import join_data
9
+
10
+ _instruments = ("haystack-ai >= 2.0.0",)
11
+
12
+ WRAPPED_METHODS = [
13
+ {
14
+ "package": "haystack.components.joiners.document_joiner",
15
+ "object": "DocumentJoiner",
16
+ "endpoint": "haystack.join_data",
17
+ "wrapper": join_data,
18
+ }
19
+ ]
20
+
21
+ class HaystackInstrumentor(BaseInstrumentor):
22
+ """An instrumentor for Cohere's client library."""
23
+
24
+ def instrumentation_dependencies(self) -> Collection[str]:
25
+ return _instruments
26
+
27
+ def _instrument(self, **kwargs):
28
+ application_name = kwargs.get("application_name")
29
+ environment = kwargs.get("environment")
30
+ tracer = kwargs.get("tracer")
31
+ pricing_info = kwargs.get("pricing_info")
32
+ trace_content = kwargs.get("trace_content")
33
+ version = importlib.metadata.version("haystack-ai")
34
+
35
+ for wrapped_method in WRAPPED_METHODS:
36
+ wrap_package = wrapped_method.get("package")
37
+ wrap_object = wrapped_method.get("object")
38
+ gen_ai_endpoint = wrapped_method.get("endpoint")
39
+ wrapper = wrapped_method.get("wrapper")
40
+ wrap_function_wrapper(
41
+ wrap_package,
42
+ wrap_object,
43
+ wrapper(gen_ai_endpoint, version, environment, application_name,
44
+ tracer, pricing_info, trace_content),
45
+ )
46
+
47
+ @staticmethod
48
+ def _uninstrument(self, **kwargs):
49
+ pass
@@ -0,0 +1,84 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
2
+ """
3
+ Module for monitoring Haystack 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 join_data(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 Haystack application.
26
+ - environment (str): The deployment environment (e.g., 'production', 'development').
27
+ - application_name (str): Name of the Haystack 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_HAYSTACK)
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_status(Status(StatusCode.OK))
73
+
74
+ # Return original response
75
+ return response
76
+
77
+ except Exception as e:
78
+ handle_exception(span, e)
79
+ logger.error("Error in trace creation: %s", e)
80
+
81
+ # Return original response
82
+ return response
83
+
84
+ return wrapper
@@ -60,7 +60,7 @@ def general_wrap(gen_ai_endpoint, version, environment, application_name,
60
60
  try:
61
61
  span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
62
62
  span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
63
- "langchain")
63
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
64
64
  span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
65
65
  gen_ai_endpoint)
66
66
  span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
@@ -0,0 +1,55 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of LlamaIndex 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.llamaindex.llamaindex import load_data
9
+
10
+ _instruments = ("llama-index >= 0.10.0",)
11
+
12
+ WRAPPED_METHODS = [
13
+ {
14
+ "package": "llama_index.core.readers",
15
+ "object": "SimpleDirectoryReader.load_data",
16
+ "endpoint": "llamaindex.load_data",
17
+ "wrapper": load_data,
18
+ },
19
+ {
20
+ "package": "llama_index.core.node_parser",
21
+ "object": "SentenceSplitter.get_nodes_from_documents",
22
+ "endpoint": "llamaindex.data_splitter",
23
+ "wrapper": load_data,
24
+ },
25
+ ]
26
+
27
+ class LlamaIndexInstrumentor(BaseInstrumentor):
28
+ """An instrumentor for Cohere'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("llama-index")
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,86 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
2
+ """
3
+ Module for monitoring LlamaIndex 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 load_data(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 LlamaIndex application.
26
+ - environment (str): The deployment environment (e.g., 'production', 'development').
27
+ - application_name (str): Name of the LlamaIndex 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_LLAMAINDEX)
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_RETRIEVAL_SOURCE,
73
+ response[0].metadata["file_path"])
74
+ span.set_status(Status(StatusCode.OK))
75
+
76
+ # Return original response
77
+ return response
78
+
79
+ except Exception as e:
80
+ handle_exception(span, e)
81
+ logger.error("Error in trace creation: %s", e)
82
+
83
+ # Return original response
84
+ return response
85
+
86
+ return wrapper
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Mistral API calls.
4
4
  """
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Mistral API calls.
4
4
  """
@@ -1,4 +1,4 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
2
  """
3
3
  Module for monitoring Pinecone.
4
4
  """
@@ -0,0 +1,147 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of VertexAI 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.vertexai.vertexai import (
10
+ generate_content, predict, predict_streaming,
11
+ send_message, start_chat, start_chat_streaming,
12
+ embeddings
13
+ )
14
+ from openlit.instrumentation.vertexai.async_vertexai import (
15
+ generate_content_async, predict_async,
16
+ predict_streaming_async,
17
+ send_message_async,
18
+ start_chat_async, start_chat_streaming_async,
19
+ embeddings_async
20
+ )
21
+
22
+
23
+ _instruments = ("google-cloud-aiplatform >= 1.38.1",)
24
+
25
+ class VertexAIInstrumentor(BaseInstrumentor):
26
+ """
27
+ An instrumentor for VertexAI's client library.
28
+ """
29
+
30
+ def instrumentation_dependencies(self) -> Collection[str]:
31
+ return _instruments
32
+
33
+ def _instrument(self, **kwargs):
34
+ application_name = kwargs.get("application_name", "default")
35
+ environment = kwargs.get("environment", "default")
36
+ tracer = kwargs.get("tracer")
37
+ metrics = kwargs.get("metrics_dict")
38
+ pricing_info = kwargs.get("pricing_info", {})
39
+ trace_content = kwargs.get("trace_content", False)
40
+ disable_metrics = kwargs.get("disable_metrics")
41
+ version = importlib.metadata.version("google-cloud-aiplatform")
42
+
43
+ #sync
44
+ wrap_function_wrapper(
45
+ "vertexai.generative_models",
46
+ "GenerativeModel.generate_content",
47
+ generate_content("vertexai.generate_content", version, environment, application_name,
48
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
49
+ )
50
+
51
+ wrap_function_wrapper(
52
+ "vertexai.generative_models",
53
+ "ChatSession.send_message",
54
+ send_message("vertexai.send_message", version, environment, application_name,
55
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
56
+ )
57
+
58
+ wrap_function_wrapper(
59
+ "vertexai.language_models",
60
+ "TextGenerationModel.predict",
61
+ predict("vertexai.predict", version, environment, application_name,
62
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
63
+ )
64
+
65
+ wrap_function_wrapper(
66
+ "vertexai.language_models",
67
+ "TextGenerationModel.predict_streaming",
68
+ predict_streaming("vertexai.predict", version, environment, application_name,
69
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
70
+ )
71
+
72
+ wrap_function_wrapper(
73
+ "vertexai.language_models",
74
+ "ChatSession.send_message",
75
+ start_chat("vertexai.send_message", version, environment, application_name,
76
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
77
+ )
78
+
79
+ wrap_function_wrapper(
80
+ "vertexai.language_models",
81
+ "ChatSession.send_message_streaming",
82
+ start_chat_streaming("vertexai.send_message", version, environment, application_name,
83
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
84
+ )
85
+
86
+ wrap_function_wrapper(
87
+ "vertexai.language_models",
88
+ "TextEmbeddingModel.get_embeddings",
89
+ embeddings("vertexai.get_embeddings", version, environment, application_name,
90
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
91
+ )
92
+
93
+ #async
94
+ wrap_function_wrapper(
95
+ "vertexai.generative_models",
96
+ "GenerativeModel.generate_content_async",
97
+ generate_content_async("vertexai.generate_content", version, environment,
98
+ application_name, tracer, pricing_info, trace_content,
99
+ metrics, disable_metrics),
100
+ )
101
+
102
+ wrap_function_wrapper(
103
+ "vertexai.generative_models",
104
+ "ChatSession.send_message_async",
105
+ send_message_async("vertexai.send_message", version, environment, application_name,
106
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
107
+ )
108
+
109
+ wrap_function_wrapper(
110
+ "vertexai.language_models",
111
+ "TextGenerationModel.predict_async",
112
+ predict_async("vertexai.predict", version, environment, application_name,
113
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
114
+ )
115
+
116
+ wrap_function_wrapper(
117
+ "vertexai.language_models",
118
+ "TextGenerationModel.predict_streaming_async",
119
+ predict_streaming_async("vertexai.predict", version, environment, application_name,
120
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
121
+ )
122
+
123
+ wrap_function_wrapper(
124
+ "vertexai.language_models",
125
+ "ChatSession.send_message_async",
126
+ start_chat_async("vertexai.send_message", version, environment, application_name,
127
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
128
+ )
129
+
130
+ wrap_function_wrapper(
131
+ "vertexai.language_models",
132
+ "ChatSession.send_message_streaming_async",
133
+ start_chat_streaming_async("vertexai.send_message", version, environment,
134
+ application_name, tracer, pricing_info, trace_content,
135
+ metrics, disable_metrics),
136
+ )
137
+
138
+ wrap_function_wrapper(
139
+ "vertexai.language_models",
140
+ "TextEmbeddingModel.get_embeddings_async",
141
+ embeddings_async("vertexai.get_embeddings", version, environment, application_name,
142
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
143
+ )
144
+
145
+ def _uninstrument(self, **kwargs):
146
+ # Proper uninstrumentation logic to revert patched methods
147
+ pass