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

@@ -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"):
@@ -6,3 +6,4 @@ class Config:
6
6
  enrich_assistant = False
7
7
  exception_logger = None
8
8
  get_common_metrics_attributes: Callable[[], dict] = lambda: {}
9
+ upload_base64_image: Callable[[str, str, str], str] = lambda trace_id, span_id, base64_image_url: str
@@ -1 +1 @@
1
- __version__ = "0.30.1"
1
+ __version__ = "0.31.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentelemetry-instrumentation-openai
3
- Version: 0.30.1
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
@@ -1,8 +1,8 @@
1
- opentelemetry/instrumentation/openai/__init__.py,sha256=w0gjgORccQ3EsMiK2dzZg6V7J3pa6PcAuDvy1oofQ5A,1503
1
+ opentelemetry/instrumentation/openai/__init__.py,sha256=Y_YgW1pgE7HKFz3LXAA4v-87IwW0aqcuXez1sV10RcY,1645
2
2
  opentelemetry/instrumentation/openai/shared/__init__.py,sha256=HcS1Ar6WX9DPtlJuiPji3u7XV_SwYerTf5O32Kfe1FQ,8839
3
- opentelemetry/instrumentation/openai/shared/chat_wrappers.py,sha256=9Db3PzB9ZsxqrcalLnGNtgd1GBxYMwWvIZmjixjGGmY,26721
3
+ opentelemetry/instrumentation/openai/shared/chat_wrappers.py,sha256=q6uLpnqrgoXcuEf-W5D20TxfqWfcctrJEE9q4aD74CM,27835
4
4
  opentelemetry/instrumentation/openai/shared/completion_wrappers.py,sha256=CZngvHkGtLUh-Ne4uzM6VH8LiajZsKVOV1glhmSwij0,6843
5
- opentelemetry/instrumentation/openai/shared/config.py,sha256=_4AkHau8C44uBc6-fNBl9EzCGPBuj9yDIngTuwSW6ZE,199
5
+ opentelemetry/instrumentation/openai/shared/config.py,sha256=86mItW37lxSAyD8LAx4RbYWTR_-XKLeGxQgMozD5eNY,305
6
6
  opentelemetry/instrumentation/openai/shared/embeddings_wrappers.py,sha256=YI0lFGulaE8N2F1hdTGHj52kHwUy6KQPIt7Lw9AWJHc,7069
7
7
  opentelemetry/instrumentation/openai/shared/image_gen_wrappers.py,sha256=A4qdJIeJdA45SfiLaFj3Vo0Ndcqqfuew1BDsGdnJU3E,2122
8
8
  opentelemetry/instrumentation/openai/utils.py,sha256=3ONjsia3xG4rRMOwjU91liOVpZxoRE39CxJ-C5HxIgQ,3464
@@ -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=3lF2HrdOSEjFYtffVUtfz7zCxpNVnfN4hDz0kCGq7CA,23
14
- opentelemetry_instrumentation_openai-0.30.1.dist-info/METADATA,sha256=DmAd7aF6VVoa6fUxUbNje73VJVwekQC5thU2lPxi1cw,2255
15
- opentelemetry_instrumentation_openai-0.30.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
- opentelemetry_instrumentation_openai-0.30.1.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
17
- opentelemetry_instrumentation_openai-0.30.1.dist-info/RECORD,,
13
+ opentelemetry/instrumentation/openai/version.py,sha256=TJt1pYzTJuPE6GzDP1gxaeeVQlzcoUyEmSVSUPgYnIA,23
14
+ opentelemetry_instrumentation_openai-0.31.0.dist-info/METADATA,sha256=yQi_9c02-R73k5dPjNBgyQV7803HR5LKSE5tyylwb8M,2255
15
+ opentelemetry_instrumentation_openai-0.31.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
+ opentelemetry_instrumentation_openai-0.31.0.dist-info/entry_points.txt,sha256=vTBfiX5yXji5YHikuJHEOoBZ1TFdPQ1EI4ctd2pZSeE,93
17
+ opentelemetry_instrumentation_openai-0.31.0.dist-info/RECORD,,