aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2018-07-11 12:30:58 -0700
committerKristen Kozak <sebright@google.com>2018-07-11 12:30:58 -0700
commitda272152bc24bbbe78217a2655260cae9da7242b (patch)
treef92f3784f8dd35ffc2c162fb510acad46bba1072 /README.md
parent17aa3eb213de1a9785694d352571a395df008aad (diff)
downloadopencensus-java-da272152bc24bbbe78217a2655260cae9da7242b.tar.gz
Format and add imports to tracing example in readme.
Diffstat (limited to 'README.md')
-rw-r--r--README.md20
1 files changed, 13 insertions, 7 deletions
diff --git a/README.md b/README.md
index 861eff23..393b38ee 100644
--- a/README.md
+++ b/README.md
@@ -64,18 +64,24 @@ annotations is possible because we propagate scope. 3rd parties libraries like S
the same way.
```java
+import io.opencensus.common.Scope;
+import io.opencensus.trace.Tracer;
+import io.opencensus.trace.Tracing;
+import io.opencensus.trace.samplers.Samplers;
+
public final class MyClassWithTracing {
private static final Tracer tracer = Tracing.getTracer();
public static void doWork() {
- // Create a child Span of the current Span. Always record events for this span and force it to
- // be sampled. This makes it easier to try out the example, but unless you have a clear use
+ // Create a child Span of the current Span. Always record events for this span and force it to
+ // be sampled. This makes it easier to try out the example, but unless you have a clear use
// case, you don't need to explicitly set record events or sampler.
- try (Scope ss =
- tracer.spanBuilder("MyChildWorkSpan")
- .setRecordEvents(true)
- .setSampler(Samplers.alwaysSample())
- .startScopedSpan()) {
+ try (Scope ss =
+ tracer
+ .spanBuilder("MyChildWorkSpan")
+ .setRecordEvents(true)
+ .setSampler(Samplers.alwaysSample())
+ .startScopedSpan()) {
doInitialWork();
tracer.getCurrentSpan().addAnnotation("Finished initial work");
doFinalWork();