opentelemetry-instrumentation-openai 0.15.3__py3-none-any.whl → 0.15.5__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.
Potentially problematic release.
This version of opentelemetry-instrumentation-openai might be problematic. Click here for more details.
- opentelemetry/instrumentation/openai/shared/__init__.py +5 -0
- opentelemetry/instrumentation/openai/v0/__init__.py +106 -2
- opentelemetry/instrumentation/openai/version.py +1 -1
- {opentelemetry_instrumentation_openai-0.15.3.dist-info → opentelemetry_instrumentation_openai-0.15.5.dist-info}/METADATA +1 -1
- {opentelemetry_instrumentation_openai-0.15.3.dist-info → opentelemetry_instrumentation_openai-0.15.5.dist-info}/RECORD +7 -7
- {opentelemetry_instrumentation_openai-0.15.3.dist-info → opentelemetry_instrumentation_openai-0.15.5.dist-info}/WHEEL +0 -0
- {opentelemetry_instrumentation_openai-0.15.3.dist-info → opentelemetry_instrumentation_openai-0.15.5.dist-info}/entry_points.txt +0 -0
|
@@ -134,6 +134,11 @@ def _set_request_attributes(span, kwargs):
|
|
|
134
134
|
_set_span_attribute(
|
|
135
135
|
span, SpanAttributes.LLM_HEADERS, str(kwargs.get("headers"))
|
|
136
136
|
)
|
|
137
|
+
# The new OpenAI SDK removed the `headers` and create new field called `extra_headers`
|
|
138
|
+
if kwargs.get("extra_headers") is not None:
|
|
139
|
+
_set_span_attribute(
|
|
140
|
+
span, SpanAttributes.LLM_HEADERS, str(kwargs.get("extra_headers"))
|
|
141
|
+
)
|
|
137
142
|
_set_span_attribute(
|
|
138
143
|
span, SpanAttributes.LLM_IS_STREAMING, kwargs.get("stream") or False
|
|
139
144
|
)
|
|
@@ -2,6 +2,7 @@ from typing import Collection
|
|
|
2
2
|
|
|
3
3
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
4
4
|
from opentelemetry.trace import get_tracer
|
|
5
|
+
from opentelemetry.metrics import get_meter
|
|
5
6
|
from wrapt import wrap_function_wrapper
|
|
6
7
|
|
|
7
8
|
from opentelemetry.instrumentation.openai.shared.chat_wrappers import (
|
|
@@ -16,6 +17,7 @@ from opentelemetry.instrumentation.openai.shared.embeddings_wrappers import (
|
|
|
16
17
|
embeddings_wrapper,
|
|
17
18
|
aembeddings_wrapper,
|
|
18
19
|
)
|
|
20
|
+
from opentelemetry.instrumentation.openai.utils import is_metrics_enabled
|
|
19
21
|
from opentelemetry.instrumentation.openai.version import __version__
|
|
20
22
|
|
|
21
23
|
_instruments = ("openai >= 0.27.0", "openai < 1.0.0")
|
|
@@ -29,13 +31,115 @@ class OpenAIV0Instrumentor(BaseInstrumentor):
|
|
|
29
31
|
tracer_provider = kwargs.get("tracer_provider")
|
|
30
32
|
tracer = get_tracer(__name__, __version__, tracer_provider)
|
|
31
33
|
|
|
34
|
+
meter_provider = kwargs.get("meter_provider")
|
|
35
|
+
meter = get_meter(__name__, __version__, meter_provider)
|
|
36
|
+
|
|
37
|
+
if is_metrics_enabled():
|
|
38
|
+
chat_token_counter = meter.create_counter(
|
|
39
|
+
name="llm.openai.chat_completions.tokens",
|
|
40
|
+
unit="token",
|
|
41
|
+
description="Number of tokens used in prompt and completions",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
chat_choice_counter = meter.create_counter(
|
|
45
|
+
name="llm.openai.chat_completions.choices",
|
|
46
|
+
unit="choice",
|
|
47
|
+
description="Number of choices returned by chat completions call",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
chat_duration_histogram = meter.create_histogram(
|
|
51
|
+
name="llm.openai.chat_completions.duration",
|
|
52
|
+
unit="s",
|
|
53
|
+
description="Duration of chat completion operation",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
chat_exception_counter = meter.create_counter(
|
|
57
|
+
name="llm.openai.chat_completions.exceptions",
|
|
58
|
+
unit="time",
|
|
59
|
+
description="Number of exceptions occurred during chat completions",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
streaming_time_to_first_token = meter.create_histogram(
|
|
63
|
+
name="llm.openai.chat_completions.streaming_time_to_first_token",
|
|
64
|
+
unit="s",
|
|
65
|
+
description="Time to first token in streaming chat completions",
|
|
66
|
+
)
|
|
67
|
+
streaming_time_to_generate = meter.create_histogram(
|
|
68
|
+
name="llm.openai.chat_completions.streaming_time_to_generate",
|
|
69
|
+
unit="s",
|
|
70
|
+
description="Time between first token and completion in streaming chat completions",
|
|
71
|
+
)
|
|
72
|
+
else:
|
|
73
|
+
(
|
|
74
|
+
chat_token_counter,
|
|
75
|
+
chat_choice_counter,
|
|
76
|
+
chat_duration_histogram,
|
|
77
|
+
chat_exception_counter,
|
|
78
|
+
streaming_time_to_first_token,
|
|
79
|
+
streaming_time_to_generate,
|
|
80
|
+
) = (None, None, None, None, None, None)
|
|
81
|
+
|
|
82
|
+
if is_metrics_enabled():
|
|
83
|
+
embeddings_token_counter = meter.create_counter(
|
|
84
|
+
name="llm.openai.embeddings.tokens",
|
|
85
|
+
unit="token",
|
|
86
|
+
description="Number of tokens used in prompt and completions",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
embeddings_vector_size_counter = meter.create_counter(
|
|
90
|
+
name="llm.openai.embeddings.vector_size",
|
|
91
|
+
unit="element",
|
|
92
|
+
description="he size of returned vector",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
embeddings_duration_histogram = meter.create_histogram(
|
|
96
|
+
name="llm.openai.embeddings.duration",
|
|
97
|
+
unit="s",
|
|
98
|
+
description="Duration of embeddings operation",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
embeddings_exception_counter = meter.create_counter(
|
|
102
|
+
name="llm.openai.embeddings.exceptions",
|
|
103
|
+
unit="time",
|
|
104
|
+
description="Number of exceptions occurred during embeddings operation",
|
|
105
|
+
)
|
|
106
|
+
else:
|
|
107
|
+
(
|
|
108
|
+
embeddings_token_counter,
|
|
109
|
+
embeddings_vector_size_counter,
|
|
110
|
+
embeddings_duration_histogram,
|
|
111
|
+
embeddings_exception_counter,
|
|
112
|
+
) = (None, None, None, None)
|
|
113
|
+
|
|
32
114
|
wrap_function_wrapper("openai", "Completion.create", completion_wrapper(tracer))
|
|
33
115
|
wrap_function_wrapper(
|
|
34
116
|
"openai", "Completion.acreate", acompletion_wrapper(tracer)
|
|
35
117
|
)
|
|
36
|
-
wrap_function_wrapper(
|
|
118
|
+
wrap_function_wrapper(
|
|
119
|
+
"openai",
|
|
120
|
+
"ChatCompletion.create",
|
|
121
|
+
chat_wrapper(
|
|
122
|
+
tracer,
|
|
123
|
+
chat_token_counter,
|
|
124
|
+
chat_choice_counter,
|
|
125
|
+
chat_duration_histogram,
|
|
126
|
+
chat_exception_counter,
|
|
127
|
+
streaming_time_to_first_token,
|
|
128
|
+
streaming_time_to_generate,
|
|
129
|
+
),
|
|
130
|
+
)
|
|
37
131
|
wrap_function_wrapper("openai", "ChatCompletion.acreate", achat_wrapper(tracer))
|
|
38
|
-
wrap_function_wrapper(
|
|
132
|
+
wrap_function_wrapper(
|
|
133
|
+
"openai",
|
|
134
|
+
"Embedding.create",
|
|
135
|
+
embeddings_wrapper(
|
|
136
|
+
tracer,
|
|
137
|
+
embeddings_token_counter,
|
|
138
|
+
embeddings_vector_size_counter,
|
|
139
|
+
embeddings_duration_histogram,
|
|
140
|
+
embeddings_exception_counter,
|
|
141
|
+
),
|
|
142
|
+
)
|
|
39
143
|
wrap_function_wrapper(
|
|
40
144
|
"openai", "Embedding.acreate", aembeddings_wrapper(tracer)
|
|
41
145
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.15.
|
|
1
|
+
__version__ = "0.15.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: opentelemetry-instrumentation-openai
|
|
3
|
-
Version: 0.15.
|
|
3
|
+
Version: 0.15.5
|
|
4
4
|
Summary: OpenTelemetry OpenAI instrumentation
|
|
5
5
|
Home-page: https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-openai
|
|
6
6
|
License: Apache-2.0
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
opentelemetry/instrumentation/openai/__init__.py,sha256=RtjRSDcPG5QYh4wAuu_Szu3PgBSUewxQta5c5jrMEjY,1142
|
|
2
|
-
opentelemetry/instrumentation/openai/shared/__init__.py,sha256=
|
|
2
|
+
opentelemetry/instrumentation/openai/shared/__init__.py,sha256=90IJchM1dSyANvSTSXbGQaL04mxLRQOTTZHhZP8CUko,8399
|
|
3
3
|
opentelemetry/instrumentation/openai/shared/chat_wrappers.py,sha256=LvoZNowNh7KhTWgvp528Ma-Wrd506yPYLveBvgeT8p4,13697
|
|
4
4
|
opentelemetry/instrumentation/openai/shared/completion_wrappers.py,sha256=xg9qNqijT5ZJOk509l9Q7kVHLwo88DUH-Uv4tzSkeOQ,7045
|
|
5
5
|
opentelemetry/instrumentation/openai/shared/config.py,sha256=Us6lUrKjNXPy8OLJ0Tk2VFsbOKSNTDYY-f8ByEL2LOA,43
|
|
6
6
|
opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py,sha256=zr7qsH5bpnRMahErgstpphLI-XPN8y7Pxh2_39Oo4Ds,5573
|
|
7
7
|
opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py,sha256=SnmhXnnO5pyc0x9wvbYb1S_OVM4TYr7qeJPZbs3YxJg,1899
|
|
8
8
|
opentelemetry/instrumentation/openai/utils.py,sha256=aHudimT_OE170ip_AGq9BSiD62pu2_sKGAGyFrY9X9U,2404
|
|
9
|
-
opentelemetry/instrumentation/openai/v0/__init__.py,sha256=
|
|
9
|
+
opentelemetry/instrumentation/openai/v0/__init__.py,sha256=lwKZYa7zhYoEKw9hNQAQ68MZnaYA4-nqJrDUcm2I4ZA,5554
|
|
10
10
|
opentelemetry/instrumentation/openai/v1/__init__.py,sha256=A9X07leoMeErJaBGMMXAD5nYPc6xaUj2Ng5mriOsZ8Q,8162
|
|
11
11
|
opentelemetry/instrumentation/openai/v1/assistant_wrappers.py,sha256=T6Vtdp1fAZdcYjGiTMZwkn4F4DgsltD4p4xLEFW-GhI,5874
|
|
12
12
|
opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py,sha256=SAzYoun2yyOloofyOWtxpm8E2M9TL3Nm8TgKdNyXHuY,2779
|
|
13
|
-
opentelemetry/instrumentation/openai/version.py,sha256=
|
|
14
|
-
opentelemetry_instrumentation_openai-0.15.
|
|
15
|
-
opentelemetry_instrumentation_openai-0.15.
|
|
16
|
-
opentelemetry_instrumentation_openai-0.15.
|
|
17
|
-
opentelemetry_instrumentation_openai-0.15.
|
|
13
|
+
opentelemetry/instrumentation/openai/version.py,sha256=axkldpLAi2TFk3heerDJg_kSegHyvqyTI3ogd991rpE,23
|
|
14
|
+
opentelemetry_instrumentation_openai-0.15.5.dist-info/METADATA,sha256=rMv8evgUd1ppj9zDFSyowHvuuM4YXTRPpskMziSqYEQ,2213
|
|
15
|
+
opentelemetry_instrumentation_openai-0.15.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
16
|
+
opentelemetry_instrumentation_openai-0.15.5.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
|
|
17
|
+
opentelemetry_instrumentation_openai-0.15.5.dist-info/RECORD,,
|
|
File without changes
|