Fix: Respect CREWAI_DISABLE_TELEMETRY for tracing requests #3909
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.
Fix: Respect CREWAI_DISABLE_TELEMETRY for tracing requests
Summary
Fixes issue #3907 where HTTP requests to
/crewai_plus/api/v1/tracing/ephemeral/batcheswere still being made despiteCREWAI_DISABLE_TELEMETRY=truebeing set in the environment.The root cause was that the tracing system (TraceBatchManager and TraceCollectionListener) was separate from the telemetry system and didn't check the
CREWAI_DISABLE_TELEMETRYenvironment variable. This PR implements a defense-in-depth approach:is_tracking_disabled()helper inutils.pythat checks bothCREWAI_DISABLE_TELEMETRYandCREWAI_DISABLE_TRACKINGenvironment variables_initialize_backend_batch()- returns early_send_events_to_backend()- returns 200 to avoid error pathsfinalize_batch()- returns None early_finalize_backend_batch()- returns early__init__()- returns early to skip initialization overheadsetup_listeners()- returns early to avoid registering event handlersReview & Testing Checklist for Human
CREWAI_DISABLE_TELEMETRY=truein a real crew execution and confirm via network monitoring (tcpdump, Wireshark, or proxy logs) that NO requests are made to/crewai_plus/api/v1/tracing/ephemeral/batches_send_events_to_backend()when disabled doesn't cause unexpected behavior in calling code (it's meant to avoid error paths that would callmark_trace_batch_as_failed())CREWAI_DISABLE_TELEMETRY=trueandCREWAI_DISABLE_TRACKING=truework as expectedTest Plan
CREWAI_DISABLE_TELEMETRY=truein environmentCREWAI_DISABLE_TRACKING=trueto verify it also worksNotes