opentelemetry-instrumentation-openai 0.30.1__tar.gz → 0.31.0__tar.gz
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-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/PKG-INFO +1 -1
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/__init__.py +2 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/chat_wrappers.py +39 -1
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/config.py +1 -0
- opentelemetry_instrumentation_openai-0.31.0/opentelemetry/instrumentation/openai/version.py +1 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/pyproject.toml +1 -1
- opentelemetry_instrumentation_openai-0.30.1/opentelemetry/instrumentation/openai/version.py +0 -1
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/README.md +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/__init__.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/completion_wrappers.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/utils.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/v0/__init__.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/v1/__init__.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/v1/assistant_wrappers.py +0 -0
- {opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/opentelemetry/instrumentation/openai/v1/event_handler_wrapper.py +0 -0
{opentelemetry_instrumentation_openai-0.30.1 → opentelemetry_instrumentation_openai-0.31.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: opentelemetry-instrumentation-openai
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.31.0
|
|
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
|
|
@@ -19,12 +19,14 @@ class OpenAIInstrumentor(BaseInstrumentor):
|
|
|
19
19
|
enrich_token_usage: bool = False,
|
|
20
20
|
exception_logger=None,
|
|
21
21
|
get_common_metrics_attributes: Callable[[], dict] = lambda: {},
|
|
22
|
+
upload_base64_image: Callable[[str, str, str, str], str] = lambda *args: "",
|
|
22
23
|
):
|
|
23
24
|
super().__init__()
|
|
24
25
|
Config.enrich_assistant = enrich_assistant
|
|
25
26
|
Config.enrich_token_usage = enrich_token_usage
|
|
26
27
|
Config.exception_logger = exception_logger
|
|
27
28
|
Config.get_common_metrics_attributes = get_common_metrics_attributes
|
|
29
|
+
Config.upload_base64_image = upload_base64_image
|
|
28
30
|
|
|
29
31
|
def instrumentation_dependencies(self) -> Collection[str]:
|
|
30
32
|
return _instruments
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import copy
|
|
1
2
|
import json
|
|
2
3
|
import logging
|
|
3
4
|
import time
|
|
@@ -326,6 +327,36 @@ def _set_token_counter_metrics(token_counter, usage, shared_attributes):
|
|
|
326
327
|
token_counter.record(val, attributes=attributes_with_token_type)
|
|
327
328
|
|
|
328
329
|
|
|
330
|
+
def _is_base64_image(item):
|
|
331
|
+
if not isinstance(item, dict):
|
|
332
|
+
return False
|
|
333
|
+
|
|
334
|
+
if not isinstance(item.get('image_url'), dict):
|
|
335
|
+
return False
|
|
336
|
+
|
|
337
|
+
if 'data:image/' not in item.get('image_url', {}).get('url', ''):
|
|
338
|
+
return False
|
|
339
|
+
|
|
340
|
+
return True
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _process_image_item(item, trace_id, span_id, message_index, content_index):
|
|
344
|
+
if not Config.upload_base64_image:
|
|
345
|
+
return item
|
|
346
|
+
|
|
347
|
+
image_format = item["image_url"]["url"].split(";")[0].split("/")[1]
|
|
348
|
+
image_name = f"message_{message_index}_content_{content_index}.{image_format}"
|
|
349
|
+
base64_string = item["image_url"]["url"].split(",")[1]
|
|
350
|
+
url = Config.upload_base64_image(trace_id, span_id, image_name, base64_string)
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
'type': 'image_url',
|
|
354
|
+
'image_url': {
|
|
355
|
+
'url': url
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
329
360
|
def _set_prompts(span, messages):
|
|
330
361
|
if not span.is_recording() or messages is None:
|
|
331
362
|
return
|
|
@@ -335,8 +366,15 @@ def _set_prompts(span, messages):
|
|
|
335
366
|
|
|
336
367
|
_set_span_attribute(span, f"{prefix}.role", msg.get("role"))
|
|
337
368
|
if msg.get("content"):
|
|
338
|
-
content = msg.get("content")
|
|
369
|
+
content = copy.deepcopy(msg.get("content"))
|
|
339
370
|
if isinstance(content, list):
|
|
371
|
+
content = [
|
|
372
|
+
_process_image_item(item, span.context.trace_id, span.context.span_id, i, j)
|
|
373
|
+
if _is_base64_image(item)
|
|
374
|
+
else item
|
|
375
|
+
for j, item in enumerate(content)
|
|
376
|
+
]
|
|
377
|
+
|
|
340
378
|
content = json.dumps(content)
|
|
341
379
|
_set_span_attribute(span, f"{prefix}.content", content)
|
|
342
380
|
if msg.get("tool_call_id"):
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.31.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.30.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|