fix: serialize Memory objects for telemetry span attributes (#4703)#4704
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
fix: serialize Memory objects for telemetry span attributes (#4703)#4704devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
When crew.memory is a custom Memory instance (not a bool), OpenTelemetry cannot serialize it as a span attribute. Convert non-bool memory values to the class name string before passing to _add_attribute. Fixes #4703 Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Addressed Cursor Bugbot feedback: replaced the |
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.
fix: serialize Memory objects for telemetry span attributes (#4703)
Summary
When
crew.memoryis a customMemoryinstance (rather than abool), OpenTelemetry rejects it as a span attribute value since it only accepts primitives (bool,str,bytes,int,float). This caused a runtime error during crew initialization:Fix: In
crew_creation()intelemetry.py, thecrew.memoryvalue is now converted before being set as a span attribute — booleans pass through unchanged, while any other type (e.g. aMemoryinstance) is converted to its class name string.Fixes #4703
Review & Testing Checklist for Human
isinstance(crew.memory, bool)guard is correct — note thatboolis a subclass ofintin Python, so this must checkboolspecifically (not a broader primitive check) to avoidTrue/Falsebeing converted to"bool"stringtelemetry.pythat passcrew.memorydirectly to_add_attribute(I found only the one at the former line 282)pytest lib/crewai/tests/telemetry/test_telemetry.py -k TestCrewCreationTelemetryMemorySerialization -vvNotes
Note
Low Risk
Low risk: small telemetry-only change that converts a single span attribute to an OTEL-serializable value, covered by new regression tests.
Overview
Fixes
Telemetry.crew_creation()to ensure thecrew_memoryspan attribute is always OpenTelemetry-serializable: boolean values are preserved, and non-bool memory objects are recorded as their class name string.Adds a focused regression test suite covering
memory=True,memory=False, and custom memory instances, including an assertion that the capturedcrew_memoryvalue is always a primitive OTEL accepts.Written by Cursor Bugbot for commit b66a768. This will update automatically on new commits. Configure here.