fix: serialize Memory objects for telemetry span attributes#4718
Closed
weiguangli-io wants to merge 1 commit into
Closed
fix: serialize Memory objects for telemetry span attributes#4718weiguangli-io wants to merge 1 commit into
weiguangli-io wants to merge 1 commit into
Conversation
When `crew.memory` is a custom `Memory` instance (rather than a `bool`), OpenTelemetry rejects it as a span attribute value since it only accepts primitives. Convert non-bool memory values to the class name string. Fixes crewAIInc#4703
007760e to
894f5e7
Compare
Author
|
Closing due to inactivity. Happy to reopen if there's interest. |
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.
Summary
Fixes #4703
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 causes a runtime error during crew initialization:Fix: In
crew_creation()intelemetry.py, convert thecrew.memoryvalue before setting it as a span attribute -- booleans pass through unchanged, while any other type (e.g. aMemoryinstance) is converted to its class name string.The
isinstance(crew.memory, bool)check is intentional: sinceboolis a subclass ofintin Python, checkingboolfirst ensuresTrue/Falseare preserved as booleans rather than being converted to"bool"string.Test Plan
memory=True,memory=False, and a custom memory instancecrew_memoryattribute matches the expected valueNote
Low Risk
Low risk change limited to telemetry span attribute formatting; primary risk is minor downstream impact on analytics expecting the previous
crew_memoryvalue shape.Overview
Prevents OpenTelemetry span creation from failing when
crew.memoryis a custom object by serializing thecrew_memoryattribute to an OTel-accepted primitive (booleans preserved; other types recorded as their class name).Adds a regression test to ensure
Telemetry.crew_creation()always emits an OTel-serializablecrew_memoryvalue for both boolean and custom memory instances.Written by Cursor Bugbot for commit 894f5e7. This will update automatically on new commits. Configure here.