diff options
author | Kristen Kozak <sebright@google.com> | 2018-07-11 12:30:58 -0700 |
---|---|---|
committer | Kristen Kozak <sebright@google.com> | 2018-07-11 12:30:58 -0700 |
commit | da272152bc24bbbe78217a2655260cae9da7242b (patch) | |
tree | f92f3784f8dd35ffc2c162fb510acad46bba1072 /README.md | |
parent | 17aa3eb213de1a9785694d352571a395df008aad (diff) | |
download | opencensus-java-da272152bc24bbbe78217a2655260cae9da7242b.tar.gz |
Format and add imports to tracing example in readme.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -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(); |