opentelemetry-instrumentation-openai 0.15.4__py3-none-any.whl → 0.15.6__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.

@@ -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("openai", "ChatCompletion.create", chat_wrapper(tracer))
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("openai", "Embedding.create", embeddings_wrapper(tracer))
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.4"
1
+ __version__ = "0.15.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentelemetry-instrumentation-openai
3
- Version: 0.15.4
3
+ Version: 0.15.6
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
@@ -6,12 +6,12 @@ opentelemetry/instrumentation/openai/shared/config.py,sha256=Us6lUrKjNXPy8OLJ0Tk
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=z-ueiax_1LvNTSKI4M4Ha-jlfdAQXx3q4FcFecUOh4E,1613
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=Ypoj4dM4zqbnGvYnOqiUlHcf_l1wO2M39u5_-ECRTQU,23
14
- opentelemetry_instrumentation_openai-0.15.4.dist-info/METADATA,sha256=61f0I2u7XLLF5DKpy6uSDD2k1LbKwUic7QdDnbUM65E,2213
15
- opentelemetry_instrumentation_openai-0.15.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
- opentelemetry_instrumentation_openai-0.15.4.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
17
- opentelemetry_instrumentation_openai-0.15.4.dist-info/RECORD,,
13
+ opentelemetry/instrumentation/openai/version.py,sha256=So0qfsz_A4mujJ9XBWY4PqtrU6DdTz1l5TygxPTJj1Y,23
14
+ opentelemetry_instrumentation_openai-0.15.6.dist-info/METADATA,sha256=9PYb3SuwqESFcEHqce_hfma34zANQ0z6Jy1v-6GB2bE,2213
15
+ opentelemetry_instrumentation_openai-0.15.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
+ opentelemetry_instrumentation_openai-0.15.6.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
17
+ opentelemetry_instrumentation_openai-0.15.6.dist-info/RECORD,,