Skip to content

fix: serialize Memory objects for telemetry span attributes#4718

Closed
weiguangli-io wants to merge 1 commit into
crewAIInc:mainfrom
weiguangli-io:codex/crewai-4703-telemetry-memory-serialization
Closed

fix: serialize Memory objects for telemetry span attributes#4718
weiguangli-io wants to merge 1 commit into
crewAIInc:mainfrom
weiguangli-io:codex/crewai-4703-telemetry-memory-serialization

Conversation

@weiguangli-io
Copy link
Copy Markdown

@weiguangli-io weiguangli-io commented Mar 5, 2026

Summary

Fixes #4703

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 (bool, str, bytes, int, float). This causes a runtime error during crew initialization:

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

Fix: In crew_creation() in telemetry.py, convert the crew.memory value before setting it as a span attribute -- booleans pass through unchanged, while any other type (e.g. a Memory instance) is converted to its class name string.

The isinstance(crew.memory, bool) check is intentional: since bool is a subclass of int in Python, checking bool first ensures True/False are preserved as booleans rather than being converted to "bool" string.

Test Plan

  • Added parametrized test covering memory=True, memory=False, and a custom memory instance
  • Each case asserts the captured crew_memory attribute matches the expected value
  • Each case verifies the value is an OTel-serializable type

Note

Low Risk
Low risk change limited to telemetry span attribute formatting; primary risk is minor downstream impact on analytics expecting the previous crew_memory value shape.

Overview
Prevents OpenTelemetry span creation from failing when crew.memory is a custom object by serializing the crew_memory attribute 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-serializable crew_memory value for both boolean and custom memory instances.

Written by Cursor Bugbot for commit 894f5e7. This will update automatically on new commits. Configure here.

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
@weiguangli-io weiguangli-io force-pushed the codex/crewai-4703-telemetry-memory-serialization branch from 007760e to 894f5e7 Compare March 6, 2026 09:47
@weiguangli-io
Copy link
Copy Markdown
Author

Closing due to inactivity. Happy to reopen if there's interest.

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.

[BUG]Telemetry Fails When Using Custom Memory Storage Backends

1 participant