Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add docstrings to telemetry class #2377

Merged
merged 2 commits into from
Mar 21, 2025
Merged

Conversation

JulioPeixoto
Copy link
Contributor

Description

This PR adds detailed documentation for all methods in the Telemetry class, improving code understanding and facilitating future contributions.

Changes

  • Add complete docstrings following Google Style pattern
  • Document parameters and types for all methods
  • Include usage notes for specific functionalities
  • Improve clarity of existing documentation

Why is this change necessary?

  • Makes telemetry system easier to understand for new contributors
  • Improves auto-generated documentation
  • Helps with code maintenance

Checklist

  • Documentation added/updated
  • Follows project style guidelines
  • No code behavior changes
  • Docstrings are clear and informative

Additional Notes

This contribution focuses exclusively on documentation, with no functional code changes. All docstrings were written based on the current method implementations.

@JulioPeixoto JulioPeixoto changed the title docs/add-docstrings-to-telemetry-class docs: Add docstrings to telemetry class Mar 15, 2025
@joaomdmoura
Copy link
Collaborator

Disclaimer: This review was made by a crew of AI Agents.

Code Review Comment

Overview

The recent pull request aims to enhance the documentation within the Telemetry class, focusing on consistent and informative docstrings for methods that aid in understanding how telemetry data is collected and used effectively.

Positive Aspects

  1. Consistent Docstring Format: The documentation adheres to the Google style guide, which enhances readability and maintainability.
  2. Clear Parameter Descriptions: Each method clearly describes its parameters, aiding developers in understanding the necessary inputs for proper usage.
  3. Contextual Information Included: Important details have been added to "Note" sections, providing clarity on special considerations when using certain methods.
  4. Comprehensive Coverage: The enhancements cover all method parameters, which is essential for future developers interacting with this code.

Suggested Improvements

1. Return Type Documentation

To improve clarity and usability, all methods should include return type annotations. For example:

def task_ended(self, span: Span, task: Task, crew: Crew) -> None:
    """Records the completion of a task execution in a crew.

    Args:
        span (Span): The OpenTelemetry span tracking the task execution
        task (Task): The task that was completed
        crew (Crew): The crew context in which the task was executed

    Returns:
        None

    Note:
        If share_crew is enabled, this will also record the task output
    """

2. Exception Documentation

Each method should specify possible exceptions that might arise during execution. For instance:

def tool_usage(self, llm: Any, tool_name: str, attempts: int) -> None:
    """Records the usage of a tool by an agent.

    Args:
        llm (Any): The language model being used
        tool_name (str): Name of the tool being used
        attempts (int): Number of attempts made with this tool

    Returns:
        None

    Raises:
        TelemetryError: If telemetry operation fails
    """

3. Type Hints Improvement

Utilizing more specific type hints instead of Any can aid in understanding and IDE support:

def tool_usage_error(self, llm: BaseLanguageModel) -> None:
    """Records when a tool usage results in an error.
    
    Args:
        llm (BaseLanguageModel): The language model being used when the error occurred
        
    Returns:
        None
    """

4. Method Examples

For complex methods, adding usage examples in their docstrings could significantly enhance developer understanding. Consider:

def test_execution_span(self, crew: Crew, iterations: int, inputs: dict[str, Any] | None, model_name: str) -> None:
    """Records the execution of a test suite for a crew.

    Args:
        crew (Crew): The crew being tested
        iterations (int): Number of test iterations
        inputs (dict[str, Any] | None): Input parameters for the test
        model_name (str): Name of the model used in testing

    Returns:
        None

    Example:
        >>> telemetry = Telemetry()
        >>> telemetry.test_execution_span(
        ...     crew=my_crew,
        ...     iterations=5,
        ...     inputs={"test_data": "sample"},
        ...     model_name="gpt-4"
        ... )
    """

5. Validation Information

Documenting input validation requirements can help prevent misuse of methods:

def flow_plotting_span(self, flow_name: str, node_names: list[str]) -> None:
    """Records flow visualization/plotting activity.

    Args:
        flow_name (str): Name of the flow being plotted
        node_names (list[str]): List of node names in the flow

    Returns:
        None

    Note:
        - flow_name must be non-empty
        - node_names must contain at least one node name
    """

General Recommendations

  1. Consistency Enforcement: Utilizing tools like pydocstyle can help enforce documentation standards consistently across the codebase.
  2. Comprehensive Type Annotations: Improved type hints throughout the code will greatly enhance maintainability and developer experience.
  3. Class-Level Documentation: Group methods by functionality within the class docstring to enhance organization and usability.

Conclusion

Overall, this pull request significantly enhances the documentation quality of the Telemetry class, fostering better maintainability and developer engagement. Implementing the suggested improvements will further enhance the code quality and ease of understanding for current and future contributors. Thank you for your hard work on this!

Copy link
Collaborator

@bhancockio bhancockio left a comment

Choose a reason for hiding this comment

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

Thank you!!

@bhancockio bhancockio merged commit 6b1cf78 into crewAIInc:main Mar 21, 2025
4 checks passed
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.

3 participants