Skip to content

[java]: better span name for TracedCommandExecutor #14902

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

Merged

Conversation

navin772
Copy link
Member

@navin772 navin772 commented Dec 16, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Fixes #13905
Use command.getName() to have better span names instead of the generic command

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Enhanced tracing functionality in TracedCommandExecutor by using specific command names for spans instead of generic "command"
  • Added test coverage to verify the new span naming behavior
  • Improves observability by making trace spans more descriptive and command-specific

Changes walkthrough 📝

Relevant files
Enhancement
TracedCommandExecutor.java
Improve tracing span name with specific command name         

java/src/org/openqa/selenium/remote/TracedCommandExecutor.java

  • Changed span name in execute() method from generic "command" to
    specific command name using command.getName()
  • +1/-1     
    Tests
    TracedCommandExecutorTest.java
    Add tests for command-specific span naming                             

    java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java

  • Updated mock setup to handle any string for span name instead of fixed
    "command"
  • Added new test case canCreateSpanWithCommandNameAsSpanName() to verify
    span naming
  • +16/-1   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Check
    The command.getName() call should be validated for null before using it as span name to avoid potential NullPointerException

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add defensive null check to prevent runtime exceptions from null command names

    Add null check for command.getName() to avoid potential NullPointerException if
    command name is null. Use a default span name as fallback.

    java/src/org/openqa/selenium/remote/TracedCommandExecutor.java [40]

    -try (Span commandSpan = tracer.getCurrentContext().createSpan(command.getName())) {
    +String spanName = command.getName() != null ? command.getName() : "command";
    +try (Span commandSpan = tracer.getCurrentContext().createSpan(spanName)) {
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential runtime error by adding a null check for command.getName(), which could prevent NullPointerException in production. This is a critical defensive programming practice that improves code robustness.

    8

    @navin772
    Copy link
    Member Author

    Hi @pujagani, can you please take a look at this, the minor change should resolve the issue.

    Copy link
    Contributor

    @pujagani pujagani 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! @navin772

    @pujagani pujagani merged commit 825b040 into SeleniumHQ:trunk Dec 19, 2024
    32 of 34 checks passed
    @navin772 navin772 deleted the java-TracedCommandExecutor-span_name branch December 19, 2024 09:07
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Dec 27, 2024
    )
    
    Co-authored-by: Puja Jagani <puja.jagani93@gmail.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [🚀 Feature]: TracedCommandExecutor better span name
    2 participants