Skip to content

fix: convert crew.memory to string in telemetry span attribute#4971

Open
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
guoyangzhen:fix/telemetry-memory-attribute-type
Open

fix: convert crew.memory to string in telemetry span attribute#4971
guoyangzhen wants to merge 1 commit intocrewAIInc:mainfrom
guoyangzhen:fix/telemetry-memory-attribute-type

Conversation

@guoyangzhen
Copy link

Problem

When using a custom Memory instance with an explicitly configured storage backend (e.g. LanceDB), the crew fails to initialize with:

Invalid type Memory for attribute 'crew_memory' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

This happens because crew.memory can be:

  • True (default Memory)
  • False (no memory)
  • A Memory instance (custom storage)

OpenTelemetry span attributes only accept primitive types. Passing a Memory object directly causes the error.

Root Cause

In lib/crewai/src/crewai/telemetry/telemetry.py line 282:

self._add_attribute(span, "crew_memory", crew.memory)

When crew.memory is a Memory instance, this fails the OpenTelemetry type check.

Fix

Convert to string:

self._add_attribute(span, "crew_memory", str(crew.memory))

This works for all three cases:

  • True"True"
  • False"False"
  • Memory(...)"Memory(storage=..., ...)" (or whatever __str__ returns)

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant