openlit 1.17.0__py3-none-any.whl → 1.18.0__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 +3 -0
- openlit/instrumentation/vllm/__init__.py +43 -0
- openlit/instrumentation/vllm/vllm.py +143 -0
- openlit/semcov/__init__.py +1 -0
- {openlit-1.17.0.dist-info → openlit-1.18.0.dist-info}/METADATA +3 -1
- {openlit-1.17.0.dist-info → openlit-1.18.0.dist-info}/RECORD +8 -6
- {openlit-1.17.0.dist-info → openlit-1.18.0.dist-info}/LICENSE +0 -0
- {openlit-1.17.0.dist-info → openlit-1.18.0.dist-info}/WHEEL +0 -0
openlit/__init__.py
CHANGED
@@ -32,6 +32,7 @@ from openlit.instrumentation.groq import GroqInstrumentor
|
|
32
32
|
from openlit.instrumentation.ollama import OllamaInstrumentor
|
33
33
|
from openlit.instrumentation.gpt4all import GPT4AllInstrumentor
|
34
34
|
from openlit.instrumentation.elevenlabs import ElevenLabsInstrumentor
|
35
|
+
from openlit.instrumentation.vllm import VLLMInstrumentor
|
35
36
|
from openlit.instrumentation.langchain import LangChainInstrumentor
|
36
37
|
from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
|
37
38
|
from openlit.instrumentation.haystack import HaystackInstrumentor
|
@@ -194,6 +195,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
194
195
|
"ollama": "ollama",
|
195
196
|
"gpt4all": "gpt4all",
|
196
197
|
"elevenlabs": "elevenlabs",
|
198
|
+
"vllm": "vllm",
|
197
199
|
"langchain": "langchain",
|
198
200
|
"llama_index": "llama_index",
|
199
201
|
"haystack": "haystack",
|
@@ -270,6 +272,7 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
|
|
270
272
|
"ollama": OllamaInstrumentor(),
|
271
273
|
"gpt4all": GPT4AllInstrumentor(),
|
272
274
|
"elevenlabs": ElevenLabsInstrumentor(),
|
275
|
+
"vllm": VLLMInstrumentor(),
|
273
276
|
"langchain": LangChainInstrumentor(),
|
274
277
|
"llama_index": LlamaIndexInstrumentor(),
|
275
278
|
"haystack": HaystackInstrumentor(),
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
|
+
"""Initializer of Auto Instrumentation of vLLM 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.vllm.vllm import (
|
10
|
+
generate
|
11
|
+
)
|
12
|
+
|
13
|
+
_instruments = ("vllm >= 0.5.4",)
|
14
|
+
|
15
|
+
class VLLMInstrumentor(BaseInstrumentor):
|
16
|
+
"""
|
17
|
+
An instrumentor for vLLM'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("vllm")
|
32
|
+
|
33
|
+
# sync chat
|
34
|
+
wrap_function_wrapper(
|
35
|
+
"vllm",
|
36
|
+
"LLM.generate",
|
37
|
+
generate("vllm.generate", version, environment, application_name,
|
38
|
+
tracer, pricing_info, trace_content, metrics, disable_metrics),
|
39
|
+
)
|
40
|
+
|
41
|
+
def _uninstrument(self, **kwargs):
|
42
|
+
# Proper uninstrumentation logic to revert patched methods
|
43
|
+
pass
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
|
2
|
+
"""
|
3
|
+
Module for monitoring vLLM 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 vLLM API.
|
25
|
+
tracer: OpenTelemetry tracer for creating spans.
|
26
|
+
pricing_info: Information used for calculating the cost of vLLM 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
|
+
# pylint: disable=line-too-long
|
51
|
+
with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
|
52
|
+
response = wrapped(*args, **kwargs)
|
53
|
+
|
54
|
+
try:
|
55
|
+
model = instance.llm_engine.model_config.model or "facebook/opt-125m"
|
56
|
+
# Set base span attribues
|
57
|
+
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
58
|
+
span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
|
59
|
+
SemanticConvetion.GEN_AI_SYSTEM_VLLM)
|
60
|
+
span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
|
61
|
+
SemanticConvetion.GEN_AI_TYPE_CHAT)
|
62
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
|
63
|
+
gen_ai_endpoint)
|
64
|
+
span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
|
65
|
+
environment)
|
66
|
+
span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
|
67
|
+
application_name)
|
68
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
69
|
+
model)
|
70
|
+
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
71
|
+
False)
|
72
|
+
input_tokens = 0
|
73
|
+
output_tokens = 0
|
74
|
+
cost = 0
|
75
|
+
|
76
|
+
if trace_content:
|
77
|
+
prompt_attributes = {}
|
78
|
+
completion_attributes = {}
|
79
|
+
|
80
|
+
for i, output in enumerate(response):
|
81
|
+
prompt_attributes[f"{SemanticConvetion.GEN_AI_CONTENT_PROMPT}.{i}"] = output.prompt
|
82
|
+
completion_attributes[f"{SemanticConvetion.GEN_AI_CONTENT_COMPLETION}.{i}"] = output.outputs[0].text
|
83
|
+
input_tokens += general_tokens(output.prompt)
|
84
|
+
output_tokens += general_tokens(output.outputs[0].text)
|
85
|
+
|
86
|
+
# Add a single event for all prompts
|
87
|
+
span.add_event(
|
88
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
89
|
+
attributes=prompt_attributes,
|
90
|
+
)
|
91
|
+
|
92
|
+
# Add a single event for all completions
|
93
|
+
span.add_event(
|
94
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
95
|
+
attributes=completion_attributes,
|
96
|
+
)
|
97
|
+
|
98
|
+
total_tokens = input_tokens + output_tokens
|
99
|
+
|
100
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
101
|
+
input_tokens)
|
102
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
103
|
+
output_tokens)
|
104
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
105
|
+
total_tokens)
|
106
|
+
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
107
|
+
cost)
|
108
|
+
|
109
|
+
span.set_status(Status(StatusCode.OK))
|
110
|
+
|
111
|
+
if disable_metrics is False:
|
112
|
+
attributes = {
|
113
|
+
TELEMETRY_SDK_NAME:
|
114
|
+
"openlit",
|
115
|
+
SemanticConvetion.GEN_AI_APPLICATION_NAME:
|
116
|
+
application_name,
|
117
|
+
SemanticConvetion.GEN_AI_SYSTEM:
|
118
|
+
SemanticConvetion.GEN_AI_SYSTEM_VLLM,
|
119
|
+
SemanticConvetion.GEN_AI_ENVIRONMENT:
|
120
|
+
environment,
|
121
|
+
SemanticConvetion.GEN_AI_TYPE:
|
122
|
+
SemanticConvetion.GEN_AI_TYPE_CHAT,
|
123
|
+
SemanticConvetion.GEN_AI_REQUEST_MODEL:
|
124
|
+
model
|
125
|
+
}
|
126
|
+
|
127
|
+
metrics["genai_requests"].add(1, attributes)
|
128
|
+
metrics["genai_total_tokens"].add(total_tokens, attributes)
|
129
|
+
metrics["genai_completion_tokens"].add(output_tokens, attributes)
|
130
|
+
metrics["genai_prompt_tokens"].add(input_tokens, attributes)
|
131
|
+
metrics["genai_cost"].record(cost, attributes)
|
132
|
+
|
133
|
+
# Return original response
|
134
|
+
return response
|
135
|
+
|
136
|
+
except Exception as e:
|
137
|
+
handle_exception(span, e)
|
138
|
+
logger.error("Error in trace creation: %s", e)
|
139
|
+
|
140
|
+
# Return original response
|
141
|
+
return response
|
142
|
+
|
143
|
+
return wrapper
|
openlit/semcov/__init__.py
CHANGED
@@ -101,6 +101,7 @@ class SemanticConvetion:
|
|
101
101
|
GEN_AI_SYSTEM_OLLAMA = "ollama"
|
102
102
|
GEN_AI_SYSTEM_GPT4ALL = "gpt4all"
|
103
103
|
GEN_AI_SYSTEM_ELEVENLABS = "elevenlabs"
|
104
|
+
GEN_AI_SYSTEM_VLLM = "vLLM"
|
104
105
|
GEN_AI_SYSTEM_LANGCHAIN = "langchain"
|
105
106
|
GEN_AI_SYSTEM_LLAMAINDEX = "llama_index"
|
106
107
|
GEN_AI_SYSTEM_HAYSTACK = "haystack"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openlit
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.18.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
|
@@ -68,6 +68,8 @@ This project adheres to the [Semantic Conventions](https://github.com/open-telem
|
|
68
68
|
| [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | | | |
|
69
69
|
| [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | | | |
|
70
70
|
| [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |
|
71
|
+
| [✅ vLLM](https://docs.openlit.io/latest/integrations/vllm) | | | |
|
72
|
+
|
71
73
|
## Supported Destinations
|
72
74
|
- [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
|
73
75
|
- [✅ Prometheus + Tempo](https://docs.openlit.io/latest/connections/prometheus-tempo)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
openlit/__helpers.py,sha256=lrn4PBs9owDudiCY2NBoVbAi7AU_HtUpyOj0oqPBsPY,5545
|
2
|
-
openlit/__init__.py,sha256=
|
2
|
+
openlit/__init__.py,sha256=LfU5w-D62u5pY70DdNbv5_DGtqeL1Yb0TlY-l0NAn8I,15103
|
3
3
|
openlit/instrumentation/anthropic/__init__.py,sha256=oaU53BOPyfUKbEzYvLr1DPymDluurSnwo4Hernf2XdU,1955
|
4
4
|
openlit/instrumentation/anthropic/anthropic.py,sha256=y7CEGhKOGHWt8G_5Phr4qPJTfPGRJIAr9Yk6nM3CcvM,16775
|
5
5
|
openlit/instrumentation/anthropic/async_anthropic.py,sha256=Zz1KRKIG9wGn0quOoLvjORC-49IvHQpJ6GBdB-4PfCQ,16816
|
@@ -48,10 +48,12 @@ openlit/instrumentation/transformers/transformers.py,sha256=KNAT2ROjziW6OAP6Y0Ec
|
|
48
48
|
openlit/instrumentation/vertexai/__init__.py,sha256=N3E9HtzefD-zC0fvmfGYiDmSqssoavp_i59wfuYLyMw,6079
|
49
49
|
openlit/instrumentation/vertexai/async_vertexai.py,sha256=8JwSwLPPA4lAatf4w_5kJ5_YZDLwl5yG8N59cTD-EZM,55198
|
50
50
|
openlit/instrumentation/vertexai/vertexai.py,sha256=R6dDQfC3YFoZDygxU2fkflcMsqIv8AVoU3XOwWSvpwA,54951
|
51
|
+
openlit/instrumentation/vllm/__init__.py,sha256=OVWalQ1dXvip1DUsjUGaHX4J-2FrSp-T-qCVOfw7OZo,1495
|
52
|
+
openlit/instrumentation/vllm/vllm.py,sha256=lDzM7F5pgxvh8nKL0dcKB4TD0Mc9wXOWeXOsOGN7Wd8,6527
|
51
53
|
openlit/otel/metrics.py,sha256=O7NoaDz0bY19mqpE4-0PcKwEe-B-iJFRgOCaanAuZAc,4291
|
52
54
|
openlit/otel/tracing.py,sha256=vL1ifMbARPBpqK--yXYsCM6y5dSu5LFIKqkhZXtYmUc,3712
|
53
|
-
openlit/semcov/__init__.py,sha256=
|
54
|
-
openlit-1.
|
55
|
-
openlit-1.
|
56
|
-
openlit-1.
|
57
|
-
openlit-1.
|
55
|
+
openlit/semcov/__init__.py,sha256=EvoNOKtc7UKwLZ3Gp0-B1zwmeTcAIbx8O7wvAw8wXP4,7498
|
56
|
+
openlit-1.18.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
57
|
+
openlit-1.18.0.dist-info/METADATA,sha256=LzRSgLCKr0x6Vr8YwhFkPCEuTbF_NfQtpQTpMdiXCqo,14334
|
58
|
+
openlit-1.18.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
59
|
+
openlit-1.18.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|