From 825b0406e0842992e4dd37c06b2dc9bafa27a37c Mon Sep 17 00:00:00 2001 From: Navin Chandra <98466550+navin772@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:31:01 +0530 Subject: [PATCH] [java]: Improved span name for `TracedCommandExecutor` (#14902) Co-authored-by: Puja Jagani --- .../selenium/remote/TracedCommandExecutor.java | 2 +- .../remote/TracedCommandExecutorTest.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/java/src/org/openqa/selenium/remote/TracedCommandExecutor.java b/java/src/org/openqa/selenium/remote/TracedCommandExecutor.java index a8d0b220ea678..a33d52d79e758 100644 --- a/java/src/org/openqa/selenium/remote/TracedCommandExecutor.java +++ b/java/src/org/openqa/selenium/remote/TracedCommandExecutor.java @@ -37,7 +37,7 @@ public TracedCommandExecutor(CommandExecutor delegate, Tracer tracer) { @Override public Response execute(Command command) throws IOException { - try (Span commandSpan = tracer.getCurrentContext().createSpan("command")) { + try (Span commandSpan = tracer.getCurrentContext().createSpan(command.getName())) { SessionId sessionId = command.getSessionId(); if (sessionId != null) { commandSpan.setAttribute("sessionId", sessionId.toString()); diff --git a/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java b/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java index e747b712092fc..6a7aa226826f4 100644 --- a/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java +++ b/java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java @@ -17,6 +17,7 @@ package org.openqa.selenium.remote; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -48,7 +49,7 @@ class TracedCommandExecutorTest { public void createMocksAndTracedCommandExecutor() { MockitoAnnotations.initMocks(this); when(tracer.getCurrentContext()).thenReturn(traceContext); - when(traceContext.createSpan("command")).thenReturn(span); + when(traceContext.createSpan(anyString())).thenReturn(span); tracedCommandExecutor = new TracedCommandExecutor(commandExecutor, tracer); } @@ -109,4 +110,18 @@ void canCreateSpanWithCommandName() throws IOException { verify(span, times(1)).close(); verifyNoMoreInteractions(span); } + + @Test + void canCreateSpanWithCommandNameAsSpanName() throws IOException { + SessionId sessionId = new SessionId(UUID.randomUUID()); + Command command = new Command(sessionId, "findElement"); + + tracedCommandExecutor.execute(command); + + verify(traceContext).createSpan("findElement"); + verify(span).setAttribute("sessionId", sessionId.toString()); + verify(span).setAttribute("command", "findElement"); + verify(span).close(); + verifyNoMoreInteractions(span); + } }