openlit 1.34.20__py3-none-any.whl → 1.34.22__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/__helpers.py +40 -0
- openlit/instrumentation/openai/__init__.py +63 -68
- openlit/instrumentation/openai/async_openai.py +203 -1277
- openlit/instrumentation/openai/openai.py +200 -1274
- openlit/instrumentation/openai/utils.py +794 -0
- openlit/instrumentation/vertexai/__init__.py +18 -23
- openlit/instrumentation/vertexai/async_vertexai.py +46 -364
- openlit/instrumentation/vertexai/utils.py +204 -0
- openlit/instrumentation/vertexai/vertexai.py +46 -364
- {openlit-1.34.20.dist-info → openlit-1.34.22.dist-info}/METADATA +1 -1
- {openlit-1.34.20.dist-info → openlit-1.34.22.dist-info}/RECORD +13 -11
- {openlit-1.34.20.dist-info → openlit-1.34.22.dist-info}/LICENSE +0 -0
- {openlit-1.34.20.dist-info → openlit-1.34.22.dist-info}/WHEEL +0 -0
openlit/__helpers.py
CHANGED
@@ -402,3 +402,43 @@ def record_embedding_metrics(metrics, gen_ai_operation, gen_ai_system, server_ad
|
|
402
402
|
metrics["genai_requests"].add(1, attributes)
|
403
403
|
metrics["genai_prompt_tokens"].add(input_tokens, attributes)
|
404
404
|
metrics["genai_cost"].record(cost, attributes)
|
405
|
+
|
406
|
+
def record_audio_metrics(metrics, gen_ai_operation, gen_ai_system, server_address, server_port,
|
407
|
+
request_model, response_model, environment, application_name, start_time, end_time, cost):
|
408
|
+
"""
|
409
|
+
Record audio-specific metrics for the operation.
|
410
|
+
"""
|
411
|
+
|
412
|
+
attributes = create_metrics_attributes(
|
413
|
+
operation=gen_ai_operation,
|
414
|
+
system=gen_ai_system,
|
415
|
+
server_address=server_address,
|
416
|
+
server_port=server_port,
|
417
|
+
request_model=request_model,
|
418
|
+
response_model=response_model,
|
419
|
+
service_name=application_name,
|
420
|
+
deployment_environment=environment,
|
421
|
+
)
|
422
|
+
metrics["genai_client_operation_duration"].record(end_time - start_time, attributes)
|
423
|
+
metrics["genai_requests"].add(1, attributes)
|
424
|
+
metrics["genai_cost"].record(cost, attributes)
|
425
|
+
|
426
|
+
def record_image_metrics(metrics, gen_ai_operation, gen_ai_system, server_address, server_port,
|
427
|
+
request_model, response_model, environment, application_name, start_time, end_time, cost):
|
428
|
+
"""
|
429
|
+
Record image-specific metrics for the operation.
|
430
|
+
"""
|
431
|
+
|
432
|
+
attributes = create_metrics_attributes(
|
433
|
+
operation=gen_ai_operation,
|
434
|
+
system=gen_ai_system,
|
435
|
+
server_address=server_address,
|
436
|
+
server_port=server_port,
|
437
|
+
request_model=request_model,
|
438
|
+
response_model=response_model,
|
439
|
+
service_name=application_name,
|
440
|
+
deployment_environment=environment,
|
441
|
+
)
|
442
|
+
metrics["genai_client_operation_duration"].record(end_time - start_time, attributes)
|
443
|
+
metrics["genai_requests"].add(1, attributes)
|
444
|
+
metrics["genai_cost"].record(cost, attributes)
|
@@ -1,147 +1,142 @@
|
|
1
|
-
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
1
|
"""Initializer of Auto Instrumentation of OpenAI Functions"""
|
3
2
|
from typing import Collection
|
4
3
|
import importlib.metadata
|
5
4
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
6
5
|
from wrapt import wrap_function_wrapper
|
7
6
|
|
8
|
-
from openlit.instrumentation.openai.openai import
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
from openlit.instrumentation.openai.async_openai import
|
13
|
-
|
7
|
+
from openlit.instrumentation.openai.openai import (
|
8
|
+
chat_completions, embedding, responses, chat_completions_parse,
|
9
|
+
image_generate, image_variatons, audio_create
|
10
|
+
)
|
11
|
+
from openlit.instrumentation.openai.async_openai import (
|
12
|
+
async_chat_completions, async_embedding, async_chat_completions_parse,
|
13
|
+
async_image_generate, async_image_variations, async_audio_create, async_responses
|
14
|
+
)
|
14
15
|
|
15
16
|
_instruments = ("openai >= 1.92.0",)
|
16
17
|
|
17
18
|
class OpenAIInstrumentor(BaseInstrumentor):
|
18
|
-
"""
|
19
|
+
"""
|
20
|
+
An instrumentor for OpenAI client library.
|
21
|
+
"""
|
19
22
|
|
20
23
|
def instrumentation_dependencies(self) -> Collection[str]:
|
21
24
|
return _instruments
|
22
25
|
|
23
26
|
def _instrument(self, **kwargs):
|
24
|
-
|
25
|
-
environment = kwargs.get("environment")
|
27
|
+
version = importlib.metadata.version("openai")
|
28
|
+
environment = kwargs.get("environment", "default")
|
29
|
+
application_name = kwargs.get("application_name", "default")
|
26
30
|
tracer = kwargs.get("tracer")
|
31
|
+
pricing_info = kwargs.get("pricing_info", {})
|
32
|
+
capture_message_content = kwargs.get("capture_message_content", False)
|
27
33
|
metrics = kwargs.get("metrics_dict")
|
28
|
-
pricing_info = kwargs.get("pricing_info")
|
29
|
-
capture_message_content = kwargs.get("capture_message_content")
|
30
34
|
disable_metrics = kwargs.get("disable_metrics")
|
31
|
-
version = importlib.metadata.version("openai")
|
32
35
|
|
36
|
+
# chat completions
|
33
37
|
wrap_function_wrapper(
|
34
38
|
"openai.resources.chat.completions",
|
35
39
|
"Completions.create",
|
36
40
|
chat_completions(version, environment, application_name,
|
37
|
-
|
38
|
-
metrics, disable_metrics),
|
41
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
39
42
|
)
|
40
43
|
|
41
44
|
wrap_function_wrapper(
|
42
45
|
"openai.resources.chat.completions",
|
43
46
|
"AsyncCompletions.create",
|
44
47
|
async_chat_completions(version, environment, application_name,
|
45
|
-
|
46
|
-
metrics, disable_metrics),
|
48
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
47
49
|
)
|
48
50
|
|
51
|
+
# chat completions parse
|
49
52
|
wrap_function_wrapper(
|
50
|
-
"openai.resources.
|
51
|
-
"
|
52
|
-
|
53
|
-
|
54
|
-
metrics, disable_metrics),
|
53
|
+
"openai.resources.chat.completions",
|
54
|
+
"Completions.parse",
|
55
|
+
chat_completions_parse(version, environment, application_name,
|
56
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
55
57
|
)
|
56
58
|
|
57
59
|
wrap_function_wrapper(
|
58
|
-
"openai.resources.
|
59
|
-
"
|
60
|
-
|
61
|
-
|
62
|
-
metrics, disable_metrics),
|
60
|
+
"openai.resources.chat.completions",
|
61
|
+
"AsyncCompletions.parse",
|
62
|
+
async_chat_completions_parse(version, environment, application_name,
|
63
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
63
64
|
)
|
64
65
|
|
66
|
+
# responses
|
65
67
|
wrap_function_wrapper(
|
66
|
-
"openai.resources.
|
67
|
-
"
|
68
|
-
|
69
|
-
|
70
|
-
metrics, disable_metrics),
|
68
|
+
"openai.resources.responses.responses",
|
69
|
+
"Responses.create",
|
70
|
+
responses(version, environment, application_name,
|
71
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
71
72
|
)
|
72
73
|
|
73
74
|
wrap_function_wrapper(
|
74
|
-
"openai.resources.
|
75
|
-
"
|
76
|
-
|
77
|
-
|
78
|
-
metrics, disable_metrics),
|
75
|
+
"openai.resources.responses.responses",
|
76
|
+
"AsyncResponses.create",
|
77
|
+
async_responses(version, environment, application_name,
|
78
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
79
79
|
)
|
80
80
|
|
81
|
+
# embeddings
|
81
82
|
wrap_function_wrapper(
|
82
83
|
"openai.resources.embeddings",
|
83
84
|
"Embeddings.create",
|
84
85
|
embedding(version, environment, application_name,
|
85
|
-
|
86
|
-
metrics, disable_metrics),
|
86
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
87
87
|
)
|
88
88
|
|
89
89
|
wrap_function_wrapper(
|
90
90
|
"openai.resources.embeddings",
|
91
91
|
"AsyncEmbeddings.create",
|
92
92
|
async_embedding(version, environment, application_name,
|
93
|
-
|
94
|
-
|
93
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
94
|
+
)
|
95
|
+
|
96
|
+
# image generation
|
97
|
+
wrap_function_wrapper(
|
98
|
+
"openai.resources.images",
|
99
|
+
"Images.generate",
|
100
|
+
image_generate(version, environment, application_name,
|
101
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
95
102
|
)
|
96
103
|
|
104
|
+
wrap_function_wrapper(
|
105
|
+
"openai.resources.images",
|
106
|
+
"AsyncImages.generate",
|
107
|
+
async_image_generate(version, environment, application_name,
|
108
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
109
|
+
)
|
110
|
+
|
111
|
+
# image variations
|
97
112
|
wrap_function_wrapper(
|
98
113
|
"openai.resources.images",
|
99
114
|
"Images.create_variation",
|
100
|
-
image_variatons(version,
|
101
|
-
|
102
|
-
tracer, pricing_info, capture_message_content,
|
103
|
-
metrics, disable_metrics),
|
115
|
+
image_variatons(version, environment, application_name,
|
116
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
104
117
|
)
|
105
118
|
|
106
119
|
wrap_function_wrapper(
|
107
120
|
"openai.resources.images",
|
108
121
|
"AsyncImages.create_variation",
|
109
|
-
|
110
|
-
|
111
|
-
tracer, pricing_info, capture_message_content,
|
112
|
-
metrics, disable_metrics),
|
122
|
+
async_image_variations(version, environment, application_name,
|
123
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
113
124
|
)
|
114
125
|
|
126
|
+
# audio generation
|
115
127
|
wrap_function_wrapper(
|
116
128
|
"openai.resources.audio.speech",
|
117
129
|
"Speech.create",
|
118
130
|
audio_create(version, environment, application_name,
|
119
|
-
|
120
|
-
metrics, disable_metrics),
|
131
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
121
132
|
)
|
122
133
|
|
123
134
|
wrap_function_wrapper(
|
124
135
|
"openai.resources.audio.speech",
|
125
136
|
"AsyncSpeech.create",
|
126
137
|
async_audio_create(version, environment, application_name,
|
127
|
-
|
128
|
-
metrics, disable_metrics),
|
129
|
-
)
|
130
|
-
|
131
|
-
wrap_function_wrapper(
|
132
|
-
"openai.resources.chat.completions",
|
133
|
-
"Completions.parse",
|
134
|
-
chat_completions_parse(version, environment, application_name, tracer, pricing_info,
|
135
|
-
capture_message_content, metrics, disable_metrics),
|
136
|
-
)
|
137
|
-
|
138
|
-
wrap_function_wrapper(
|
139
|
-
"openai.resources.chat.completions",
|
140
|
-
"AsyncCompletions.parse",
|
141
|
-
async_chat_completions_parse(version, environment, application_name, tracer, pricing_info,
|
142
|
-
capture_message_content, metrics, disable_metrics),
|
138
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
143
139
|
)
|
144
140
|
|
145
|
-
@staticmethod
|
146
141
|
def _uninstrument(self, **kwargs):
|
147
142
|
pass
|