Skip to content

Commit

Permalink
[java]: Improved span name for TracedCommandExecutor (#14902)
Browse files Browse the repository at this point in the history
Co-authored-by: Puja Jagani <[email protected]>
  • Loading branch information
navin772 and pujagani authored Dec 19, 2024
1 parent cd138fc commit 825b040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 825b040

Please sign in to comment.