mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
Add crew context tracking using OpenTelemetry baggage for thread-safe propagation. Context is set during kickoff and cleaned up in finally block. Added thread safety tests with mocked agent execution.
17 lines
506 B
Python
17 lines
506 B
Python
"""Context management utilities for tracking crew and task execution context using OpenTelemetry baggage."""
|
|
|
|
from typing import Optional
|
|
|
|
from opentelemetry import baggage
|
|
|
|
from crewai.utilities.crew.models import CrewContext
|
|
|
|
|
|
def get_crew_context() -> Optional[CrewContext]:
|
|
"""Get the current crew context from OpenTelemetry baggage.
|
|
|
|
Returns:
|
|
CrewContext instance containing crew context information, or None if no context is set
|
|
"""
|
|
return baggage.get_baggage("crew_context")
|