-
Notifications
You must be signed in to change notification settings - Fork 165
Description
-
Summary
LangChain’s OpenInference auto-instrumentor only tagsinput/output.mime_typeasapplication/jsonwhen the payload is a Python dict/list. When the producer hands stringified JSON, the tracer leaves the MIME astext/plain, so the frontend can’t render pretty JSON. -
Environment
openinference-instrumentation-langchain0.1.35–0.1.54 (current release)- LangChain auto-instrumentation only; no custom span processor.
-
Steps to Reproduce
- Run a LangChain chain whose input/output values are JSON strings (e.g.,
{"input": "{\"name\": \"Ada\"}"}) rather than dicts. - Observe the emitted span attributes:
input.valuecontains the JSON string, butinput.mime_type(andoutput.mime_type) remaintext/plain. - Frontend receives
text/plainand renders raw text instead of the JSON renderer.
- Run a LangChain chain whose input/output values are JSON strings (e.g.,
-
Expected Behavior
Any payload that can be parsed as JSON (or whose MIME already contains a JSON subtype) should reach the span withinput/output.mime_type = "application/json"so the UI knows to prettify it. -
Actual Behavior
_convert_ioreturns early for string values, soinput/output.mime_typeis never updated._normalize_mime_typerejects values liketext/plain; charset=utf-8, so there’s no later chance to fix it. UI renders as plain text. -
Proposed Fix Not sure if Correct or not so please check
Extend_convert_io(or a dedicated helper) to re-parse string values:- When the sole input/output value is a
str, attemptjson.loads. If parsing succeeds and yields a dict/list, emit the serialized JSON string plusOpenInferenceMimeTypeValues.JSON.value. - Optionally normalize incoming MIME strings (lowercase, strip
; charset=..., treat any subtype containing"json"as JSON) before storing them. - Add unit tests covering stringified JSON and MIME variants (e.g.,
application/json; charset=utf-8).
- When the sole input/output value is a
Metadata
Metadata
Assignees
Labels
Type
Projects
Status