fix(otel): detect base64 data URIs with media-type parameters#837
Open
i-anubhav-anand wants to merge 1 commit into
Open
fix(otel): detect base64 data URIs with media-type parameters#837i-anubhav-anand wants to merge 1 commit into
i-anubhav-anand wants to merge 1 commit into
Conversation
The media-extraction regex required ;base64 to immediately follow the content type (/data:[^;]+;base64,/), so a valid RFC 2397 data URI with a parameter such as data:text/plain;charset=utf-8;base64,... never matched: the media was not uploaded and the raw base64 stayed embedded in the exported attribute. (The downstream core parser already handles parameterized URIs.) Match any non-comma run up to ;base64, instead. Adds an integration test (fails before: URI left embedded, not replaced with a media tag).
|
@i-anubhav-anand is attempting to deploy a commit to the langfuse Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The media-extraction regex in
MediaServicerequires;base64to immediately follow the content type:So a valid RFC 2397 data URI with a media-type parameter never matches:
The result: the media is not extracted/uploaded, and the raw base64 stays embedded verbatim in the exported attribute (payload bloat + the upload is silently skipped). Plain
data:image/png;base64,…works only because it has no parameter.The downstream parser (
@langfuse/coreparseBase64DataUri) is already parameter-aware (header.split(";")), so the extraction regex was stricter than the parser it feeds. Fix matches any non-comma run up to;base64,:Test
Adds an integration test embedding
data:text/plain;charset=utf-8;base64,…and asserting it is replaced with a@@@langfuseMedia:…@@@tag. Fails before (URI left embedded), passes after. Existing media tests still pass;prettier/eslint/tscclean (pre-commit).Type of change
Greptile Summary
This PR fixes a regex in
MediaServicethat failed to match RFC 2397 data URIs containing media-type parameters (e.g.data:text/plain;charset=utf-8;base64,…), causing those URIs to be left embedded verbatim instead of being extracted and uploaded. The fix narrows the matching expression from[^;]+(stops at first;) to[^,]*(stops at first,, covering the full header), aligned with how the downstreamparseBase64DataUriparser already handles parameters.packages/otel/src/MediaService.ts: single-character class change in the detection regex, with an explanatory comment added.tests/integration/span-processor.integration.test.ts: new integration test that embeds a parameterised data URI and asserts it is replaced with a@@@langfuseMedia:…@@@tag.Confidence Score: 5/5
Safe to merge — the change is a single-character class adjustment in a detection regex, well-covered by a new integration test, and consistent with the downstream parser.
The regex fix is minimal and well-reasoned: greedy backtracking on
[^,]*;base64,correctly locates the last;base64,before the MIME-type/data boundary for both plain and parameterised URIs. The new integration test directly exercises the previously-broken path and confirms replacement. Existing tests continue to cover the simpleimage/png;base64case. No unrelated code is touched.No files require special attention.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Span attribute value string] --> B{Regex match on value} B -- No match --> C[Skip attribute] B -- Match found --> D[Deduplicate matches] D --> E[For each data URI] E --> F[Create LangfuseMedia object] F --> G{Get media tag} G -- Failure --> H[Log warn, skip item] G -- Success --> I[Schedule upload] I --> J[Replace URI with langfuseMedia tag] J --> K[Write updated value back to span attributes] K --> EReviews (1): Last reviewed commit: "fix(otel): detect base64 data URIs with ..." | Re-trigger Greptile