openlit 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
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.
- openlit/__init__.py +40 -16
- openlit/instrumentation/cohere/__init__.py +1 -1
- openlit/instrumentation/cohere/cohere.py +12 -12
- openlit/instrumentation/langchain/__init__.py +1 -2
- {openlit-0.0.1.dist-info → openlit-0.0.2.dist-info}/METADATA +1 -1
- {openlit-0.0.1.dist-info → openlit-0.0.2.dist-info}/RECORD +8 -8
- {openlit-0.0.1.dist-info → openlit-0.0.2.dist-info}/LICENSE +0 -0
- {openlit-0.0.1.dist-info → openlit-0.0.2.dist-info}/WHEEL +0 -0
openlit/__init__.py
CHANGED
@@ -3,8 +3,9 @@ The __init__.py module for the openLIT package.
|
|
3
3
|
This module sets up the openLIT configuration and instrumentation for various
|
4
4
|
large language models (LLMs).
|
5
5
|
"""
|
6
|
-
from typing import
|
6
|
+
from typing import Dict
|
7
7
|
import logging
|
8
|
+
from importlib.util import find_spec
|
8
9
|
|
9
10
|
# Import internal modules for setting up tracing and fetching pricing info.
|
10
11
|
from openlit.otel.tracing import setup_tracing
|
@@ -91,6 +92,30 @@ class OpenlitConfig:
|
|
91
92
|
cls.trace_content = trace_content
|
92
93
|
cls.disable_metrics = disable_metrics
|
93
94
|
|
95
|
+
def instrument_if_available(instrumentor_name, instrumentor_instance, config,
|
96
|
+
disabled_instrumentors, module_name_map):
|
97
|
+
"""Instruments the specified instrumentor if its library is available."""
|
98
|
+
if instrumentor_name in disabled_instrumentors:
|
99
|
+
return
|
100
|
+
|
101
|
+
module_name = module_name_map.get(instrumentor_name)
|
102
|
+
|
103
|
+
if not module_name or find_spec(module_name) is not None:
|
104
|
+
try:
|
105
|
+
instrumentor_instance.instrument(
|
106
|
+
environment=config.environment,
|
107
|
+
application_name=config.application_name,
|
108
|
+
tracer=config.tracer,
|
109
|
+
pricing_info=config.pricing_info,
|
110
|
+
trace_content=config.trace_content,
|
111
|
+
metrics_dict=config.metrics_dict,
|
112
|
+
disable_metrics=config.disable_metrics
|
113
|
+
)
|
114
|
+
|
115
|
+
# pylint: disable=broad-exception-caught
|
116
|
+
except Exception as e:
|
117
|
+
logger.error("Failed to instrument %s: %s", instrumentor_name, e)
|
118
|
+
|
94
119
|
def init(environment="default", application_name="default", tracer=None, otlp_endpoint=None,
|
95
120
|
otlp_headers=None, disable_batch=False, trace_content=True, disabled_instrumentors=None,
|
96
121
|
meter=None, disable_metrics=False):
|
@@ -115,12 +140,19 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
115
140
|
disabled_instrumentors = disabled_instrumentors if disabled_instrumentors else []
|
116
141
|
|
117
142
|
# Check for invalid instrumentor names
|
118
|
-
|
119
|
-
|
120
|
-
"
|
121
|
-
"
|
143
|
+
|
144
|
+
module_name_map = {
|
145
|
+
"openai": "openai",
|
146
|
+
"anthropic": "anthropic",
|
147
|
+
"cohere": "cohere",
|
148
|
+
"mistral": "mistralai",
|
149
|
+
"langchain": "langchain",
|
150
|
+
"chroma": "chromadb",
|
151
|
+
"pinecone": "pincone",
|
152
|
+
"transformers": "transformers"
|
122
153
|
}
|
123
|
-
|
154
|
+
|
155
|
+
invalid_instrumentors = [name for name in disabled_instrumentors if name not in module_name_map]
|
124
156
|
for invalid_name in invalid_instrumentors:
|
125
157
|
logger.warning("Invalid instrumentor name detected and ignored: '%s'", invalid_name)
|
126
158
|
|
@@ -168,16 +200,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
168
200
|
|
169
201
|
# Initialize and instrument only the enabled instrumentors
|
170
202
|
for name, instrumentor in instrumentor_instances.items():
|
171
|
-
|
172
|
-
|
173
|
-
environment=config.environment,
|
174
|
-
application_name=config.application_name,
|
175
|
-
tracer=config.tracer,
|
176
|
-
pricing_info=config.pricing_info,
|
177
|
-
trace_content=config.trace_content,
|
178
|
-
metrics_dict=config.metrics_dict,
|
179
|
-
disable_metrics=config.disable_metrics
|
180
|
-
)
|
203
|
+
instrument_if_available(name, instrumentor, config,
|
204
|
+
disabled_instrumentors, module_name_map)
|
181
205
|
|
182
206
|
# pylint: disable=broad-exception-caught
|
183
207
|
except Exception as e:
|
@@ -7,7 +7,7 @@ from wrapt import wrap_function_wrapper
|
|
7
7
|
|
8
8
|
from openlit.instrumentation.cohere.cohere import chat, chat_stream, embed
|
9
9
|
|
10
|
-
_instruments = ("cohere >= 5.
|
10
|
+
_instruments = ("cohere >= 5.3.2",)
|
11
11
|
|
12
12
|
class CohereInstrumentor(BaseInstrumentor):
|
13
13
|
"""An instrumentor for Cohere's client library."""
|
@@ -173,8 +173,8 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
173
173
|
# Calculate cost of the operation
|
174
174
|
cost = get_chat_model_cost(kwargs.get("model", "command"),
|
175
175
|
pricing_info,
|
176
|
-
response.meta
|
177
|
-
response.meta
|
176
|
+
response.meta.billed_units.input_tokens,
|
177
|
+
response.meta.billed_units.output_tokens)
|
178
178
|
|
179
179
|
# Set Span attributes
|
180
180
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
@@ -207,12 +207,12 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
207
207
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
208
208
|
response.response_id)
|
209
209
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
210
|
-
response.meta
|
210
|
+
response.meta.billed_units.input_tokens)
|
211
211
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
212
|
-
response.meta
|
212
|
+
response.meta.billed_units.output_tokens)
|
213
213
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
214
|
-
response.meta
|
215
|
-
response.meta
|
214
|
+
response.meta.billed_units.input_tokens +
|
215
|
+
response.meta.billed_units.output_tokens)
|
216
216
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
217
217
|
cost)
|
218
218
|
if trace_content:
|
@@ -241,12 +241,12 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
241
241
|
|
242
242
|
metrics["genai_requests"].add(1, attributes)
|
243
243
|
metrics["genai_total_tokens"].add(
|
244
|
-
response.meta
|
245
|
-
response.meta
|
244
|
+
response.meta.billed_units.input_tokens +
|
245
|
+
response.meta.billed_units.output_tokens, attributes)
|
246
246
|
metrics["genai_completion_tokens"].add(
|
247
|
-
response.meta
|
247
|
+
response.meta.billed_units.output_tokens, attributes)
|
248
248
|
metrics["genai_prompt_tokens"].add(
|
249
|
-
response.meta
|
249
|
+
response.meta.billed_units.input_tokens, attributes)
|
250
250
|
metrics["genai_cost"].record(cost, attributes)
|
251
251
|
|
252
252
|
# Return original response
|
@@ -307,8 +307,8 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
307
307
|
if event.event_type == "stream-end":
|
308
308
|
llmresponse = event.response.text
|
309
309
|
response_id = event.response.response_id
|
310
|
-
prompt_tokens = event.response.meta
|
311
|
-
completion_tokens = event.response.meta
|
310
|
+
prompt_tokens = event.response.meta.billed_units.input_tokens
|
311
|
+
completion_tokens = event.response.meta.billed_units.output_tokens
|
312
312
|
finish_reason = event.finish_reason
|
313
313
|
yield event
|
314
314
|
|
@@ -7,8 +7,7 @@ from wrapt import wrap_function_wrapper
|
|
7
7
|
|
8
8
|
from openlit.instrumentation.langchain.langchain import general_wrap, hub
|
9
9
|
|
10
|
-
_instruments = ("langchain >= 0.1.1",
|
11
|
-
"langchain-core > 0.1.1", "langchain-community >= 0.0.31")
|
10
|
+
_instruments = ("langchain >= 0.1.1",)
|
12
11
|
|
13
12
|
WRAPPED_METHODS = [
|
14
13
|
{
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openlit
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.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/open-lit/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
|
@@ -1,13 +1,13 @@
|
|
1
1
|
openlit/__helpers.py,sha256=G-QikEhscZIKxV372EQwW8oEqXKy11okykmvQ6VO_Ys,4649
|
2
|
-
openlit/__init__.py,sha256=
|
2
|
+
openlit/__init__.py,sha256=E1J6QPM0BiQAbOSetZ32yaw-Ikx4ZgvPemMP9XTdxFA,8795
|
3
3
|
openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
|
4
4
|
openlit/instrumentation/anthropic/anthropic.py,sha256=gLN7LrgbTTOxgO8TEn-mX7WCYVGExrIGB-_ueCLPMEY,15993
|
5
5
|
openlit/instrumentation/anthropic/async_anthropic.py,sha256=wb5U9aF3FtgPZ_1EZudsuKaB6wmOrEVwDIlfcEWnQqU,16035
|
6
6
|
openlit/instrumentation/chroma/__init__.py,sha256=61lFpHlUEQUobsUJZHXdvOViKwsOH8AOvSfc4VgCmiM,3253
|
7
7
|
openlit/instrumentation/chroma/chroma.py,sha256=wcY5sN-Lfdr4P56FDy8O_ft20gfxTDP12c2vIUF7Qno,10374
|
8
|
-
openlit/instrumentation/cohere/__init__.py,sha256=
|
9
|
-
openlit/instrumentation/cohere/cohere.py,sha256=
|
10
|
-
openlit/instrumentation/langchain/__init__.py,sha256=
|
8
|
+
openlit/instrumentation/cohere/__init__.py,sha256=PC5T1qIg9pwLNocBP_WjG5B_6p_z019s8quk_fNLAMs,1920
|
9
|
+
openlit/instrumentation/cohere/cohere.py,sha256=LdRMStLs-UTxDsGsTObEv-unC8g1tRFaU2EFCUBFGHI,20348
|
10
|
+
openlit/instrumentation/langchain/__init__.py,sha256=TW1ZR7I1i9Oig-wDWp3j1gmtQFO76jNBXQRBGGKzoOo,2531
|
11
11
|
openlit/instrumentation/langchain/langchain.py,sha256=D-PiYlmUW5SuE4rvKRMOsMGtW5wI6aA3ldig1JhXUok,7609
|
12
12
|
openlit/instrumentation/mistral/__init__.py,sha256=zJCIpFWRbsYrvooOJYuqwyuKeSOQLWbyXWCObL-Snks,3156
|
13
13
|
openlit/instrumentation/mistral/async_mistral.py,sha256=nD1ns326mclIUjd4PEfrSa8mufpoZqjYF1meK9oohkA,21328
|
@@ -24,7 +24,7 @@ openlit/instrumentation/transformers/transformers.py,sha256=peT0BGskYt7AZ0b93TZ7
|
|
24
24
|
openlit/otel/metrics.py,sha256=GdlQB1PpNvFAVbCqSTh7A87k6VVb1raHrW0y7xGSuQA,4293
|
25
25
|
openlit/otel/tracing.py,sha256=peismkno0YPoRezHPbF5Ycz15_oOBErn_coW1CPspHg,3612
|
26
26
|
openlit/semcov/__init__.py,sha256=n7lrz6xOwATtKF8cOWvhjr3JIrZ16sy3DXAW4Li2Q24,5686
|
27
|
-
openlit-0.0.
|
28
|
-
openlit-0.0.
|
29
|
-
openlit-0.0.
|
30
|
-
openlit-0.0.
|
27
|
+
openlit-0.0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
28
|
+
openlit-0.0.2.dist-info/METADATA,sha256=qNG41ZQC_-n7j1C5HqT7F-eQ7KTf1bUoZZm6CHxlH1U,6515
|
29
|
+
openlit-0.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
30
|
+
openlit-0.0.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|