fix: convert crew.memory to string in telemetry span attribute#4971
Open
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
Open
fix: convert crew.memory to string in telemetry span attribute#4971guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…IInc#4703) OpenTelemetry only accepts primitive types (bool, str, bytes, int, float) for span attributes. When crew.memory is a Memory instance (e.g. with custom LanceDBStorage), passing it directly causes: Invalid type Memory for attribute 'crew_memory' value. Fix: use str(crew.memory) to serialize the attribute value.
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.
Problem
When using a custom
Memoryinstance with an explicitly configured storage backend (e.g. LanceDB), the crew fails to initialize with:This happens because
crew.memorycan be:True(default Memory)False(no memory)Memoryinstance (custom storage)OpenTelemetry span attributes only accept primitive types. Passing a
Memoryobject directly causes the error.Root Cause
In
lib/crewai/src/crewai/telemetry/telemetry.pyline 282:When
crew.memoryis aMemoryinstance, this fails the OpenTelemetry type check.Fix
Convert to string:
This works for all three cases:
True→"True"False→"False"Memory(...)→"Memory(storage=..., ...)"(or whatever__str__returns)