-
Notifications
You must be signed in to change notification settings - Fork 172
Open
Labels
Description
Describe the bug
The LangChain tracer fails to serialize span attributes when dictionary keys are non-string types (such as enum values). The safe_json_dumps fallback only handles non-serializable values via default=str, but does not handle non-string dictionary keys, which causes json.dumps() to fail.
To Reproduce
- Use Azure AI Document Intelligence to process a document with PII detection enabled
- Pass the resulting document through a LangChain chain with openinference-instrumentation-langchain enabled
- The tracer fails when attempting to serialize metadata containing PISubType enum keys
Expected behavior
The tracer should successfully serialize objects with non-string dictionary keys by converting them to strings, rather than raising a TypeError.
Screenshots
2025-12-08 14:48:07.927 | ERROR | Failed to get attribute.
Traceback (most recent call last):
File ".../openinference/instrumentation/langchain/_tracer.py", line 481, in _json_dumps
return json.dumps(obj, cls=_OpenInferenceJSONEncoder, ensure_ascii=False)
...
TypeError: keys must be str, int, float, bool or None, not PISubType
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../openinference/instrumentation/langchain/_tracer.py", line 327, in wrapper
yield from wrapped(*args, **kwargs)
File ".../openinference/instrumentation/langchain/_tracer.py", line 421, in _convert_io
json_value = _json_dumps(obj)
File ".../openinference/instrumentation/langchain/_tracer.py", line 484, in _json_dumps
return safe_json_dumps(obj)
File ".../openinference/instrumentation/helpers.py", line 21, in safe_json_dumps
return json.dumps(obj, default=str, ensure_ascii=False, **kwargs)
...
TypeError: keys must be str, int, float, bool or None, not PISubType
Desktop (please complete the following information):
- OS: Linux
- Python: 3.11
Additional context
Add any other context about the problem here.
dosubot
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo