Skip to content

bug(sdk-python): Failed OTEL media uploads with openinference #15179

Description

@MJRuskin

Describe the bug

When generating an image with Gemini, openinference will return the base64 in both the message parts and the final output.value field within the OTEL span.

Langfuse will attempt to upload both, which is fine, since the second upload would normally cancel automatically.

However, one of the images is actually urlsafe base64, which results in the invalid strings "-" and "_" to be dropped.
This causes two possible scenarios:

  • Two separate medias are uploaded, one being the correct image, the other being an empty/failed image
  • The resulting string is not %4 length, which results in an error, and the output value is replaced with an error message instead of the Langfuse media tag

While this could be considered an issue with the openinference, since that package is the recommended by Langfuse it would seem appropriate to handle this on the SDK side.

My suggestion would be to modify the following section to accept urlsafe base64:
https://github.com/langfuse/langfuse-python/blob/957d067d81ea357abf36c394bf68c7a8b184d53d/langfuse/media.py#L294

standardized_data = actual_data.replace("-", "+").replace("_", "/")
return base64.b64decode(standardized_data), cast(MediaContentType, content_type)

Steps to reproduce

  • Install langfuse v4 and openinference-instrumentation-google-genai packages
  • Generate an image using gemini

Langfuse Cloud or self-hosted?

Self-hosted

If self-hosted, what version are you running?

3.212

SDK and integration versions

langfuse v4.14.0
openinference-instrumentation-google-genai v1.2.0

Additional information

No response

Are you interested in contributing a fix for this bug?

Yes

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions