opentelemetry-instrumentation-openai 0.31.2__py3-none-any.whl → 0.31.3__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/__init__.py +5 -2
- opentelemetry/instrumentation/openai/shared/chat_wrappers.py +19 -19
- opentelemetry/instrumentation/openai/version.py +1 -1
- {opentelemetry_instrumentation_openai-0.31.2.dist-info → opentelemetry_instrumentation_openai-0.31.3.dist-info}/METADATA +1 -1
- {opentelemetry_instrumentation_openai-0.31.2.dist-info → opentelemetry_instrumentation_openai-0.31.3.dist-info}/RECORD +7 -7
- {opentelemetry_instrumentation_openai-0.31.2.dist-info → opentelemetry_instrumentation_openai-0.31.3.dist-info}/WHEEL +0 -0
- {opentelemetry_instrumentation_openai-0.31.2.dist-info → opentelemetry_instrumentation_openai-0.31.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from typing import Callable, Collection
|
|
1
|
+
from typing import Callable, Collection, Optional
|
|
2
|
+
from typing_extensions import Coroutine
|
|
2
3
|
|
|
3
4
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
4
5
|
|
|
@@ -19,7 +20,9 @@ class OpenAIInstrumentor(BaseInstrumentor):
|
|
|
19
20
|
enrich_token_usage: bool = False,
|
|
20
21
|
exception_logger=None,
|
|
21
22
|
get_common_metrics_attributes: Callable[[], dict] = lambda: {},
|
|
22
|
-
upload_base64_image:
|
|
23
|
+
upload_base64_image: Optional[
|
|
24
|
+
Callable[[str, str, str, str], Coroutine[None, None, str]]
|
|
25
|
+
] = lambda *args: "",
|
|
23
26
|
):
|
|
24
27
|
super().__init__()
|
|
25
28
|
Config.enrich_assistant = enrich_assistant
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import copy
|
|
2
3
|
import json
|
|
3
4
|
import logging
|
|
@@ -69,15 +70,15 @@ def chat_wrapper(
|
|
|
69
70
|
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY
|
|
70
71
|
):
|
|
71
72
|
return wrapped(*args, **kwargs)
|
|
72
|
-
|
|
73
73
|
# span needs to be opened and closed manually because the response is a generator
|
|
74
|
+
|
|
74
75
|
span = tracer.start_span(
|
|
75
76
|
SPAN_NAME,
|
|
76
77
|
kind=SpanKind.CLIENT,
|
|
77
78
|
attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value},
|
|
78
79
|
)
|
|
79
80
|
|
|
80
|
-
_handle_request(span, kwargs, instance)
|
|
81
|
+
asyncio.run(_handle_request(span, kwargs, instance))
|
|
81
82
|
|
|
82
83
|
try:
|
|
83
84
|
start_time = time.time()
|
|
@@ -167,7 +168,7 @@ async def achat_wrapper(
|
|
|
167
168
|
kind=SpanKind.CLIENT,
|
|
168
169
|
attributes={SpanAttributes.LLM_REQUEST_TYPE: LLM_REQUEST_TYPE.value},
|
|
169
170
|
)
|
|
170
|
-
_handle_request(span, kwargs, instance)
|
|
171
|
+
await _handle_request(span, kwargs, instance)
|
|
171
172
|
|
|
172
173
|
try:
|
|
173
174
|
start_time = time.time()
|
|
@@ -236,11 +237,11 @@ async def achat_wrapper(
|
|
|
236
237
|
|
|
237
238
|
|
|
238
239
|
@dont_throw
|
|
239
|
-
def _handle_request(span, kwargs, instance):
|
|
240
|
+
async def _handle_request(span, kwargs, instance):
|
|
240
241
|
_set_request_attributes(span, kwargs)
|
|
241
242
|
_set_client_attributes(span, instance)
|
|
242
243
|
if should_send_prompts():
|
|
243
|
-
_set_prompts(span, kwargs.get("messages"))
|
|
244
|
+
await _set_prompts(span, kwargs.get("messages"))
|
|
244
245
|
if kwargs.get("functions"):
|
|
245
246
|
_set_functions_attributes(span, kwargs.get("functions"))
|
|
246
247
|
elif kwargs.get("tools"):
|
|
@@ -331,33 +332,28 @@ def _is_base64_image(item):
|
|
|
331
332
|
if not isinstance(item, dict):
|
|
332
333
|
return False
|
|
333
334
|
|
|
334
|
-
if not isinstance(item.get(
|
|
335
|
+
if not isinstance(item.get("image_url"), dict):
|
|
335
336
|
return False
|
|
336
337
|
|
|
337
|
-
if
|
|
338
|
+
if "data:image/" not in item.get("image_url", {}).get("url", ""):
|
|
338
339
|
return False
|
|
339
340
|
|
|
340
341
|
return True
|
|
341
342
|
|
|
342
343
|
|
|
343
|
-
def _process_image_item(item, trace_id, span_id, message_index, content_index):
|
|
344
|
+
async def _process_image_item(item, trace_id, span_id, message_index, content_index):
|
|
344
345
|
if not Config.upload_base64_image:
|
|
345
346
|
return item
|
|
346
347
|
|
|
347
348
|
image_format = item["image_url"]["url"].split(";")[0].split("/")[1]
|
|
348
349
|
image_name = f"message_{message_index}_content_{content_index}.{image_format}"
|
|
349
350
|
base64_string = item["image_url"]["url"].split(",")[1]
|
|
350
|
-
url = Config.upload_base64_image(trace_id, span_id, image_name, base64_string)
|
|
351
|
+
url = await Config.upload_base64_image(trace_id, span_id, image_name, base64_string)
|
|
351
352
|
|
|
352
|
-
return {
|
|
353
|
-
'type': 'image_url',
|
|
354
|
-
'image_url': {
|
|
355
|
-
'url': url
|
|
356
|
-
}
|
|
357
|
-
}
|
|
353
|
+
return {"type": "image_url", "image_url": {"url": url}}
|
|
358
354
|
|
|
359
355
|
|
|
360
|
-
def _set_prompts(span, messages):
|
|
356
|
+
async def _set_prompts(span, messages):
|
|
361
357
|
if not span.is_recording() or messages is None:
|
|
362
358
|
return
|
|
363
359
|
|
|
@@ -369,9 +365,13 @@ def _set_prompts(span, messages):
|
|
|
369
365
|
content = copy.deepcopy(msg.get("content"))
|
|
370
366
|
if isinstance(content, list):
|
|
371
367
|
content = [
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
368
|
+
(
|
|
369
|
+
await _process_image_item(
|
|
370
|
+
item, span.context.trace_id, span.context.span_id, i, j
|
|
371
|
+
)
|
|
372
|
+
if _is_base64_image(item)
|
|
373
|
+
else item
|
|
374
|
+
)
|
|
375
375
|
for j, item in enumerate(content)
|
|
376
376
|
]
|
|
377
377
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.31.
|
|
1
|
+
__version__ = "0.31.3"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: opentelemetry-instrumentation-openai
|
|
3
|
-
Version: 0.31.
|
|
3
|
+
Version: 0.31.3
|
|
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,6 +1,6 @@
|
|
|
1
|
-
opentelemetry/instrumentation/openai/__init__.py,sha256=
|
|
1
|
+
opentelemetry/instrumentation/openai/__init__.py,sha256=ZNytfy9PeGr-O4qkyCQLtANukfPlnOEynsXJ_5L75oU,1750
|
|
2
2
|
opentelemetry/instrumentation/openai/shared/__init__.py,sha256=HcS1Ar6WX9DPtlJuiPji3u7XV_SwYerTf5O32Kfe1FQ,8839
|
|
3
|
-
opentelemetry/instrumentation/openai/shared/chat_wrappers.py,sha256=
|
|
3
|
+
opentelemetry/instrumentation/openai/shared/chat_wrappers.py,sha256=YS1MLJEKmp_PFTl0cGBiX8dHBDrSdVZl6cN3VRvdA8E,27971
|
|
4
4
|
opentelemetry/instrumentation/openai/shared/completion_wrappers.py,sha256=CZngvHkGtLUh-Ne4uzM6VH8LiajZsKVOV1glhmSwij0,6843
|
|
5
5
|
opentelemetry/instrumentation/openai/shared/config.py,sha256=86mItW37lxSAyD8LAx4RbYWTR_-XKLeGxQgMozD5eNY,305
|
|
6
6
|
opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py,sha256=YI0lFGulaE8N2F1hdTGHj52kHwUy6KQPIt7Lw9AWJHc,7069
|
|
@@ -10,8 +10,8 @@ opentelemetry/instrumentation/openai/v0/__init__.py,sha256=02-bXv0aZbscMYO2W3jsH
|
|
|
10
10
|
opentelemetry/instrumentation/openai/v1/__init__.py,sha256=kqGsXkjyjIDNRfTSzJKjLdvvGUOViW2shZ73cM4PfS0,7693
|
|
11
11
|
opentelemetry/instrumentation/openai/v1/assistant_wrappers.py,sha256=BMiZykQ3u2xrWpo2g3qZOxTJqy317JXRGO4zCVu4bZ8,6277
|
|
12
12
|
opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py,sha256=kXOuDAt7If23EhWpH2r6L0eUVFvVWQBYrWGu3qJNKR0,2779
|
|
13
|
-
opentelemetry/instrumentation/openai/version.py,sha256=
|
|
14
|
-
opentelemetry_instrumentation_openai-0.31.
|
|
15
|
-
opentelemetry_instrumentation_openai-0.31.
|
|
16
|
-
opentelemetry_instrumentation_openai-0.31.
|
|
17
|
-
opentelemetry_instrumentation_openai-0.31.
|
|
13
|
+
opentelemetry/instrumentation/openai/version.py,sha256=KeJnUdf2sotD3eMjgcCRocii5SSlhH5-B6DNBS_0gO8,23
|
|
14
|
+
opentelemetry_instrumentation_openai-0.31.3.dist-info/METADATA,sha256=9s0Qze0lONCb6d7SYl2ssk-RcWwlRA5mvhWZFPjGwKg,2255
|
|
15
|
+
opentelemetry_instrumentation_openai-0.31.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
16
|
+
opentelemetry_instrumentation_openai-0.31.3.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
|
|
17
|
+
opentelemetry_instrumentation_openai-0.31.3.dist-info/RECORD,,
|
|
File without changes
|