Skip to content

fix: serialize Memory objects for telemetry span attributes (#4703)#4704

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1772642874-fix-telemetry-custom-memory
Open

fix: serialize Memory objects for telemetry span attributes (#4703)#4704
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1772642874-fix-telemetry-custom-memory

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 4, 2026

fix: serialize Memory objects for telemetry span attributes (#4703)

Summary

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 caused 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, the crew.memory value is now converted before being set as a span attribute — booleans pass through unchanged, while any other type (e.g. a Memory instance) is converted to its class name string.

Fixes #4703

Review & Testing Checklist for Human

  • Verify the isinstance(crew.memory, bool) guard is correct — note that bool is a subclass of int in Python, so this must check bool specifically (not a broader primitive check) to avoid True/False being converted to "bool" string
  • Confirm there are no other places in telemetry.py that pass crew.memory directly to _add_attribute (I found only the one at the former line 282)
  • Run the 4 new tests locally: pytest lib/crewai/tests/telemetry/test_telemetry.py -k TestCrewCreationTelemetryMemorySerialization -vv

Notes


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 the crew_memory span 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 captured crew_memory value is always a primitive OTEL accepts.

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

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>
@devin-ai-integration
Copy link
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@devin-ai-integration
Copy link
Contributor Author

Addressed Cursor Bugbot feedback: replaced the MagicMock.__class__.__name__ mutation with a lightweight _FakeMemory stub to avoid global class-name pollution. CI is green.

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

0 participants