Repository navigation
fix(langchain): support for date/time in langchain serializations - #2792
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
👍 Looks good to me! Reviewed everything up to 9ff8d4f in 1 minute and 22 seconds
More details
- Looked at
220lines of code in4files - Skipped
0files when reviewing. - Skipped posting
10drafted comments based on config settings.
1. packages/opentelemetry-instrumentation-langchain/.python-version:1
- Draft comment:
Ensure the Python version bump to 3.11 is intentional and all dependencies are compatible. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%
This comment is asking the PR author to ensure compatibility of dependencies with the new Python version, which is against the rules. It also asks to confirm the intention of the version bump, which is not allowed.
2. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/utils.py:28
- Draft comment:
The explicit datetime check returning isoformat is good. Consider if it's preferable to call super().default(o) rather than converting to string by default to preserve standard JSONEncoder behavior. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
The change from super().default(o) to str(o) was intentional and adds more robustness by handling objects that can be string-converted but not JSON-serialized. The new code also adds proper error handling and logging when serialization fails. The original behavior of raising TypeError for non-serializable objects may be too strict for this use case. The custom encoder seems focused on being permissive and handling edge cases gracefully.
The comment raises a valid point about standard JSON encoder behavior, and there might be cases where preserving that behavior is important for consistency.
The new implementation appears to be an intentional design choice to be more permissive and handle errors gracefully, which is often desirable in instrumentation code that shouldn't break the main application.
The comment should be deleted as the current implementation is an intentional improvement in error handling and flexibility, not a mistake.
3. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/utils.py:31
- Draft comment:
Using a fallback of converting non-datetime objects to a string might mask serialization issues. Consider whether this is the intended behavior or if falling back to super().default(o) would be more appropriate. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
The comment raises a valid point about masking serialization issues. However, the current implementation seems intentionally designed to be lenient - it tries to convert to string, logs failures, and returns empty string rather than erroring. This appears to be a deliberate choice for robustness. The previous behavior of using super().default(o) would raise TypeError for unsupported types.
I could be wrong about the intention - maybe strict serialization with errors is actually better here. The current approach could hide bugs.
The code is in an instrumentation library where failing gracefully is typically preferred over throwing errors. The debug logging ensures issues aren't completely hidden.
The comment should be deleted. The current lenient approach appears intentional and appropriate for an instrumentation library, with proper error logging in place.
4. packages/opentelemetry-instrumentation-langchain/tests/test_lcel.py:257
- Draft comment:
The new test 'test_lcel_with_datetime' correctly verifies that datetime metadata is serialized as an ISO formatted string. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%
None
5. packages/opentelemetry-instrumentation-langchain/.python-version:1
- Draft comment:
Updating Python from 3.9.5 to 3.11 is a breaking change for some users. Ensure documentation notes this version upgrade requirement. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%
This comment is about a dependency change, specifically a Python version upgrade. The rules specify not to comment on pure dependency changes or library versions. Therefore, this comment should be removed.
6. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/utils.py:28
- Draft comment:
Good job handling datetime serialization. Consider also supporting datetime.date (and possibly time) if those types can appear in outputs. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
The comment is about code that was just added in this PR. It's a reasonable suggestion since datetime.date objects are common and would likely need similar handling. However, we don't have evidence that date objects actually appear in the data being serialized. The comment is somewhat speculative - "if those types can appear in outputs".
We don't have concrete evidence that datetime.date objects are actually used in this codebase. The fallback str() conversion might be sufficient for date objects.
While we lack evidence of date objects being used, adding support is a simple change that follows the pattern established for datetime objects and would make the code more robust.
The comment should be deleted because it's speculative - we don't have evidence that datetime.date support is actually needed. The fallback str() conversion would handle date objects adequately if they do appear.
7. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/utils.py:31
- Draft comment:
Fallback to returning an empty string on serialization error may mask issues. Consider whether logging at a higher level or returning None might be more appropriate for debugging. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
This is a JSON encoder class, which means its output needs to be JSON-compatible. Both "" and None (which becomes null) are valid JSON values. The current approach of returning "" is actually safer since it preserves the field structure while being falsy, whereas null might cause issues with consumers expecting a string. The debug log already captures the error for debugging purposes.
I might be underestimating the debugging value of distinguishing between empty strings and serialization failures. Some consumers might handle null differently than empty string in a beneficial way.
While null might provide slightly more information, the debug log already captures the exact failure case. The empty string approach is more conservative and less likely to cause issues with JSON consumers.
The current approach of returning "" with debug logging is a reasonable design choice. The suggested change to None doesn't clearly improve the situation and could potentially cause more problems.
8. packages/opentelemetry-instrumentation-langchain/tests/test_lcel.py:297
- Draft comment:
Test for datetime serialization is clear and validates the expected ISO string format. Ensure additional date/time types (if supported later) are also covered in tests. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%<= threshold50%
The comment is asking the author to ensure future support for additional date/time types in tests. This is a speculative and non-specific request, which violates the rule against asking the author to ensure something is tested without being specific.
9. packages/opentelemetry-instrumentation-langchain/.python-version:1
- Draft comment:
There is no trailing newline at the end of this file. It is a minor stylistic issue that can help with tool compatibility. Please add a newline at the end of the file. - Reason this comment was not posted:
Comment was on unchanged code.
10. packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/utils.py:60
- Draft comment:
Typo detected: 'OpenLLMetry' should be corrected to 'OpenTelemetry' for consistency and clarity. - Reason this comment was not posted:
Comment was not on a location in the diff, so it can't be submitted as a review comment.
Workflow ID: wflow_0JSTXoDtH27CBaYA
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.
doronkopit5
reviewed
Mar 22, 2025
doronkopit5
approved these changes
Mar 22, 2025
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.
Fixes #2775
feat(instrumentation): ...orfix(instrumentation): ....Important
Adds support for
datetimeserialization in Langchain and updates Python version to 3.11.datetimeserialization inCallbackFilteredJSONEncoderinutils.pyby convertingdatetimeobjects to ISO format..python-version.test_lcel_with_datetimeintest_lcel.pyto verify serialization ofdatetimein metadata.test_lcel_with_datetime.yamlfor testing date/time serialization.This description was created by
for 9ff8d4f. It will automatically update as commits are pushed.