Skip to content

Commit

Permalink
[java] Allow disabling tracing in RemoteWebDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Jan 24, 2022
1 parent ea3b91c commit 3d21349
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions java/src/org/openqa/selenium/remote/RemoteWebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,21 @@ protected RemoteWebDriver() {

public RemoteWebDriver(Capabilities capabilities) {
this(getDefaultServerURL(),
Require.nonNull("Capabilities", capabilities));
Require.nonNull("Capabilities", capabilities), true);
}

public RemoteWebDriver(Capabilities capabilities, boolean enableTracing) {
this(getDefaultServerURL(),
Require.nonNull("Capabilities", capabilities), enableTracing);
}

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) {
this(createTracedExecutorWithTracedHttpClient(Require.nonNull("Server URL", remoteAddress)),
this(createExecutor(Require.nonNull("Server URL", remoteAddress), true),
Require.nonNull("Capabilities", capabilities));
}

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities, boolean enableTracing) {
this(createExecutor(Require.nonNull("Server URL", remoteAddress), enableTracing),
Require.nonNull("Capabilities", capabilities));
}

Expand Down Expand Up @@ -168,13 +178,18 @@ private static URL getDefaultServerURL() {
}
}

private static CommandExecutor createTracedExecutorWithTracedHttpClient(URL remoteAddress) {
Tracer tracer = OpenTelemetryTracer.getInstance();
CommandExecutor executor = new HttpCommandExecutor(
Collections.emptyMap(),
ClientConfig.defaultConfig().baseUrl(remoteAddress),
new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()));
return new TracedCommandExecutor(executor, tracer);
private static CommandExecutor createExecutor(URL remoteAddress, boolean enableTracing) {
ClientConfig config = ClientConfig.defaultConfig().baseUrl(remoteAddress);
if (enableTracing) {
Tracer tracer = OpenTelemetryTracer.getInstance();
CommandExecutor executor = new HttpCommandExecutor(
Collections.emptyMap(),
config,
new TracedHttpClient.Factory(tracer, HttpClient.Factory.createDefault()));
return new TracedCommandExecutor(executor, tracer);
} else {
return new HttpCommandExecutor(config);
}
}

@Beta
Expand Down

0 comments on commit 3d21349

Please sign in to comment.