This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathHello.java
More file actions
56 lines (46 loc) · 1.55 KB
/
Copy pathHello.java
File metadata and controls
56 lines (46 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package lesson02.exercise;
import io.opentracing.Span;
import com.google.common.collect.ImmutableMap;
import com.uber.jaeger.Tracer;
import lib.Tracing;
public class Hello {
private final Tracer tracer;
private Hello(Tracer tracer) {
this.tracer = tracer;
}
private void sayHello(String helloTo) {
Span span = tracer.buildSpan("say-hello").startManual();
span.setTag("hello-to", helloTo);
String helloStr = formatString(span, helloTo);
printHello(span, helloStr);
span.finish();
}
private String formatString(Span rootSpan, String helloTo) {
Span span = tracer.buildSpan("formatString").startManual();
try {
String helloStr = String.format("Hello, %s!", helloTo);
span.log(ImmutableMap.of("event", "string-format", "value", helloStr));
return helloStr;
} finally {
span.finish();
}
}
private void printHello(Span rootSpan, String helloStr) {
Span span = tracer.buildSpan("printHello").startManual();
try {
System.out.println(helloStr);
span.log(ImmutableMap.of("event", "println"));
} finally {
span.finish();
}
}
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);
tracer.close();
}
}