Skip to content

fix(crewai): stop the __dict__ walk leaking credentials onto spans - #4465

Open
IdoGol24 wants to merge 2 commits into
traceloop:mainfrom
IdoGol24:fix/crewai-span-attribute-allowlist
Open

fix(crewai): stop the __dict__ walk leaking credentials onto spans#4465
IdoGol24 wants to merge 2 commits into
traceloop:mainfrom
IdoGol24:fix/crewai-span-attribute-allowlist

Conversation

@IdoGol24

@IdoGol24 IdoGol24 commented Sep 7, 2026

Copy link
Copy Markdown

CrewAISpanAttributes stringified every attribute of the Crew, Agent and Task objects it was handed, so anything those objects held -- an LLM client, an embedder config -- reached the span through its repr, api keys included.

Read a fixed set of fields instead. Agents already had a hand-written allowlist in _extract_agent_data; the standalone-agent path just wasn't using it. Tasks reuse the dict _parse_tasks already built. Only Crew needed a new list. Tools go through the existing _serialize_tools on every path rather than being repr'd, and the dead _populate_llm_attributes is gone.

  • I have added tests that cover my changes.

  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.

  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....

  • (If applicable) I have updated the documentation accordingly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved telemetry safety by preventing credentials and other sensitive configuration values from appearing in span attributes.
    • Standardized captured task and agent details, including task identifiers and serialized tool information.
    • Continued emitting supported Crew, task, and agent identifiers while excluding unsupported configuration data.
    • Improved consistency of telemetry attributes across CrewAI components.

CrewAISpanAttributes stringified every attribute of the Crew, Agent and Task
objects it was handed, so anything those objects held -- an LLM client, an
embedder config -- reached the span through its repr, api keys included.

Read a fixed set of fields instead. Agents already had a hand-written
allowlist in _extract_agent_data; the standalone-agent path just wasn't using
it. Tasks reuse the dict _parse_tasks already built. Only Crew needed a new
list. Tools go through the existing _serialize_tools on every path rather than
being repr'd, and the dead _populate_llm_attributes is gone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012SsveLwpjmyX6GEydCuX6H
@CLAassistant

CLAassistant commented Sep 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 4c04cd01-fc6b-41ca-bfd1-12caa740d75b

📥 Commits

Reviewing files that changed from the base of the PR and between 9ce6b03 and 75d80e3.

📒 Files selected for processing (2)
  • packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/crewai_span_attributes.py
  • packages/opentelemetry-instrumentation-crewai/tests/test_span_attribute_allowlist.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/crewai_span_attributes.py
  • packages/opentelemetry-instrumentation-crewai/tests/test_span_attribute_allowlist.py

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

CrewAI span extraction now uses an explicit safe-field allowlist and shared serialization for agents, tasks, and tools. New tests verify that sentinel credentials do not enter span attributes while identifiers remain available.

Changes

CrewAI attribute safety

Layer / File(s) Summary
Allowlisted CrewAI extraction
packages/opentelemetry-instrumentation-crewai/opentelemetry/instrumentation/crewai/crewai_span_attributes.py
Crew extraction uses CREW_FIELDS. Agent and task extraction reuse stringification helpers. Tool data is serialized, and agent configuration is excluded.
Credential leakage validation
packages/opentelemetry-instrumentation-crewai/tests/test_span_attribute_allowlist.py
Tests construct agents, tasks, and crews with sentinel credentials. They verify that span attributes exclude the sentinel while retaining allowlisted identifiers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 75d80

CrewAI span extraction now limits serialized fields to safe allowlists to prevent credential leakage while retaining supported identifiers. No concrete merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant CrewInstance
  participant CrewAISpanAttributes
  participant InMemorySpanExporter
  CrewInstance->>CrewAISpanAttributes: provide crew, agent, and task data
  CrewAISpanAttributes->>CrewAISpanAttributes: select allowlisted fields and serialize tools
  CrewAISpanAttributes->>InMemorySpanExporter: emit filtered span attributes
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 76.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing credential leakage caused by walking CrewAI object dict values into spans.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Satisfies the docstring coverage check on the PR.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012SsveLwpjmyX6GEydCuX6H
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.

2 participants