Skip to content

Commit 825b040

Browse files
navin772pujagani
andauthored
[java]: Improved span name for TracedCommandExecutor (#14902)
Co-authored-by: Puja Jagani <[email protected]>
1 parent cd138fc commit 825b040

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public TracedCommandExecutor(CommandExecutor delegate, Tracer tracer) {
3737

3838
@Override
3939
public Response execute(Command command) throws IOException {
40-
try (Span commandSpan = tracer.getCurrentContext().createSpan("command")) {
40+
try (Span commandSpan = tracer.getCurrentContext().createSpan(command.getName())) {
4141
SessionId sessionId = command.getSessionId();
4242
if (sessionId != null) {
4343
commandSpan.setAttribute("sessionId", sessionId.toString());

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.remote;
1919

20+
import static org.mockito.ArgumentMatchers.anyString;
2021
import static org.mockito.Mockito.times;
2122
import static org.mockito.Mockito.verify;
2223
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -48,7 +49,7 @@ class TracedCommandExecutorTest {
4849
public void createMocksAndTracedCommandExecutor() {
4950
MockitoAnnotations.initMocks(this);
5051
when(tracer.getCurrentContext()).thenReturn(traceContext);
51-
when(traceContext.createSpan("command")).thenReturn(span);
52+
when(traceContext.createSpan(anyString())).thenReturn(span);
5253
tracedCommandExecutor = new TracedCommandExecutor(commandExecutor, tracer);
5354
}
5455

@@ -109,4 +110,18 @@ void canCreateSpanWithCommandName() throws IOException {
109110
verify(span, times(1)).close();
110111
verifyNoMoreInteractions(span);
111112
}
113+
114+
@Test
115+
void canCreateSpanWithCommandNameAsSpanName() throws IOException {
116+
SessionId sessionId = new SessionId(UUID.randomUUID());
117+
Command command = new Command(sessionId, "findElement");
118+
119+
tracedCommandExecutor.execute(command);
120+
121+
verify(traceContext).createSpan("findElement");
122+
verify(span).setAttribute("sessionId", sessionId.toString());
123+
verify(span).setAttribute("command", "findElement");
124+
verify(span).close();
125+
verifyNoMoreInteractions(span);
126+
}
112127
}

0 commit comments

Comments
 (0)