Skip to content

Commit 6b1cf78

Browse files
docs: add detailed docstrings to Telemetry class methods (#2377)
Co-authored-by: Brandon Hancock (bhancock_ai) <109994880+bhancockio@users.noreply.github.com>
1 parent 80f1a88 commit 6b1cf78

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

src/crewai/telemetry/telemetry.py

+76-4
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,16 @@ def operation():
281281
return self._safe_telemetry_operation(operation)
282282

283283
def task_ended(self, span: Span, task: Task, crew: Crew):
284-
"""Records task execution in a crew."""
284+
"""Records the completion of a task execution in a crew.
285285
286+
Args:
287+
span (Span): The OpenTelemetry span tracking the task execution
288+
task (Task): The task that was completed
289+
crew (Crew): The crew context in which the task was executed
290+
291+
Note:
292+
If share_crew is enabled, this will also record the task output
293+
"""
286294
def operation():
287295
if crew.share_crew:
288296
self._add_attribute(
@@ -297,8 +305,13 @@ def operation():
297305
self._safe_telemetry_operation(operation)
298306

299307
def tool_repeated_usage(self, llm: Any, tool_name: str, attempts: int):
300-
"""Records the repeated usage 'error' of a tool by an agent."""
308+
"""Records when a tool is used repeatedly, which might indicate an issue.
301309
310+
Args:
311+
llm (Any): The language model being used
312+
tool_name (str): Name of the tool being repeatedly used
313+
attempts (int): Number of attempts made with this tool
314+
"""
302315
def operation():
303316
tracer = trace.get_tracer("crewai.telemetry")
304317
span = tracer.start_span("Tool Repeated Usage")
@@ -317,8 +330,13 @@ def operation():
317330
self._safe_telemetry_operation(operation)
318331

319332
def tool_usage(self, llm: Any, tool_name: str, attempts: int):
320-
"""Records the usage of a tool by an agent."""
333+
"""Records the usage of a tool by an agent.
321334
335+
Args:
336+
llm (Any): The language model being used
337+
tool_name (str): Name of the tool being used
338+
attempts (int): Number of attempts made with this tool
339+
"""
322340
def operation():
323341
tracer = trace.get_tracer("crewai.telemetry")
324342
span = tracer.start_span("Tool Usage")
@@ -337,8 +355,11 @@ def operation():
337355
self._safe_telemetry_operation(operation)
338356

339357
def tool_usage_error(self, llm: Any):
340-
"""Records the usage of a tool by an agent."""
358+
"""Records when a tool usage results in an error.
341359
360+
Args:
361+
llm (Any): The language model being used when the error occurred
362+
"""
342363
def operation():
343364
tracer = trace.get_tracer("crewai.telemetry")
344365
span = tracer.start_span("Tool Usage Error")
@@ -357,6 +378,14 @@ def operation():
357378
def individual_test_result_span(
358379
self, crew: Crew, quality: float, exec_time: int, model_name: str
359380
):
381+
"""Records individual test results for a crew execution.
382+
383+
Args:
384+
crew (Crew): The crew being tested
385+
quality (float): Quality score of the execution
386+
exec_time (int): Execution time in seconds
387+
model_name (str): Name of the model used
388+
"""
360389
def operation():
361390
tracer = trace.get_tracer("crewai.telemetry")
362391
span = tracer.start_span("Crew Individual Test Result")
@@ -383,6 +412,14 @@ def test_execution_span(
383412
inputs: dict[str, Any] | None,
384413
model_name: str,
385414
):
415+
"""Records the execution of a test suite for a crew.
416+
417+
Args:
418+
crew (Crew): The crew being tested
419+
iterations (int): Number of test iterations
420+
inputs (dict[str, Any] | None): Input parameters for the test
421+
model_name (str): Name of the model used in testing
422+
"""
386423
def operation():
387424
tracer = trace.get_tracer("crewai.telemetry")
388425
span = tracer.start_span("Crew Test Execution")
@@ -408,6 +445,7 @@ def operation():
408445
self._safe_telemetry_operation(operation)
409446

410447
def deploy_signup_error_span(self):
448+
"""Records when an error occurs during the deployment signup process."""
411449
def operation():
412450
tracer = trace.get_tracer("crewai.telemetry")
413451
span = tracer.start_span("Deploy Signup Error")
@@ -417,6 +455,11 @@ def operation():
417455
self._safe_telemetry_operation(operation)
418456

419457
def start_deployment_span(self, uuid: Optional[str] = None):
458+
"""Records the start of a deployment process.
459+
460+
Args:
461+
uuid (Optional[str]): Unique identifier for the deployment
462+
"""
420463
def operation():
421464
tracer = trace.get_tracer("crewai.telemetry")
422465
span = tracer.start_span("Start Deployment")
@@ -428,6 +471,7 @@ def operation():
428471
self._safe_telemetry_operation(operation)
429472

430473
def create_crew_deployment_span(self):
474+
"""Records the creation of a new crew deployment."""
431475
def operation():
432476
tracer = trace.get_tracer("crewai.telemetry")
433477
span = tracer.start_span("Create Crew Deployment")
@@ -437,6 +481,12 @@ def operation():
437481
self._safe_telemetry_operation(operation)
438482

439483
def get_crew_logs_span(self, uuid: Optional[str], log_type: str = "deployment"):
484+
"""Records the retrieval of crew logs.
485+
486+
Args:
487+
uuid (Optional[str]): Unique identifier for the crew
488+
log_type (str, optional): Type of logs being retrieved. Defaults to "deployment".
489+
"""
440490
def operation():
441491
tracer = trace.get_tracer("crewai.telemetry")
442492
span = tracer.start_span("Get Crew Logs")
@@ -449,6 +499,11 @@ def operation():
449499
self._safe_telemetry_operation(operation)
450500

451501
def remove_crew_span(self, uuid: Optional[str] = None):
502+
"""Records the removal of a crew.
503+
504+
Args:
505+
uuid (Optional[str]): Unique identifier for the crew being removed
506+
"""
452507
def operation():
453508
tracer = trace.get_tracer("crewai.telemetry")
454509
span = tracer.start_span("Remove Crew")
@@ -574,6 +629,11 @@ def operation():
574629
self._safe_telemetry_operation(operation)
575630

576631
def flow_creation_span(self, flow_name: str):
632+
"""Records the creation of a new flow.
633+
634+
Args:
635+
flow_name (str): Name of the flow being created
636+
"""
577637
def operation():
578638
tracer = trace.get_tracer("crewai.telemetry")
579639
span = tracer.start_span("Flow Creation")
@@ -584,6 +644,12 @@ def operation():
584644
self._safe_telemetry_operation(operation)
585645

586646
def flow_plotting_span(self, flow_name: str, node_names: list[str]):
647+
"""Records flow visualization/plotting activity.
648+
649+
Args:
650+
flow_name (str): Name of the flow being plotted
651+
node_names (list[str]): List of node names in the flow
652+
"""
587653
def operation():
588654
tracer = trace.get_tracer("crewai.telemetry")
589655
span = tracer.start_span("Flow Plotting")
@@ -595,6 +661,12 @@ def operation():
595661
self._safe_telemetry_operation(operation)
596662

597663
def flow_execution_span(self, flow_name: str, node_names: list[str]):
664+
"""Records the execution of a flow.
665+
666+
Args:
667+
flow_name (str): Name of the flow being executed
668+
node_names (list[str]): List of nodes being executed in the flow
669+
"""
598670
def operation():
599671
tracer = trace.get_tracer("crewai.telemetry")
600672
span = tracer.start_span("Flow Execution")

0 commit comments

Comments
 (0)