Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opentracing example to set span #6

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions vertx-opentracing/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ over the configuration.
----
{@link examples.OpenTracingExamples#ex2}
----

After the Tracer has been configured, Vert.x may inject _spans_ into existing traces for
some API calls, such as HTTP client or server requests. A trace that starts from a server
call will be automatically created by Vert.x.

However, to initiate a trace for a client call, you need to create it first and make Vert.x
aware of it by using `OpenTracingUtil.setSpan`:

[source,$lang]
----
{@link examples.OpenTracingExamples#ex3}
----

In an HTTP scenario between two Vert.x services, a span will be created client-side, then
the trace context will be propagated server-side and another span will be added to the trace.
11 changes: 11 additions & 0 deletions vertx-opentracing/src/main/java/examples/OpenTracingExamples.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package examples;

import io.opentracing.Span;
import io.opentracing.Tracer;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.docgen.Source;
import io.vertx.tracing.opentracing.OpenTracingOptions;
import io.vertx.tracing.opentracing.OpenTracingUtil;

@Source
public class OpenTracingExamples {
Expand All @@ -24,4 +26,13 @@ public void ex2(Tracer tracer) {
)
);
}

public void ex3(Tracer tracer) {
Span span = tracer.buildSpan("my-operation")
.withTag("some-key", "some-value")
.start();
OpenTracingUtil.setSpan(span);
// Do something, e.g. client request
span.finish();
}
}