From 82c9b53a79682b527305421c182d11ca2e026db9 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Thu, 6 Sep 2018 23:17:05 +0700 Subject: [PATCH 1/9] Resolve deprecation & try-resource warnings --- java/src/main/java/lesson01/solution/Hello.java | 10 +++++----- .../main/java/lesson02/solution/HelloActive.java | 10 +++++----- .../main/java/lesson02/solution/HelloManual.java | 16 ++++++++-------- java/src/main/java/lesson03/exercise/Hello.java | 6 +++--- java/src/main/java/lesson03/solution/Hello.java | 6 +++--- java/src/main/java/lesson04/solution/Hello.java | 6 +++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/java/src/main/java/lesson01/solution/Hello.java b/java/src/main/java/lesson01/solution/Hello.java index 4d5a04d..df19556 100644 --- a/java/src/main/java/lesson01/solution/Hello.java +++ b/java/src/main/java/lesson01/solution/Hello.java @@ -15,9 +15,9 @@ private Hello(Tracer tracer) { } private void sayHello(String helloTo) { - Span span = tracer.buildSpan("say-hello").startManual(); + Span span = tracer.buildSpan("say-hello").start(); span.setTag("hello-to", helloTo); - + String helloStr = String.format("Hello, %s!", helloTo); span.log(ImmutableMap.of("event", "string-format", "value", helloStr)); @@ -32,8 +32,8 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson02/solution/HelloActive.java b/java/src/main/java/lesson02/solution/HelloActive.java index c08ec14..c3c5ac5 100644 --- a/java/src/main/java/lesson02/solution/HelloActive.java +++ b/java/src/main/java/lesson02/solution/HelloActive.java @@ -7,7 +7,7 @@ import lib.Tracing; public class HelloActive { - + private final Tracer tracer; private HelloActive(Tracer tracer) { @@ -17,7 +17,7 @@ private HelloActive(Tracer tracer) { private void sayHello(String helloTo) { try (Scope scope = tracer.buildSpan("say-hello").startActive(true)) { scope.span().setTag("hello-to", helloTo); - + String helloStr = formatString(helloTo); printHello(helloStr); } @@ -43,8 +43,8 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new HelloActive(tracer).sayHello(helloTo); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new HelloActive(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson02/solution/HelloManual.java b/java/src/main/java/lesson02/solution/HelloManual.java index 695ab7c..d1cadf4 100644 --- a/java/src/main/java/lesson02/solution/HelloManual.java +++ b/java/src/main/java/lesson02/solution/HelloManual.java @@ -7,7 +7,7 @@ import lib.Tracing; public class HelloManual { - + private final Tracer tracer; private HelloManual(Tracer tracer) { @@ -15,9 +15,9 @@ private HelloManual(Tracer tracer) { } private void sayHello(String helloTo) { - Span span = tracer.buildSpan("say-hello").startManual(); + Span span = tracer.buildSpan("say-hello").start(); span.setTag("hello-to", helloTo); - + String helloStr = formatString(span, helloTo); printHello(span, helloStr); @@ -25,7 +25,7 @@ private void sayHello(String helloTo) { } private String formatString(Span rootSpan, String helloTo) { - Span span = tracer.buildSpan("formatString").asChildOf(rootSpan).startManual(); + Span span = tracer.buildSpan("formatString").asChildOf(rootSpan).start(); try { String helloStr = String.format("Hello, %s!", helloTo); span.log(ImmutableMap.of("event", "string-format", "value", helloStr)); @@ -36,7 +36,7 @@ private String formatString(Span rootSpan, String helloTo) { } private void printHello(Span rootSpan, String helloStr) { - Span span = tracer.buildSpan("printHello").asChildOf(rootSpan).startManual(); + Span span = tracer.buildSpan("printHello").asChildOf(rootSpan).start(); try { System.out.println(helloStr); span.log(ImmutableMap.of("event", "println")); @@ -50,8 +50,8 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new HelloManual(tracer).sayHello(helloTo); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new HelloManual(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson03/exercise/Hello.java b/java/src/main/java/lesson03/exercise/Hello.java index 1a32c45..8db9303 100644 --- a/java/src/main/java/lesson03/exercise/Hello.java +++ b/java/src/main/java/lesson03/exercise/Hello.java @@ -67,8 +67,8 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson03/solution/Hello.java b/java/src/main/java/lesson03/solution/Hello.java index f293f17..f1172fd 100644 --- a/java/src/main/java/lesson03/solution/Hello.java +++ b/java/src/main/java/lesson03/solution/Hello.java @@ -75,8 +75,8 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson04/solution/Hello.java b/java/src/main/java/lesson04/solution/Hello.java index d155c14..bf6eded 100644 --- a/java/src/main/java/lesson04/solution/Hello.java +++ b/java/src/main/java/lesson04/solution/Hello.java @@ -77,8 +77,8 @@ public static void main(String[] args) { } String helloTo = args[0]; String greeting = args[1]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo, greeting); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo, greeting); + } } } From 15419f95590efae6cec3965c8f8a27d45a498510 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Thu, 6 Sep 2018 23:24:59 +0700 Subject: [PATCH 2/9] Add required modules to support jdk9+ --- java/run.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/run.sh b/java/run.sh index d9b33e0..fc0d9bc 100755 --- a/java/run.sh +++ b/java/run.sh @@ -1,8 +1,8 @@ #!/bin/bash if [ "$1" == "" ]; then - echo "Usage: run.sh qualified-class-name [args]" - exit 1 + echo "Usage: run.sh qualified-class-name [args]" + exit 1 fi className=$1 @@ -17,4 +17,9 @@ for jar in $(ls target/dependency/*.jar target/java-opentracing-tutorial-*.jar); CLASSPATH=$CLASSPATH:$jar done -java -cp $CLASSPATH $className $* +ADD_MODULES="" +if [ "$(java -version 2>&1 | head -1 | grep '\"1\.[78].\+\"')" = "" ]; then + ADD_MODULES="--add-modules=java.xml.bind" +fi + +java $ADD_MODULES -cp $CLASSPATH $className $* From 560464cfde4bf9c01be7a1cc08eaaff3e798849f Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Thu, 6 Sep 2018 23:34:56 +0700 Subject: [PATCH 3/9] Update lesson[124] README.md --- java/src/main/java/lesson01/README.md | 14 +++++++------- java/src/main/java/lesson02/README.md | 10 +++++----- java/src/main/java/lesson04/README.md | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/java/src/main/java/lesson01/README.md b/java/src/main/java/lesson01/README.md index ed1d541..03330f2 100644 --- a/java/src/main/java/lesson01/README.md +++ b/java/src/main/java/lesson01/README.md @@ -64,7 +64,7 @@ public class Hello { } private void sayHello(String helloTo) { - Span span = tracer.buildSpan("say-hello").startManual(); + Span span = tracer.buildSpan("say-hello").start(); String helloStr = String.format("Hello, %s!", helloTo); System.out.println(helloStr); @@ -85,7 +85,7 @@ public class Hello { We are using the following basic features of the OpenTracing API: * a `tracer` instance is used to create a span builder via `buildSpan()` * each `span` is given an _operation name_, `"say-hello"` in this case - * builder is used to create a span via `startManual()` + * builder is used to create a span via `start()` * each `span` must be finished by calling its `finish()` function * the start and end timestamps of the span will be captured automatically by the tracer implementation @@ -101,7 +101,7 @@ Our `pom.xml` already imports Jaeger: com.uber.jaeger jaeger-core - 0.26.0 + 0.27.0 ``` @@ -113,9 +113,9 @@ import com.uber.jaeger.Configuration.ReporterConfiguration; import com.uber.jaeger.Configuration.SamplerConfiguration; public static com.uber.jaeger.Tracer initTracer(String service) { - SamplerConfiguration samplerConfig = new SamplerConfiguration("const", 1); - ReporterConfiguration reporterConfig = new ReporterConfiguration(true, null, null, null, null); - Configuration config = new Configuration(service, samplerConfig, reporterConfig); + SamplerConfiguration samplerConfig = new SamplerConfiguration().withType("const").withParam(1); + ReporterConfiguration reporterConfig = new ReporterConfiguration().withLogSpans(true); + Configuration config = new Configuration(service).withSampler(samplerConfig).withReporter(reporterConfig); return (com.uber.jaeger.Tracer) config.getTracer(); } ``` @@ -177,7 +177,7 @@ In the case of `Hello Bryan`, the string `"Bryan"` is a good candidate for a spa to the whole span and not to a particular moment in time. We can record it like this: ```java -Span span = tracer.buildSpan("say-hello").startManual(); +Span span = tracer.buildSpan("say-hello").start(); span.setTag("hello-to", helloTo); ``` diff --git a/java/src/main/java/lesson02/README.md b/java/src/main/java/lesson02/README.md index c8f3990..26ab32c 100644 --- a/java/src/main/java/lesson02/README.md +++ b/java/src/main/java/lesson02/README.md @@ -42,7 +42,7 @@ Of course, this does not change the outcome. What we really want to do is to wra ```java private String formatString(Span rootSpan, String helloTo) { - Span span = tracer.buildSpan("formatString").startManual(); + Span span = tracer.buildSpan("formatString").start(); try { String helloStr = String.format("Hello, %s!", helloTo); span.log(ImmutableMap.of("event", "string-format", "value", helloStr)); @@ -53,7 +53,7 @@ private String formatString(Span rootSpan, String helloTo) { } private void printHello(Span rootSpan, String helloStr) { - Span span = tracer.buildSpan("printHello").startManual(); + Span span = tracer.buildSpan("printHello").start(); try { System.out.println(helloStr); span.log(ImmutableMap.of("event", "println")); @@ -81,7 +81,7 @@ What we really wanted was to establish causal relationship between the two new s span started in `main()`. We can do that by passing an additional option `asChildOf` to the span builder: ```java -Span span = tracer.buildSpan("formatString").asChildOf(rootSpan).startManual(); +Span span = tracer.buildSpan("formatString").asChildOf(rootSpan).start(); ``` If we think of the trace as a directed acyclic graph where nodes are the spans and edges are @@ -121,7 +121,7 @@ You may have noticed a few unpleasant side effects of our recent changes * we also had to write somewhat verbose try/finally code to finish the spans OpenTracing API for Java provides a better way. Using thread-locals and the notion of an "active span", -we can avoid passing the span through our code and just access it via `tracer. +we can avoid passing the span through our code and just access it via `tracer`. ```java private void sayHello(String helloTo) { @@ -150,7 +150,7 @@ private void printHello(String helloStr) { ``` In the above code we're making the following changes: - * We use `startActive()` method of the span builder instead of `startManual()`, + * We use `startActive()` method of the span builder instead of `start()`, which makes the span "active" by storing it in a thread-local storage. * `startActive()` returns a `Scope` object instead of a `Span`. Scope is a container of the currently active span. We access the active span via `scope.span()`. Once the scope is closed, the previous diff --git a/java/src/main/java/lesson04/README.md b/java/src/main/java/lesson04/README.md index 280d3cc..6d0db08 100644 --- a/java/src/main/java/lesson04/README.md +++ b/java/src/main/java/lesson04/README.md @@ -36,9 +36,9 @@ public static void main(String[] args) { } String helloTo = args[0]; String greeting = args[1]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo, greeting); - tracer.close(); + try (Tracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo, greeting); + } } ``` From 06b33b46925ac811924cd5c94309094de8fe369e Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Fri, 7 Sep 2018 17:07:52 +0700 Subject: [PATCH 4/9] Upgrade to io.jaegertracing:jaeger-core:0.31.0 --- java/pom.xml | 4 +-- java/src/main/java/lesson01/README.md | 29 ++++++++++--------- .../main/java/lesson01/solution/Hello.java | 8 ++--- java/src/main/java/lesson02/README.md | 12 ++++---- .../java/lesson02/solution/HelloActive.java | 8 ++--- .../java/lesson02/solution/HelloManual.java | 7 ++--- java/src/main/java/lesson03/README.md | 12 ++++---- .../main/java/lesson03/solution/Hello.java | 7 ++--- java/src/main/java/lesson04/README.md | 17 +++++------ .../main/java/lesson04/solution/Hello.java | 7 ++--- java/src/main/java/lib/Tracing.java | 14 ++++----- 11 files changed, 61 insertions(+), 64 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index d19b952..45c70f4 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -9,7 +9,7 @@ http://maven.apache.org UTF-8 - 0.26.0 + 0.31.0 1.7.5 23.0 1.1.4 @@ -40,7 +40,7 @@ - com.uber.jaeger + io.jaegertracing jaeger-core ${jaeger.version} diff --git a/java/src/main/java/lesson01/README.md b/java/src/main/java/lesson01/README.md index 03330f2..049ab41 100644 --- a/java/src/main/java/lesson01/README.md +++ b/java/src/main/java/lesson01/README.md @@ -94,40 +94,41 @@ That's because the function `GlobalTracer.get()` returns a no-op tracer by defau ### Initialize a real tracer -Let's create an instance of a real tracer, such as Jaeger (http://github.com/uber/jaeger-client-java). +Let's create an instance of a real tracer, such as Jaeger (https://github.com/jaegertracing/jaeger-client-java). Our `pom.xml` already imports Jaeger: ```xml - com.uber.jaeger + io.jaegertracing jaeger-core - 0.27.0 + 0.31.0 ``` First let's define a helper function that will create a tracer. ```java -import com.uber.jaeger.Configuration; -import com.uber.jaeger.Configuration.ReporterConfiguration; -import com.uber.jaeger.Configuration.SamplerConfiguration; +import io.jaegertracing.Configuration; +import io.jaegertracing.Configuration.ReporterConfiguration; +import io.jaegertracing.Configuration.SamplerConfiguration; +import io.jaegertracing.internal.JaegerTracer; -public static com.uber.jaeger.Tracer initTracer(String service) { +public static JaegerTracer initTracer(String service) { SamplerConfiguration samplerConfig = new SamplerConfiguration().withType("const").withParam(1); ReporterConfiguration reporterConfig = new ReporterConfiguration().withLogSpans(true); Configuration config = new Configuration(service).withSampler(samplerConfig).withReporter(reporterConfig); - return (com.uber.jaeger.Tracer) config.getTracer(); + return config.getTracer(); } ``` To use this instance, let's change the main function: ```java -import com.uber.jaeger.Tracer; +import io.jaegertracing.internal.JaegerTracer; -Tracer tracer = initTracer("hello-world"); -new Hello(tracer).sayHello(helloTo); -tracer.close(); +try (JaegerTracer tracer = initTracer("hello-world")) { + new Hello(tracer).sayHello(helloTo); +} ``` Note that we are passing a string `hello-world` to the init method. It is used to mark all spans emitted by @@ -137,9 +138,9 @@ If we run the program now, we should see a span logged: ``` $ ./run.sh lesson01.exercise.Hello Bryan -[lesson01.exercise.Hello.main()] INFO com.uber.jaeger.Configuration - Initialized tracer=Tracer(...) +[lesson01.exercise.Hello.main()] INFO io.jaegertracing.Configuration - Initialized tracer=Tracer(...) Hello, Bryan! -[lesson01.exercise.Hello.main()] INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 76509ca0cd333055:76509ca0cd333055:0:1 - say-hello +[lesson01.exercise.Hello.main()] INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 76509ca0cd333055:76509ca0cd333055:0:1 - say-hello ``` If you have Jaeger backend running, you should be able to see the trace in the UI. diff --git a/java/src/main/java/lesson01/solution/Hello.java b/java/src/main/java/lesson01/solution/Hello.java index df19556..6cdcad7 100644 --- a/java/src/main/java/lesson01/solution/Hello.java +++ b/java/src/main/java/lesson01/solution/Hello.java @@ -1,16 +1,16 @@ package lesson01.solution; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Span; import lib.Tracing; public class Hello { - private final Tracer tracer; + private final JaegerTracer tracer; - private Hello(Tracer tracer) { + private Hello(JaegerTracer tracer) { this.tracer = tracer; } @@ -32,7 +32,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (Tracer tracer = Tracing.init("hello-world")) { + try (JaegerTracer tracer = Tracing.init("hello-world")) { new Hello(tracer).sayHello(helloTo); } } diff --git a/java/src/main/java/lesson02/README.md b/java/src/main/java/lesson02/README.md index 26ab32c..5e79b90 100644 --- a/java/src/main/java/lesson02/README.md +++ b/java/src/main/java/lesson02/README.md @@ -67,10 +67,10 @@ Let's run it: ``` $ ./run.sh lesson02.exercise.Hello Bryan -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 12c92a6604499c25:12c92a6604499c25:0:1 - formatString +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 12c92a6604499c25:12c92a6604499c25:0:1 - formatString Hello, Bryan! -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 14aaaf7a377e5147:14aaaf7a377e5147:0:1 - printHello -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: a25cf88369793b9b:a25cf88369793b9b:0:1 - say-hello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 14aaaf7a377e5147:14aaaf7a377e5147:0:1 - printHello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: a25cf88369793b9b:a25cf88369793b9b:0:1 - say-hello ``` We got three spans, but there is a problem here. The first hexadecimal segment of the output represents @@ -100,10 +100,10 @@ spans now belong to the same trace: ``` $ ./run.sh lesson02.exercise.Hello Bryan -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:42d38965612a195a:4ca67017b68d14c:1 - formatString +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:42d38965612a195a:4ca67017b68d14c:1 - formatString Hello, Bryan! -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:19af156b64c22d23:4ca67017b68d14c:1 - printHello -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:4ca67017b68d14c:0:1 - say-hello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:19af156b64c22d23:4ca67017b68d14c:1 - printHello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 4ca67017b68d14c:4ca67017b68d14c:0:1 - say-hello ``` We can also see that instead of `0` in the 3rd position the first two reported spans display diff --git a/java/src/main/java/lesson02/solution/HelloActive.java b/java/src/main/java/lesson02/solution/HelloActive.java index c3c5ac5..d58e756 100644 --- a/java/src/main/java/lesson02/solution/HelloActive.java +++ b/java/src/main/java/lesson02/solution/HelloActive.java @@ -1,9 +1,10 @@ package lesson02.solution; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; +import io.opentracing.Tracer; import lib.Tracing; public class HelloActive { @@ -43,8 +44,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (Tracer tracer = Tracing.init("hello-world")) { - new HelloActive(tracer).sayHello(helloTo); - } + Tracer tracer = Tracing.init("hello-world"); + new HelloActive(tracer).sayHello(helloTo); } } diff --git a/java/src/main/java/lesson02/solution/HelloManual.java b/java/src/main/java/lesson02/solution/HelloManual.java index d1cadf4..ee6d60a 100644 --- a/java/src/main/java/lesson02/solution/HelloManual.java +++ b/java/src/main/java/lesson02/solution/HelloManual.java @@ -1,9 +1,9 @@ package lesson02.solution; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; import io.opentracing.Span; +import io.opentracing.Tracer; import lib.Tracing; public class HelloManual { @@ -50,8 +50,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (Tracer tracer = Tracing.init("hello-world")) { - new HelloManual(tracer).sayHello(helloTo); - } + Tracer tracer = Tracing.init("hello-world"); + new HelloManual(tracer).sayHello(helloTo); } } diff --git a/java/src/main/java/lesson03/README.md b/java/src/main/java/lesson03/README.md index a0bd820..bffce38 100644 --- a/java/src/main/java/lesson03/README.md +++ b/java/src/main/java/lesson03/README.md @@ -219,7 +219,7 @@ Then run `lesson03.exercise.Hello`. You should see the outputs like this: $ ./run.sh lesson03.exercise.Formatter server [skip noise] INFO org.eclipse.jetty.server.Server: Started @3968ms -INFO com.uber.jaeger.reporters.LoggingReporter: Span reported: 5fe2d9de96c3887a:b73ff97ea68a36f8:72910f6018b1bd09:1 - format +INFO io.jaegertracing.reporters.LoggingReporter: Span reported: 5fe2d9de96c3887a:b73ff97ea68a36f8:72910f6018b1bd09:1 - format 127.0.0.1 - - "GET /format?helloTo=Bryan HTTP/1.1" 200 13 "-" "okhttp/3.9.0" 3 # publisher @@ -227,15 +227,15 @@ $ ./run.sh lesson03.exercise.Publisher server [skip noise] INFO org.eclipse.jetty.server.Server: Started @3388ms Hello, Bryan! -INFO com.uber.jaeger.reporters.LoggingReporter: Span reported: 5fe2d9de96c3887a:4a2c39e462cb2a92:62d73167c129ecd7:1 - publish +INFO io.jaegertracing.reporters.LoggingReporter: Span reported: 5fe2d9de96c3887a:4a2c39e462cb2a92:62d73167c129ecd7:1 - publish 127.0.0.1 - - "GET /publish?helloStr=Hello,%20Bryan! HTTP/1.1" 200 9 "-" "okhttp/3.9.0" 80 # client $ ./run.sh lesson03.exercise.Hello Bryan -INFO com.uber.jaeger.Configuration - Initialized tracer=Tracer(...) -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:72910f6018b1bd09:5fe2d9de96c3887a:1 - formatString -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:62d73167c129ecd7:5fe2d9de96c3887a:1 - printHello -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:5fe2d9de96c3887a:0:1 - say-hello +INFO io.jaegertracing.Configuration - Initialized tracer=Tracer(...) +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:72910f6018b1bd09:5fe2d9de96c3887a:1 - formatString +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:62d73167c129ecd7:5fe2d9de96c3887a:1 - printHello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: 5fe2d9de96c3887a:5fe2d9de96c3887a:0:1 - say-hello ``` Note how all recorded spans show the same trace ID `5fe2d9de96c3887a`. This is a sign diff --git a/java/src/main/java/lesson03/solution/Hello.java b/java/src/main/java/lesson03/solution/Hello.java index f1172fd..9f1c899 100644 --- a/java/src/main/java/lesson03/solution/Hello.java +++ b/java/src/main/java/lesson03/solution/Hello.java @@ -3,9 +3,9 @@ import java.io.IOException; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; import io.opentracing.Scope; +import io.opentracing.Tracer; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import lib.Tracing; @@ -75,8 +75,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (Tracer tracer = Tracing.init("hello-world")) { - new Hello(tracer).sayHello(helloTo); - } + Tracer tracer = Tracing.init("hello-world"); + new Hello(tracer).sayHello(helloTo); } } diff --git a/java/src/main/java/lesson04/README.md b/java/src/main/java/lesson04/README.md index 6d0db08..7660f84 100644 --- a/java/src/main/java/lesson04/README.md +++ b/java/src/main/java/lesson04/README.md @@ -36,9 +36,8 @@ public static void main(String[] args) { } String helloTo = args[0]; String greeting = args[1]; - try (Tracer tracer = Tracing.init("hello-world")) { - new Hello(tracer).sayHello(helloTo, greeting); - } + Tracer tracer = Tracing.init("hello-world"); + new Hello(tracer).sayHello(helloTo, greeting); } ``` @@ -72,7 +71,7 @@ with two arguments, e.g. `Bryan Bonjour`. The `publisher` should print `Bonjour, $ ./run.sh lesson04.exercise.Formatter server [skip noise] INFO org.eclipse.jetty.server.Server: Started @3508ms -INFO com.uber.jaeger.reporters.LoggingReporter: Span reported: e6ee8a816c8386ce:cd2c1d243ddf319b:ef06ddba375ff053:1 - format +INFO io.jaegertracing.reporters.LoggingReporter: Span reported: e6ee8a816c8386ce:cd2c1d243ddf319b:ef06ddba375ff053:1 - format 127.0.0.1 - - "GET /format?helloTo=Bryan HTTP/1.1" 200 15 "-" "okhttp/3.9.0" 69 # publisher @@ -80,15 +79,15 @@ $ ./run.sh lesson04.exercise.Publisher server [skip noise] INFO org.eclipse.jetty.server.Server: Started @3388ms Bonjour, Bryan! -INFO com.uber.jaeger.reporters.LoggingReporter: Span reported: e6ee8a816c8386ce:f46156fcd7d3abd3:20cdfed1d23892c1:1 - publish +INFO io.jaegertracing.reporters.LoggingReporter: Span reported: e6ee8a816c8386ce:f46156fcd7d3abd3:20cdfed1d23892c1:1 - publish 127.0.0.1 - - "GET /publish?helloStr=Bonjour,%20Bryan! HTTP/1.1" 200 9 "-" "okhttp/3.9.0" 92 # client $ ./run.sh lesson04.exercise.Hello Bryan Bonjour -INFO com.uber.jaeger.Configuration - Initialized tracer=Tracer(...) -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:ef06ddba375ff053:e6ee8a816c8386ce:1 - formatString -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:20cdfed1d23892c1:e6ee8a816c8386ce:1 - printHello -INFO com.uber.jaeger.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:e6ee8a816c8386ce:0:1 - say-hello +INFO io.jaegertracing.Configuration - Initialized tracer=Tracer(...) +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:ef06ddba375ff053:e6ee8a816c8386ce:1 - formatString +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:20cdfed1d23892c1:e6ee8a816c8386ce:1 - printHello +INFO io.jaegertracing.reporters.LoggingReporter - Span reported: e6ee8a816c8386ce:e6ee8a816c8386ce:0:1 - say-hello ``` ### What's the Big Deal? diff --git a/java/src/main/java/lesson04/solution/Hello.java b/java/src/main/java/lesson04/solution/Hello.java index bf6eded..4a24447 100644 --- a/java/src/main/java/lesson04/solution/Hello.java +++ b/java/src/main/java/lesson04/solution/Hello.java @@ -3,9 +3,9 @@ import java.io.IOException; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; import io.opentracing.Scope; +import io.opentracing.Tracer; import io.opentracing.propagation.Format; import io.opentracing.tag.Tags; import lib.Tracing; @@ -77,8 +77,7 @@ public static void main(String[] args) { } String helloTo = args[0]; String greeting = args[1]; - try (Tracer tracer = Tracing.init("hello-world")) { - new Hello(tracer).sayHello(helloTo, greeting); - } + Tracer tracer = Tracing.init("hello-world"); + new Hello(tracer).sayHello(helloTo, greeting); } } diff --git a/java/src/main/java/lib/Tracing.java b/java/src/main/java/lib/Tracing.java index bea4531..a0b5a0e 100644 --- a/java/src/main/java/lib/Tracing.java +++ b/java/src/main/java/lib/Tracing.java @@ -6,11 +6,11 @@ import javax.ws.rs.core.MultivaluedMap; -import com.uber.jaeger.Configuration; -import com.uber.jaeger.Configuration.ReporterConfiguration; -import com.uber.jaeger.Configuration.SamplerConfiguration; -import com.uber.jaeger.samplers.ConstSampler; - +import io.jaegertracing.Configuration; +import io.jaegertracing.Configuration.ReporterConfiguration; +import io.jaegertracing.Configuration.SamplerConfiguration; +import io.jaegertracing.internal.JaegerTracer; +import io.jaegertracing.internal.samplers.ConstSampler; import io.opentracing.Scope; import io.opentracing.SpanContext; import io.opentracing.Tracer; @@ -24,7 +24,7 @@ public final class Tracing { private Tracing() { } - public static com.uber.jaeger.Tracer init(String service) { + public static JaegerTracer init(String service) { SamplerConfiguration samplerConfig = SamplerConfiguration.fromEnv() .withType(ConstSampler.TYPE) .withParam(1); @@ -36,7 +36,7 @@ public static com.uber.jaeger.Tracer init(String service) { .withSampler(samplerConfig) .withReporter(reporterConfig); - return (com.uber.jaeger.Tracer) config.getTracer(); + return config.getTracer(); } public static Scope startServerSpan(Tracer tracer, javax.ws.rs.core.HttpHeaders httpHeaders, String operationName) { From b748e2f45d113bd5e2c894e1a52178af7684f668 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Fri, 7 Sep 2018 17:53:06 +0700 Subject: [PATCH 5/9] Make solutions OT vendor agnostic --- java/src/main/java/lesson01/README.md | 12 +++++------- java/src/main/java/lesson01/solution/Hello.java | 11 +++++------ .../src/main/java/lesson02/solution/HelloActive.java | 1 - 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/java/src/main/java/lesson01/README.md b/java/src/main/java/lesson01/README.md index 049ab41..06aaad9 100644 --- a/java/src/main/java/lesson01/README.md +++ b/java/src/main/java/lesson01/README.md @@ -53,13 +53,14 @@ We can use a global instance returned by `io.opentracing.util.GlobalTracer.get() ```java import io.opentracing.Span; +import io.opentracing.Tracer; import io.opentracing.util.GlobalTracer; public class Hello { - private final io.opentracing.Tracer tracer; + private final Tracer tracer; - private Hello(io.opentracing.Tracer tracer) { + private Hello(Tracer tracer) { this.tracer = tracer; } @@ -124,11 +125,8 @@ public static JaegerTracer initTracer(String service) { To use this instance, let's change the main function: ```java -import io.jaegertracing.internal.JaegerTracer; - -try (JaegerTracer tracer = initTracer("hello-world")) { - new Hello(tracer).sayHello(helloTo); -} +Tracer tracer = initTracer("hello-world"); +new Hello(tracer).sayHello(helloTo); ``` Note that we are passing a string `hello-world` to the init method. It is used to mark all spans emitted by diff --git a/java/src/main/java/lesson01/solution/Hello.java b/java/src/main/java/lesson01/solution/Hello.java index 6cdcad7..5a47152 100644 --- a/java/src/main/java/lesson01/solution/Hello.java +++ b/java/src/main/java/lesson01/solution/Hello.java @@ -2,15 +2,15 @@ import com.google.common.collect.ImmutableMap; -import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Span; +import io.opentracing.Tracer; import lib.Tracing; public class Hello { - private final JaegerTracer tracer; + private final Tracer tracer; - private Hello(JaegerTracer tracer) { + private Hello(Tracer tracer) { this.tracer = tracer; } @@ -32,8 +32,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (JaegerTracer tracer = Tracing.init("hello-world")) { - new Hello(tracer).sayHello(helloTo); - } + Tracer tracer = Tracing.init("hello-world"); + new Hello(tracer).sayHello(helloTo); } } diff --git a/java/src/main/java/lesson02/solution/HelloActive.java b/java/src/main/java/lesson02/solution/HelloActive.java index d58e756..64dcc8b 100644 --- a/java/src/main/java/lesson02/solution/HelloActive.java +++ b/java/src/main/java/lesson02/solution/HelloActive.java @@ -2,7 +2,6 @@ import com.google.common.collect.ImmutableMap; -import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; From 06c884767aa0a4597c386a4b328b535241647cc4 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Sat, 8 Sep 2018 01:11:43 +0700 Subject: [PATCH 6/9] Replace jaeger-core with jaeger-thrift --- java/pom.xml | 2 +- java/src/main/java/lesson01/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 45c70f4..156efa2 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -41,7 +41,7 @@ io.jaegertracing - jaeger-core + jaeger-thrift ${jaeger.version} diff --git a/java/src/main/java/lesson01/README.md b/java/src/main/java/lesson01/README.md index 06aaad9..65cb578 100644 --- a/java/src/main/java/lesson01/README.md +++ b/java/src/main/java/lesson01/README.md @@ -101,7 +101,7 @@ Our `pom.xml` already imports Jaeger: ```xml io.jaegertracing - jaeger-core + jaeger-thrift 0.31.0 ``` From 77377a23d8cfb95eecc9f958a970db11a3c1ff6b Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Sat, 8 Sep 2018 01:38:07 +0700 Subject: [PATCH 7/9] Replace jaeger-thrift with jaeger-client --- java/pom.xml | 2 +- java/src/main/java/lesson01/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 156efa2..757f3ba 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -41,7 +41,7 @@ io.jaegertracing - jaeger-thrift + jaeger-client ${jaeger.version} diff --git a/java/src/main/java/lesson01/README.md b/java/src/main/java/lesson01/README.md index 65cb578..8220933 100644 --- a/java/src/main/java/lesson01/README.md +++ b/java/src/main/java/lesson01/README.md @@ -101,7 +101,7 @@ Our `pom.xml` already imports Jaeger: ```xml io.jaegertracing - jaeger-thrift + jaeger-client 0.31.0 ``` From 8af3052f8d3946bf929136e0d7c3047b2f92f060 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Sat, 8 Sep 2018 01:40:32 +0700 Subject: [PATCH 8/9] Make solutions OT vendor agnostic --- java/src/main/java/lesson03/exercise/Hello.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/java/src/main/java/lesson03/exercise/Hello.java b/java/src/main/java/lesson03/exercise/Hello.java index 8db9303..bed0054 100644 --- a/java/src/main/java/lesson03/exercise/Hello.java +++ b/java/src/main/java/lesson03/exercise/Hello.java @@ -3,9 +3,9 @@ import java.io.IOException; import com.google.common.collect.ImmutableMap; -import com.uber.jaeger.Tracer; import io.opentracing.Scope; +import io.opentracing.Tracer; import lib.Tracing; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -67,8 +67,7 @@ public static void main(String[] args) { throw new IllegalArgumentException("Expecting one argument"); } String helloTo = args[0]; - try (Tracer tracer = Tracing.init("hello-world")) { - new Hello(tracer).sayHello(helloTo); - } + Tracer tracer = Tracing.init("hello-world"); + new Hello(tracer).sayHello(helloTo); } } From ea77699ba5e58660f8d2c024e165f32609265619 Mon Sep 17 00:00:00 2001 From: Seva Safris Date: Thu, 27 Sep 2018 22:03:25 +0700 Subject: [PATCH 9/9] Upcast to JaegerTracer for Closeable --- java/src/main/java/lesson01/solution/Hello.java | 7 +++++-- java/src/main/java/lesson02/solution/HelloActive.java | 7 +++++-- java/src/main/java/lesson02/solution/HelloManual.java | 7 +++++-- java/src/main/java/lesson03/exercise/Hello.java | 7 +++++-- java/src/main/java/lesson03/solution/Formatter.java | 6 ++++-- java/src/main/java/lesson03/solution/Hello.java | 7 +++++-- java/src/main/java/lesson03/solution/Publisher.java | 6 ++++-- java/src/main/java/lesson04/exercise/Publisher.java | 6 ++++-- java/src/main/java/lesson04/solution/Formatter.java | 6 ++++-- java/src/main/java/lesson04/solution/Hello.java | 6 ++++-- java/src/main/java/lesson04/solution/Publisher.java | 6 ++++-- 11 files changed, 49 insertions(+), 22 deletions(-) diff --git a/java/src/main/java/lesson01/solution/Hello.java b/java/src/main/java/lesson01/solution/Hello.java index 5a47152..ab3ba07 100644 --- a/java/src/main/java/lesson01/solution/Hello.java +++ b/java/src/main/java/lesson01/solution/Hello.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Span; import io.opentracing.Tracer; import lib.Tracing; @@ -31,8 +32,10 @@ public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException("Expecting one argument"); } + String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson02/solution/HelloActive.java b/java/src/main/java/lesson02/solution/HelloActive.java index 64dcc8b..5f428e8 100644 --- a/java/src/main/java/lesson02/solution/HelloActive.java +++ b/java/src/main/java/lesson02/solution/HelloActive.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -42,8 +43,10 @@ public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException("Expecting one argument"); } + String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new HelloActive(tracer).sayHello(helloTo); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new HelloActive(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson02/solution/HelloManual.java b/java/src/main/java/lesson02/solution/HelloManual.java index ee6d60a..0e8a7b6 100644 --- a/java/src/main/java/lesson02/solution/HelloManual.java +++ b/java/src/main/java/lesson02/solution/HelloManual.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Span; import io.opentracing.Tracer; import lib.Tracing; @@ -49,8 +50,10 @@ public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException("Expecting one argument"); } + String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new HelloManual(tracer).sayHello(helloTo); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new HelloManual(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson03/exercise/Hello.java b/java/src/main/java/lesson03/exercise/Hello.java index bed0054..32a130f 100644 --- a/java/src/main/java/lesson03/exercise/Hello.java +++ b/java/src/main/java/lesson03/exercise/Hello.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -66,8 +67,10 @@ public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException("Expecting one argument"); } + String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson03/solution/Formatter.java b/java/src/main/java/lesson03/solution/Formatter.java index 679620e..c31d5f6 100644 --- a/java/src/main/java/lesson03/solution/Formatter.java +++ b/java/src/main/java/lesson03/solution/Formatter.java @@ -13,6 +13,7 @@ import io.dropwizard.Application; import io.dropwizard.Configuration; import io.dropwizard.setup.Environment; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -48,7 +49,8 @@ public static void main(String[] args) throws Exception { System.setProperty("dw.server.applicationConnectors[0].port", "8081"); System.setProperty("dw.server.adminConnectors[0].port", "9081"); - Tracer tracer = Tracing.init("formatter"); - new Formatter(tracer).run(args); + try (JaegerTracer tracer = Tracing.init("formatter")) { + new Formatter(tracer).run(args); + } } } diff --git a/java/src/main/java/lesson03/solution/Hello.java b/java/src/main/java/lesson03/solution/Hello.java index 9f1c899..22dc23c 100644 --- a/java/src/main/java/lesson03/solution/Hello.java +++ b/java/src/main/java/lesson03/solution/Hello.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import io.opentracing.propagation.Format; @@ -74,8 +75,10 @@ public static void main(String[] args) { if (args.length != 1) { throw new IllegalArgumentException("Expecting one argument"); } + String helloTo = args[0]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo); + } } } diff --git a/java/src/main/java/lesson03/solution/Publisher.java b/java/src/main/java/lesson03/solution/Publisher.java index 99d92bc..623c064 100644 --- a/java/src/main/java/lesson03/solution/Publisher.java +++ b/java/src/main/java/lesson03/solution/Publisher.java @@ -13,6 +13,7 @@ import io.dropwizard.Application; import io.dropwizard.Configuration; import io.dropwizard.setup.Environment; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -47,7 +48,8 @@ public void run(Configuration configuration, Environment environment) throws Exc public static void main(String[] args) throws Exception { System.setProperty("dw.server.applicationConnectors[0].port", "8082"); System.setProperty("dw.server.adminConnectors[0].port", "9082"); - Tracer tracer = Tracing.init("publisher"); - new Publisher(tracer).run(args); + try (JaegerTracer tracer = Tracing.init("publisher")) { + new Publisher(tracer).run(args); + } } } diff --git a/java/src/main/java/lesson04/exercise/Publisher.java b/java/src/main/java/lesson04/exercise/Publisher.java index 101e25c..56b8a98 100644 --- a/java/src/main/java/lesson04/exercise/Publisher.java +++ b/java/src/main/java/lesson04/exercise/Publisher.java @@ -13,6 +13,7 @@ import io.dropwizard.Application; import io.dropwizard.Configuration; import io.dropwizard.setup.Environment; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -47,7 +48,8 @@ public void run(Configuration configuration, Environment environment) throws Exc public static void main(String[] args) throws Exception { System.setProperty("dw.server.applicationConnectors[0].port", "8082"); System.setProperty("dw.server.adminConnectors[0].port", "9082"); - Tracer tracer = Tracing.init("publisher"); - new Publisher(tracer).run(args); + try (JaegerTracer tracer = Tracing.init("publisher")) { + new Publisher(tracer).run(args); + } } } diff --git a/java/src/main/java/lesson04/solution/Formatter.java b/java/src/main/java/lesson04/solution/Formatter.java index 9ea0a53..29775da 100644 --- a/java/src/main/java/lesson04/solution/Formatter.java +++ b/java/src/main/java/lesson04/solution/Formatter.java @@ -13,6 +13,7 @@ import io.dropwizard.Application; import io.dropwizard.Configuration; import io.dropwizard.setup.Environment; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -51,7 +52,8 @@ public void run(Configuration configuration, Environment environment) throws Exc public static void main(String[] args) throws Exception { System.setProperty("dw.server.applicationConnectors[0].port", "8081"); System.setProperty("dw.server.adminConnectors[0].port", "9081"); - Tracer tracer = Tracing.init("formatter"); - new Formatter(tracer).run(args); + try (JaegerTracer tracer = Tracing.init("formatter")) { + new Formatter(tracer).run(args); + } } } diff --git a/java/src/main/java/lesson04/solution/Hello.java b/java/src/main/java/lesson04/solution/Hello.java index 4a24447..35b27f0 100644 --- a/java/src/main/java/lesson04/solution/Hello.java +++ b/java/src/main/java/lesson04/solution/Hello.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import io.opentracing.propagation.Format; @@ -77,7 +78,8 @@ public static void main(String[] args) { } String helloTo = args[0]; String greeting = args[1]; - Tracer tracer = Tracing.init("hello-world"); - new Hello(tracer).sayHello(helloTo, greeting); + try (JaegerTracer tracer = Tracing.init("hello-world")) { + new Hello(tracer).sayHello(helloTo, greeting); + } } } diff --git a/java/src/main/java/lesson04/solution/Publisher.java b/java/src/main/java/lesson04/solution/Publisher.java index 74ab33d..d01c15f 100644 --- a/java/src/main/java/lesson04/solution/Publisher.java +++ b/java/src/main/java/lesson04/solution/Publisher.java @@ -13,6 +13,7 @@ import io.dropwizard.Application; import io.dropwizard.Configuration; import io.dropwizard.setup.Environment; +import io.jaegertracing.internal.JaegerTracer; import io.opentracing.Scope; import io.opentracing.Tracer; import lib.Tracing; @@ -47,7 +48,8 @@ public void run(Configuration configuration, Environment environment) throws Exc public static void main(String[] args) throws Exception { System.setProperty("dw.server.applicationConnectors[0].port", "8082"); System.setProperty("dw.server.adminConnectors[0].port", "9082"); - Tracer tracer = Tracing.init("publisher"); - new Publisher(tracer).run(args); + try (JaegerTracer tracer = Tracing.init("publisher")) { + new Publisher(tracer).run(args); + } } }