Skip to content

Commit

Permalink
[tracing]: Ensure tracers are found from --ext classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Apr 2, 2019
1 parent 2bdc860 commit 3f42b4e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import io.opentracing.propagation.TextMapExtractAdapter;
import io.opentracing.util.GlobalTracer;

import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.StringJoiner;
import java.util.function.Function;

class OpenTracingTracer implements DistributedTracer {
Expand Down Expand Up @@ -75,4 +72,9 @@ public Span getActiveSpan() {
io.opentracing.Span span = delegate.activeSpan();
return span == null ? null : new OpenTracingSpan(delegate, span);
}

@Override
public String toString() {
return "OpenTracing(" + delegate.getClass().getSimpleName() + ")";
}
}
20 changes: 13 additions & 7 deletions java/server/src/org/openqa/selenium/grid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.File;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
Expand All @@ -32,18 +33,22 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

private static final Logger LOG = Logger.getLogger(Main.class.getName());

public static void main(String[] args) throws Exception {
if (args.length == 0) {
new Help(loadCommands(Main.class.getClassLoader())).configure().run();

} else {
if ("--ext".equals(args[0])) {
if (args.length > 1) {
Expand All @@ -70,24 +75,25 @@ public static void main(String[] args) throws Exception {
try {
return file.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
LOG.log(Level.SEVERE, "Unable to find JAR file " + file, e);
throw new UncheckedIOException(e);
}
}).filter(Objects::nonNull).toArray(URL[]::new);
}).toArray(URL[]::new);

URLClassLoader loader = AccessController.doPrivileged(
(PrivilegedAction<URLClassLoader>) () ->
new URLClassLoader(jarUrls, Main.class.getClassLoader()));

// Ensure that we use our freshly minted classloader by default.
Thread.currentThread().setContextClassLoader(loader);

if (args.length > 2) {
String[] remainingArgs = new String[args.length - 2];
System.arraycopy(args, 2, remainingArgs, 0, args.length - 2);
launch(remainingArgs, loader);

} else {
new Help(loadCommands(loader)).configure().run();
}

} else {
new Help(loadCommands(Main.class.getClassLoader())).configure().run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
@AutoService(CliCommand.class)
public class Standalone implements CliCommand {

public static final Logger LOG = Logger.getLogger("selenium");

@Override
public String getName() {
return "standalone";
Expand Down Expand Up @@ -117,9 +119,10 @@ public Executable configure(String... args) {
LoggingOptions loggingOptions = new LoggingOptions(config);
loggingOptions.configureLogging();

Logger.getLogger("selenium").info("Logging configured.");
LOG.info("Logging configured.");

DistributedTracer tracer = loggingOptions.getTracer();
LOG.info("Using tracer: " + tracer);
GlobalDistributedTracer.setInstance(tracer);

EventBusConfig events = new EventBusConfig(config);
Expand Down

0 comments on commit 3f42b4e

Please sign in to comment.