openlit 1.14.0__tar.gz → 1.14.2__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 (55) hide show
  1. {openlit-1.14.0 → openlit-1.14.2}/PKG-INFO +3 -3
  2. {openlit-1.14.0 → openlit-1.14.2}/README.md +2 -2
  3. {openlit-1.14.0 → openlit-1.14.2}/pyproject.toml +1 -1
  4. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/__init__.py +1 -1
  5. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/bedrock/bedrock.py +2 -2
  6. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/langchain/__init__.py +14 -2
  7. openlit-1.14.2/src/openlit/instrumentation/langchain/langchain.py +330 -0
  8. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/openai/async_azure_openai.py +3 -3
  9. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/openai/async_openai.py +5 -5
  10. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/openai/azure_openai.py +3 -3
  11. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/openai/openai.py +5 -5
  12. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/transformers/__init__.py +1 -1
  13. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/transformers/transformers.py +3 -3
  14. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/semcov/__init__.py +4 -3
  15. openlit-1.14.0/src/openlit/instrumentation/langchain/langchain.py +0 -161
  16. {openlit-1.14.0 → openlit-1.14.2}/LICENSE +0 -0
  17. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/__helpers.py +0 -0
  18. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  19. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  20. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  21. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  22. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  23. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  24. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  25. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/cohere/cohere.py +0 -0
  26. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/embedchain/__init__.py +0 -0
  27. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/embedchain/embedchain.py +0 -0
  28. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/gpt4all/__init__.py +0 -0
  29. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/gpt4all/gpt4all.py +0 -0
  30. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/gpu/__init__.py +0 -0
  31. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/groq/__init__.py +0 -0
  32. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  33. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/groq/groq.py +0 -0
  34. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  35. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  36. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
  37. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  38. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  39. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  40. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  41. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  42. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  43. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  44. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  45. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  46. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/openai/__init__.py +0 -0
  47. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  48. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  49. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  50. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
  51. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  52. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  53. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  54. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/otel/metrics.py +0 -0
  55. {openlit-1.14.0 → openlit-1.14.2}/src/openlit/otel/tracing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.14.0
3
+ Version: 1.14.2
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,7 +38,7 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
38
38
  [![GitHub Contributors](https://img.shields.io/github/contributors/openlit/openlit)](https://github.com/openlit/openlit/graphs/contributors)
39
39
 
40
40
  [![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack&logoColor=white)](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ)
41
- [![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white)](https://discord.gg/rjvTm6zd)
41
+ [![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white)](https://discord.gg/CQnXwNT3)
42
42
  [![X](https://img.shields.io/badge/follow-%40openlit__io-1DA1F2?logo=x&style=social)](https://twitter.com/openlit_io)
43
43
 
44
44
  ![OpenLIT Connections Banner](https://github.com/openlit/.github/blob/main/profile/assets/github-readme-connections-banner.png?raw=true)
@@ -204,7 +204,7 @@ Your input helps us grow and improve, and we're here to support you every step o
204
204
  Connect with the OpenLIT community and maintainers for support, discussions, and updates:
205
205
 
206
206
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
207
- - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) or [Discord](https://discord.gg/rjvTm6zd) community for live interactions and questions.
207
+ - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) or [Discord](https://discord.gg/CQnXwNT3) community for live interactions and questions.
208
208
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
209
209
  - 𝕏 Follow us on [X](https://x.com/openlit_io) for the latest updates and news.
210
210
 
@@ -11,7 +11,7 @@ OpenTelemetry Auto-Instrumentation for GenAI & LLM Applications</h1>
11
11
  [![GitHub Contributors](https://img.shields.io/github/contributors/openlit/openlit)](https://github.com/openlit/openlit/graphs/contributors)
12
12
 
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
- [![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white)](https://discord.gg/rjvTm6zd)
14
+ [![Discord](https://img.shields.io/badge/Discord-7289DA?logo=discord&logoColor=white)](https://discord.gg/CQnXwNT3)
15
15
  [![X](https://img.shields.io/badge/follow-%40openlit__io-1DA1F2?logo=x&style=social)](https://twitter.com/openlit_io)
16
16
 
17
17
  ![OpenLIT Connections Banner](https://github.com/openlit/.github/blob/main/profile/assets/github-readme-connections-banner.png?raw=true)
@@ -177,6 +177,6 @@ Your input helps us grow and improve, and we're here to support you every step o
177
177
  Connect with the OpenLIT community and maintainers for support, discussions, and updates:
178
178
 
179
179
  - 🌟 If you like it, Leave a star on our [GitHub](https://github.com/openlit/openlit/)
180
- - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) or [Discord](https://discord.gg/rjvTm6zd) community for live interactions and questions.
180
+ - 🌍 Join our [Slack](https://join.slack.com/t/openlit/shared_invite/zt-2etnfttwg-TjP_7BZXfYg84oAukY8QRQ) or [Discord](https://discord.gg/CQnXwNT3) community for live interactions and questions.
181
181
  - 🐞 Report bugs on our [GitHub Issues](https://github.com/openlit/openlit/issues) to help us improve OpenLIT.
182
182
  - 𝕏 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.14.0"
3
+ version = "1.14.2"
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"
@@ -78,7 +78,7 @@ class OpenlitConfig:
78
78
  """Resets configuration to default values."""
79
79
  cls.environment = "default"
80
80
  cls.application_name = "default"
81
- cls.pricing_info = fetch_pricing_info()
81
+ cls.pricing_info = {}
82
82
  cls.tracer = None
83
83
  cls.metrics_dict = {}
84
84
  cls.otlp_endpoint = None
@@ -88,9 +88,9 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
88
88
  quality = request_body.get("imageGenerationConfig", {}).get("quality", "standard")
89
89
  n = request_body.get("imageGenerationConfig", {}).get("numberOfImages", 1)
90
90
 
91
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
91
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
92
92
  size)
93
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
93
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
94
94
  quality)
95
95
  # Calculate cost of the operation
96
96
  cost = n * get_image_model_cost(model,
@@ -5,9 +5,9 @@ import importlib.metadata
5
5
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
7
 
8
- from openlit.instrumentation.langchain.langchain import general_wrap, hub
8
+ from openlit.instrumentation.langchain.langchain import general_wrap, hub, llm, allm
9
9
 
10
- _instruments = ("langchain >= 0.1.1",)
10
+ _instruments = ("langchain >= 0.1.20",)
11
11
 
12
12
  WRAPPED_METHODS = [
13
13
  {
@@ -40,6 +40,18 @@ WRAPPED_METHODS = [
40
40
  "endpoint": "langchain.retrieve.prompt",
41
41
  "wrapper": hub,
42
42
  },
43
+ {
44
+ "package": "langchain_core.language_models.llms",
45
+ "object": "BaseLLM.invoke",
46
+ "endpoint": "langchain.llm",
47
+ "wrapper": llm,
48
+ },
49
+ {
50
+ "package": "langchain_core.language_models.llms",
51
+ "object": "BaseLLM.ainvoke",
52
+ "endpoint": "langchain.llm",
53
+ "wrapper": allm,
54
+ },
43
55
  ]
44
56
 
45
57
  class LangChainInstrumentor(BaseInstrumentor):
@@ -0,0 +1,330 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
2
+ """
3
+ Module for monitoring Langchain 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 general_wrap(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 Langchain application.
26
+ - environment (str): The deployment environment (e.g., 'production', 'development').
27
+ - application_name (str): Name of the Langchain 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_LANGCHAIN)
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["source"])
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
87
+
88
+ def hub(gen_ai_endpoint, version, environment, application_name, tracer,
89
+ pricing_info, trace_content):
90
+ """
91
+ Creates a wrapper around Langchain hub operations for tracing and logging.
92
+
93
+ Similar to `general_wrap`, this function focuses on wrapping functions involved
94
+ in interacting with the Langchain hub, adding specific metadata relevant to
95
+ hub operations to the span attributes.
96
+
97
+ Parameters:
98
+ - gen_ai_endpoint (str): A descriptor or name for the Langchain hub endpoint.
99
+ - version (str): The version of the Langchain application.
100
+ - environment (str): The deployment environment, such as 'production' or 'development'.
101
+ - application_name (str): Name of the Langchain application.
102
+ - tracer (opentelemetry.trace.Tracer): The tracer for OpenTelemetry tracing.
103
+ - pricing_info (dict): Pricing information for the operation (not currently used).
104
+ - trace_content (bool): Indicates if the content of the response should be traced.
105
+
106
+ Returns:
107
+ - function: A new function that wraps the original hub operation call with added
108
+ logging, tracing, and metric calculation functionalities.
109
+ """
110
+
111
+ def wrapper(wrapped, instance, args, kwargs):
112
+ """
113
+ An inner wrapper specifically designed for Langchain hub operations,
114
+ providing tracing, logging, and execution metrics.
115
+
116
+ Parameters:
117
+ - wrapped (Callable): The original hub operation function to be executed.
118
+ - instance (object): The instance of the class where the hub operation
119
+ method is defined. May be None for static or class methods.
120
+ - args (tuple): Positional arguments to pass to the hub operation function.
121
+ - kwargs (dict): Keyword arguments to pass to the hub operation function.
122
+
123
+ Returns:
124
+ - The result of executing the hub operation function.
125
+
126
+ This wrapper captures additional metadata relevant to Langchain hub operations,
127
+ creating spans with specific attributes and metrics that reflect the nature of
128
+ each hub call.
129
+ """
130
+
131
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
132
+ response = wrapped(*args, **kwargs)
133
+
134
+ try:
135
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
136
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
137
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
138
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
139
+ gen_ai_endpoint)
140
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
141
+ environment)
142
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
143
+ SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
144
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
145
+ application_name)
146
+ span.set_attribute(SemanticConvetion.GEN_AI_HUB_OWNER,
147
+ response.metadata["lc_hub_owner"])
148
+ span.set_attribute(SemanticConvetion.GEN_AI_HUB_REPO,
149
+ response.metadata["lc_hub_repo"])
150
+ span.set_status(Status(StatusCode.OK))
151
+
152
+ return response
153
+
154
+ except Exception as e:
155
+ handle_exception(span, e)
156
+ logger.error("Error in trace creation: %s", e)
157
+
158
+ # Return original response
159
+ return response
160
+
161
+ return wrapper
162
+
163
+
164
+ def allm(gen_ai_endpoint, version, environment, application_name,
165
+ tracer, pricing_info, trace_content):
166
+ """
167
+ Creates a wrapper around a function call to trace and log its execution metrics.
168
+
169
+ This function wraps any given function to measure its execution time,
170
+ log its operation, and trace its execution using OpenTelemetry.
171
+
172
+ Parameters:
173
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
174
+ - version (str): The version of the Langchain application.
175
+ - environment (str): The deployment environment (e.g., 'production', 'development').
176
+ - application_name (str): Name of the Langchain application.
177
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
178
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
179
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
180
+
181
+ Returns:
182
+ - function: A higher-order function that takes a function 'wrapped' and returns
183
+ a new function that wraps 'wrapped' with additional tracing and logging.
184
+ """
185
+
186
+ async def wrapper(wrapped, instance, args, kwargs):
187
+ """
188
+ An inner wrapper function that executes the wrapped function, measures execution
189
+ time, and records trace data using OpenTelemetry.
190
+
191
+ Parameters:
192
+ - wrapped (Callable): The original function that this wrapper will execute.
193
+ - instance (object): The instance to which the wrapped function belongs. This
194
+ is used for instance methods. For static and classmethods,
195
+ this may be None.
196
+ - args (tuple): Positional arguments passed to the wrapped function.
197
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
198
+
199
+ Returns:
200
+ - The result of the wrapped function call.
201
+
202
+ The wrapper initiates a span with the provided tracer, sets various attributes
203
+ on the span based on the function's execution and response, and ensures
204
+ errors are handled and logged appropriately.
205
+ """
206
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
207
+ response = await wrapped(*args, **kwargs)
208
+
209
+ try:
210
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
211
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
212
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
213
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
214
+ gen_ai_endpoint)
215
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
216
+ environment)
217
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
218
+ SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
219
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
220
+ application_name)
221
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
222
+ str(getattr(instance, 'model')))
223
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
224
+ str(getattr(instance, 'temperature')))
225
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
226
+ str(getattr(instance, 'top_k')))
227
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
228
+ str(getattr(instance, 'top_p')))
229
+ if trace_content:
230
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
231
+ args[0])
232
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
233
+ response)
234
+ span.set_status(Status(StatusCode.OK))
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 llm(gen_ai_endpoint, version, environment, application_name,
249
+ tracer, pricing_info, trace_content):
250
+ """
251
+ Creates a wrapper around a function call to trace and log its execution metrics.
252
+
253
+ This function wraps any given function to measure its execution time,
254
+ log its operation, and trace its execution using OpenTelemetry.
255
+
256
+ Parameters:
257
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
258
+ - version (str): The version of the Langchain application.
259
+ - environment (str): The deployment environment (e.g., 'production', 'development').
260
+ - application_name (str): Name of the Langchain application.
261
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
262
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
263
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
264
+
265
+ Returns:
266
+ - function: A higher-order function that takes a function 'wrapped' and returns
267
+ a new function that wraps 'wrapped' with additional tracing and logging.
268
+ """
269
+
270
+ def wrapper(wrapped, instance, args, kwargs):
271
+ """
272
+ An inner wrapper function that executes the wrapped function, measures execution
273
+ time, and records trace data using OpenTelemetry.
274
+
275
+ Parameters:
276
+ - wrapped (Callable): The original function that this wrapper will execute.
277
+ - instance (object): The instance to which the wrapped function belongs. This
278
+ is used for instance methods. For static and classmethods,
279
+ this may be None.
280
+ - args (tuple): Positional arguments passed to the wrapped function.
281
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
282
+
283
+ Returns:
284
+ - The result of the wrapped function call.
285
+
286
+ The wrapper initiates a span with the provided tracer, sets various attributes
287
+ on the span based on the function's execution and response, and ensures
288
+ errors are handled and logged appropriately.
289
+ """
290
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
291
+ response = wrapped(*args, **kwargs)
292
+
293
+ try:
294
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
295
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
296
+ SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
297
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
298
+ gen_ai_endpoint)
299
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
300
+ environment)
301
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
302
+ SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
303
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
304
+ application_name)
305
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
306
+ str(getattr(instance, 'model')))
307
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
308
+ str(getattr(instance, 'temperature')))
309
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
310
+ str(getattr(instance, 'top_k')))
311
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
312
+ str(getattr(instance, 'top_p')))
313
+ if trace_content:
314
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
315
+ args[0])
316
+ span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
317
+ response)
318
+ span.set_status(Status(StatusCode.OK))
319
+
320
+ # Return original response
321
+ return response
322
+
323
+ except Exception as e:
324
+ handle_exception(span, e)
325
+ logger.error("Error in trace creation: %s", e)
326
+
327
+ # Return original response
328
+ return response
329
+
330
+ return wrapper
@@ -785,11 +785,11 @@ def azure_async_image_generate(gen_ai_endpoint, version, environment, applicatio
785
785
  application_name)
786
786
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
787
787
  "azure_" + kwargs.get("model", "dall-e-3"))
788
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
788
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
789
789
  kwargs.get("size", "1024x1024"))
790
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
790
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
791
791
  kwargs.get("quality", "standard"))
792
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_STYLE,
792
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_STYLE,
793
793
  kwargs.get("style", "vivid"))
794
794
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_REVISED_PROMPT,
795
795
  items.revised_prompt if response.revised_prompt else "")
@@ -600,11 +600,11 @@ def async_image_generate(gen_ai_endpoint, version, environment, application_name
600
600
  application_name)
601
601
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
602
602
  kwargs.get("model", "dall-e-2"))
603
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
603
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
604
604
  kwargs.get("size", "1024x1024"))
605
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
605
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
606
606
  kwargs.get("quality", "standard"))
607
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_STYLE,
607
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_STYLE,
608
608
  kwargs.get("style", "vivid"))
609
609
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_REVISED_PROMPT,
610
610
  items.revised_prompt if items.revised_prompt else "")
@@ -724,9 +724,9 @@ def async_image_variatons(gen_ai_endpoint, version, environment, application_nam
724
724
  kwargs.get("model", "dall-e-2"))
725
725
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
726
726
  kwargs.get("user", ""))
727
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
727
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
728
728
  kwargs.get("size", "1024x1024"))
729
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
729
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
730
730
  "standard")
731
731
  if trace_content:
732
732
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
@@ -784,11 +784,11 @@ def azure_image_generate(gen_ai_endpoint, version, environment, application_name
784
784
  application_name)
785
785
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
786
786
  "azure_" + kwargs.get("model", "dall-e-3"))
787
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
787
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
788
788
  kwargs.get("size", "1024x1024"))
789
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
789
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
790
790
  kwargs.get("quality", "standard"))
791
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_STYLE,
791
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_STYLE,
792
792
  kwargs.get("style", "vivid"))
793
793
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_REVISED_PROMPT,
794
794
  items.revised_prompt if response.revised_prompt else "")
@@ -615,11 +615,11 @@ def image_generate(gen_ai_endpoint, version, environment, application_name,
615
615
  application_name)
616
616
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
617
617
  kwargs.get("model", "dall-e-2"))
618
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
618
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
619
619
  kwargs.get("size", "1024x1024"))
620
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
620
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
621
621
  kwargs.get("quality", "standard"))
622
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_STYLE,
622
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_STYLE,
623
623
  kwargs.get("style", "vivid"))
624
624
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_REVISED_PROMPT,
625
625
  items.revised_prompt if items.revised_prompt else "")
@@ -739,9 +739,9 @@ def image_variatons(gen_ai_endpoint, version, environment, application_name,
739
739
  kwargs.get("model", "dall-e-2"))
740
740
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
741
741
  kwargs.get("user", ""))
742
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_SIZE,
742
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_SIZE,
743
743
  kwargs.get("size", "1024x1024"))
744
- span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_IMAGE_QUALITY,
744
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IMAGE_QUALITY,
745
745
  "standard")
746
746
  if trace_content:
747
747
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
@@ -26,7 +26,7 @@ class TransformersInstrumentor(BaseInstrumentor):
26
26
  version = importlib.metadata.version("transformers")
27
27
 
28
28
  wrap_function_wrapper(
29
- "transformers.pipelines",
29
+ "transformers",
30
30
  "TextGenerationPipeline.__call__",
31
31
  text_wrap("huggingface.text_generation", version, environment, application_name,
32
32
  tracer, pricing_info, trace_content, metrics, disable_metrics),
@@ -83,11 +83,11 @@ def text_wrap(gen_ai_endpoint, version, environment, application_name,
83
83
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
84
84
  instance.model.config.name_or_path)
85
85
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
86
- forward_params.get("temperature"))
86
+ forward_params.get("temperature", "null"))
87
87
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
88
- forward_params.get("top_p"))
88
+ forward_params.get("top_p", "null"))
89
89
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
90
- forward_params.get("max_length"))
90
+ forward_params.get("max_length", "null"))
91
91
  span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
92
92
  prompt)
93
93
  if trace_content:
@@ -53,6 +53,10 @@ class SemanticConvetion:
53
53
  GEN_AI_REQUEST_VALIDATION_FILE = "gen_ai.request.validation_file"
54
54
  GEN_AI_REQUEST_TRAINING_FILE = "gen_ai.request.training_file"
55
55
 
56
+ GEN_AI_REQUEST_IMAGE_SIZE = "gen_ai.request.image_size"
57
+ GEN_AI_REQUEST_IMAGE_QUALITY = "gen_ai.request.image_quality"
58
+ GEN_AI_REQUEST_IMAGE_STYLE = "gen_ai.request.image_style"
59
+
56
60
  # GenAI Usage
57
61
  GEN_AI_USAGE_PROMPT_TOKENS = "gen_ai.usage.prompt_tokens"
58
62
  GEN_AI_USAGE_COMPLETION_TOKENS = "gen_ai.usage.completion_tokens"
@@ -63,9 +67,6 @@ class SemanticConvetion:
63
67
  GEN_AI_RESPONSE_ID = "gen_ai.response.id"
64
68
  GEN_AI_RESPONSE_FINISH_REASON = "gen_ai.response.finish_reason"
65
69
  GEN_AI_RESPONSE_IMAGE = "gen_ai.response.image" # Not used directly in code yet
66
- GEN_AI_RESPONSE_IMAGE_SIZE = "gen_ai.request.image_size"
67
- GEN_AI_RESPONSE_IMAGE_QUALITY = "gen_ai.request.image_quality"
68
- GEN_AI_RESPONSE_IMAGE_STYLE = "gen_ai.request.image_style"
69
70
 
70
71
  # GenAI Content
71
72
  GEN_AI_CONTENT_PROMPT = "gen_ai.prompt"
@@ -1,161 +0,0 @@
1
- # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument
2
- """
3
- Module for monitoring Langchain 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 general_wrap(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 Langchain application.
26
- - environment (str): The deployment environment (e.g., 'production', 'development').
27
- - application_name (str): Name of the Langchain 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_LANGCHAIN)
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["source"])
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
87
-
88
- def hub(gen_ai_endpoint, version, environment, application_name, tracer,
89
- pricing_info, trace_content):
90
- """
91
- Creates a wrapper around Langchain hub operations for tracing and logging.
92
-
93
- Similar to `general_wrap`, this function focuses on wrapping functions involved
94
- in interacting with the Langchain hub, adding specific metadata relevant to
95
- hub operations to the span attributes.
96
-
97
- Parameters:
98
- - gen_ai_endpoint (str): A descriptor or name for the Langchain hub endpoint.
99
- - version (str): The version of the Langchain application.
100
- - environment (str): The deployment environment, such as 'production' or 'development'.
101
- - application_name (str): Name of the Langchain application.
102
- - tracer (opentelemetry.trace.Tracer): The tracer for OpenTelemetry tracing.
103
- - pricing_info (dict): Pricing information for the operation (not currently used).
104
- - trace_content (bool): Indicates if the content of the response should be traced.
105
-
106
- Returns:
107
- - function: A new function that wraps the original hub operation call with added
108
- logging, tracing, and metric calculation functionalities.
109
- """
110
-
111
- def wrapper(wrapped, instance, args, kwargs):
112
- """
113
- An inner wrapper specifically designed for Langchain hub operations,
114
- providing tracing, logging, and execution metrics.
115
-
116
- Parameters:
117
- - wrapped (Callable): The original hub operation function to be executed.
118
- - instance (object): The instance of the class where the hub operation
119
- method is defined. May be None for static or class methods.
120
- - args (tuple): Positional arguments to pass to the hub operation function.
121
- - kwargs (dict): Keyword arguments to pass to the hub operation function.
122
-
123
- Returns:
124
- - The result of executing the hub operation function.
125
-
126
- This wrapper captures additional metadata relevant to Langchain hub operations,
127
- creating spans with specific attributes and metrics that reflect the nature of
128
- each hub call.
129
- """
130
-
131
- with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
132
- response = wrapped(*args, **kwargs)
133
-
134
- try:
135
- span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
136
- span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
137
- SemanticConvetion.GEN_AI_SYSTEM_LANGCHAIN)
138
- span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
139
- gen_ai_endpoint)
140
- span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
141
- environment)
142
- span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
143
- SemanticConvetion.GEN_AI_TYPE_FRAMEWORK)
144
- span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
145
- application_name)
146
- span.set_attribute(SemanticConvetion.GEN_AI_HUB_OWNER,
147
- response.metadata["lc_hub_owner"])
148
- span.set_attribute(SemanticConvetion.GEN_AI_HUB_REPO,
149
- response.metadata["lc_hub_repo"])
150
- span.set_status(Status(StatusCode.OK))
151
-
152
- return response
153
-
154
- except Exception as e:
155
- handle_exception(span, e)
156
- logger.error("Error in trace creation: %s", e)
157
-
158
- # Return original response
159
- return response
160
-
161
- return wrapper
File without changes