Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Fix]: Don't log image data to traces in Bedrock and OpenAI Instrumentors (#532)

Chris Trane1fc6791b62f
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml
index 62056aa8..96336e23 100644
--- a/sdk/python/pyproject.toml
+++ b/sdk/python/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openlit"
-version = "1.32.5"
+version = "1.32.6"
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
authors = ["OpenLIT"]
repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
diff --git a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py
index 0d710445..ae5ec582 100644
--- a/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py
+++ b/sdk/python/src/openlit/instrumentation/bedrock/bedrock.py
@@ -102,12 +102,8 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,
content = message["content"]
if isinstance(content, list):
- content_str = ", ".join(
- # pylint: disable=line-too-long
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
- if "type" in item else f'text: {item["text"]}'
- for item in content
- )
+ # pylint: disable=line-too-long
+ content_str = ", ".join(f'text: {item["text"]}' for item in content if "text" in item)
formatted_messages.append(f"{role}: {content_str}")
else:
formatted_messages.append(f"{role}: {content}")
diff --git a/sdk/python/src/openlit/instrumentation/openai/openai.py b/sdk/python/src/openlit/instrumentation/openai/openai.py
index ec1ee010..12788c04 100644
--- a/sdk/python/src/openlit/instrumentation/openai/openai.py
+++ b/sdk/python/src/openlit/instrumentation/openai/openai.py
@@ -103,12 +103,15 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,
content = message["content"]
if isinstance(content, list):
- content_str = ", ".join(
- # pylint: disable=line-too-long
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
- if "type" in item else f'text: {item["text"]}'
- for item in content
- )
+ content_str_list = []
+ for item in content:
+ if item["type"] == "text":
+ content_str_list.append(f'text: {item["text"]}')
+ elif (item["type"] == "image_url" and
+ not item["image_url"]["url"].startswith("data:")):
+ # pylint: disable=line-too-long
+ content_str_list.append(f'image_url: {item["image_url"]["url"]}')
+ content_str = ", ".join(content_str_list)
formatted_messages.append(f"{role}: {content_str}")
else:
formatted_messages.append(f"{role}: {content}")