570 lines
26 KiB
HTML
570 lines
26 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!-- NewPage -->
|
|
<html lang="en">
|
|
<head>
|
|
<!-- Generated by javadoc (1.8.0_181-google-v7) on Thu Apr 25 10:43:39 PDT 2019 -->
|
|
<title>Span.Builder (openconsensus-api 0.1.0-SNAPSHOT API)</title>
|
|
<meta name="date" content="2019-04-25">
|
|
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
|
|
<script type="text/javascript" src="../../script.js"></script>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript"><!--
|
|
try {
|
|
if (location.href.indexOf('is-external=true') == -1) {
|
|
parent.document.title="Span.Builder (openconsensus-api 0.1.0-SNAPSHOT API)";
|
|
}
|
|
}
|
|
catch(err) {
|
|
}
|
|
//-->
|
|
var methods = {"i0":6,"i1":6,"i2":6,"i3":6,"i4":6,"i5":6,"i6":6,"i7":6};
|
|
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"]};
|
|
var altColor = "altColor";
|
|
var rowColor = "rowColor";
|
|
var tableTab = "tableTab";
|
|
var activeTableTab = "activeTableTab";
|
|
</script>
|
|
<noscript>
|
|
<div>JavaScript is disabled on your browser.</div>
|
|
</noscript>
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<div class="topNav"><a name="navbar.top">
|
|
<!-- -->
|
|
</a>
|
|
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
|
|
<a name="navbar.top.firstrow">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="navList" title="Navigation">
|
|
<li><a href="../../overview-summary.html">Overview</a></li>
|
|
<li><a href="package-summary.html">Package</a></li>
|
|
<li class="navBarCell1Rev">Class</li>
|
|
<li><a href="package-tree.html">Tree</a></li>
|
|
<li><a href="../../deprecated-list.html">Deprecated</a></li>
|
|
<li><a href="../../index-all.html">Index</a></li>
|
|
<li><a href="../../help-doc.html">Help</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="subNav">
|
|
<ul class="navList">
|
|
<li><a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><span class="typeNameLink">Prev Class</span></a></li>
|
|
<li><a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace"><span class="typeNameLink">Next Class</span></a></li>
|
|
</ul>
|
|
<ul class="navList">
|
|
<li><a href="../../index.html?openconsensus/trace/Span.Builder.html" target="_top">Frames</a></li>
|
|
<li><a href="Span.Builder.html" target="_top">No Frames</a></li>
|
|
</ul>
|
|
<ul class="navList" id="allclasses_navbar_top">
|
|
<li><a href="../../allclasses-noframe.html">All Classes</a></li>
|
|
</ul>
|
|
<div>
|
|
<script type="text/javascript"><!--
|
|
allClassesLink = document.getElementById("allclasses_navbar_top");
|
|
if(window==top) {
|
|
allClassesLink.style.display = "block";
|
|
}
|
|
else {
|
|
allClassesLink.style.display = "none";
|
|
}
|
|
//-->
|
|
</script>
|
|
</div>
|
|
<div>
|
|
<ul class="subNavList">
|
|
<li>Summary: </li>
|
|
<li>Nested | </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method.summary">Method</a></li>
|
|
</ul>
|
|
<ul class="subNavList">
|
|
<li>Detail: </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method.detail">Method</a></li>
|
|
</ul>
|
|
</div>
|
|
<a name="skip.navbar.top">
|
|
<!-- -->
|
|
</a></div>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<div class="header">
|
|
<div class="subTitle">openconsensus.trace</div>
|
|
<h2 title="Interface Span.Builder" class="title">Interface Span.Builder</h2>
|
|
</div>
|
|
<div class="contentContainer">
|
|
<div class="description">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<dl>
|
|
<dt>Enclosing interface:</dt>
|
|
<dd><a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace">Span</a></dd>
|
|
</dl>
|
|
<hr>
|
|
<br>
|
|
<pre>public static interface <span class="typeNameLabel">Span.Builder</span></pre>
|
|
<div class="block"><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace"><code>Span.Builder</code></a> is used to construct <a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><code>Span</code></a> instances which define arbitrary scopes of
|
|
code that are sampled for distributed tracing as a single atomic unit.
|
|
|
|
<p>This is a simple example where all the work is being done within a single scope and a single
|
|
thread and the Context is automatically propagated:
|
|
|
|
<pre><code>
|
|
class MyClass {
|
|
private static final Tracer tracer = Trace.getTracer();
|
|
void doWork {
|
|
// Create a Span as a child of the current Span.
|
|
Span span = tracer.spanBuilder("MyChildSpan").startSpan();
|
|
try (Scope ss = tracer.withSpan(span)) {
|
|
tracer.getCurrentSpan().addEvent("my event");
|
|
doSomeWork(); // Here the new span is in the current Context, so it can be used
|
|
// implicitly anywhere down the stack.
|
|
} finally {
|
|
span.end();
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
|
|
<p>There might be cases where you do not perform all the work inside one static scope and the
|
|
Context is automatically propagated:
|
|
|
|
<pre><code>
|
|
class MyRpcServerInterceptorListener implements RpcServerInterceptor.Listener {
|
|
private static final Tracer tracer = Trace.getTracer();
|
|
private Span mySpan;
|
|
|
|
public MyRpcInterceptor() {}
|
|
|
|
public void onRequest(String rpcName, Metadata metadata) {
|
|
// Create a Span as a child of the remote Span.
|
|
mySpan = tracer.spanBuilderWithRemoteParent(
|
|
getTraceContextFromMetadata(metadata), rpcName).startSpan();
|
|
}
|
|
|
|
public void onExecuteHandler(ServerCallHandler serverCallHandler) {
|
|
try (Scope ws = tracer.withSpan(mySpan)) {
|
|
tracer.getCurrentSpan().addEvent("Start rpc execution.");
|
|
serverCallHandler.run(); // Here the new span is in the current Context, so it can be
|
|
// used implicitly anywhere down the stack.
|
|
}
|
|
}
|
|
|
|
// Called when the RPC is canceled and guaranteed onComplete will not be called.
|
|
public void onCancel() {
|
|
// IMPORTANT: DO NOT forget to ended the Span here as the work is done.
|
|
mySpan.setStatus(Status.CANCELLED);
|
|
mySpan.end();
|
|
}
|
|
|
|
// Called when the RPC is done and guaranteed onCancel will not be called.
|
|
public void onComplete(RpcStatus rpcStatus) {
|
|
// IMPORTANT: DO NOT forget to ended the Span here as the work is done.
|
|
mySpan.setStatus(rpcStatusToCanonicalTraceStatus(status);
|
|
mySpan.end();
|
|
}
|
|
}
|
|
</code></pre>
|
|
|
|
<p>This is a simple example where all the work is being done within a single scope and the
|
|
Context is manually propagated:
|
|
|
|
<pre><code>
|
|
class MyClass {
|
|
private static final Tracer tracer = Trace.getTracer();
|
|
void DoWork(Span parent) {
|
|
Span childSpan = tracer.spanBuilderWithExplicitParent("MyChildSpan", parent).startSpan();
|
|
childSpan.addEvent("my event");
|
|
try {
|
|
doSomeWork(childSpan); // Manually propagate the new span down the stack.
|
|
} finally {
|
|
// To make sure we end the span even in case of an exception.
|
|
childSpan.end(); // Manually end the span.
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
|
|
<p>If your Java version is less than Java SE 7, see <a href="../../openconsensus/trace/Span.Builder.html#startSpan--"><code>startSpan()</code></a> for usage
|
|
examples.</div>
|
|
<dl>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="summary">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<!-- ========== METHOD SUMMARY =========== -->
|
|
<ul class="blockList">
|
|
<li class="blockList"><a name="method.summary">
|
|
<!-- -->
|
|
</a>
|
|
<h3>Method Summary</h3>
|
|
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
|
|
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd"> </span></span></caption>
|
|
<tr>
|
|
<th class="colFirst" scope="col">Modifier and Type</th>
|
|
<th class="colLast" scope="col">Method and Description</th>
|
|
</tr>
|
|
<tr id="i0" class="altColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#addLink-openconsensus.trace.Link-">addLink</a></span>(<a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace">Link</a> link)</code>
|
|
<div class="block">Adds a <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a> to the newly created <code>Span</code>.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i1" class="rowColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#addLinks-java.util.List-">addLinks</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><<a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace">Link</a>> links)</code>
|
|
<div class="block">Adds a <code>List</code> of <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a>s to the newly created <code>Span</code>.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i2" class="altColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#setRecordEvents-boolean-">setRecordEvents</a></span>(boolean recordEvents)</code>
|
|
<div class="block">Sets the option to record events even if not sampled for the newly created <code>Span</code>.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i3" class="rowColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#setSampler-openconsensus.trace.Sampler-">setSampler</a></span>(<a href="../../openconsensus/trace/Sampler.html" title="class in openconsensus.trace">Sampler</a> sampler)</code>
|
|
<div class="block">Sets the <a href="../../openconsensus/trace/Sampler.html" title="class in openconsensus.trace"><code>Sampler</code></a> to use.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i4" class="altColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#setSpanKind-openconsensus.trace.Span.Kind-">setSpanKind</a></span>(<a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace">Span.Kind</a> spanKind)</code>
|
|
<div class="block">Sets the <a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace"><code>Span.Kind</code></a> for the newly created <code>Span</code>.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i5" class="rowColor">
|
|
<td class="colFirst"><code><a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace">Span</a></code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#startSpan--">startSpan</a></span>()</code>
|
|
<div class="block">Starts a new <a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><code>Span</code></a>.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i6" class="altColor">
|
|
<td class="colFirst"><code><V> V</code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#startSpanAndCall-java.util.concurrent.Callable-">startSpanAndCall</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Callable.html?is-external=true" title="class or interface in java.util.concurrent">Callable</a><V> callable)</code>
|
|
<div class="block">Starts a new span and calls the given <code>Callable</code> with the newly created <code>Span</code> as
|
|
the current <code>Span</code>, and ends the <code>Span</code> after the <code>Callable</code> is called.</div>
|
|
</td>
|
|
</tr>
|
|
<tr id="i7" class="rowColor">
|
|
<td class="colFirst"><code>void</code></td>
|
|
<td class="colLast"><code><span class="memberNameLink"><a href="../../openconsensus/trace/Span.Builder.html#startSpanAndRun-java.lang.Runnable-">startSpanAndRun</a></span>(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html?is-external=true" title="class or interface in java.lang">Runnable</a> runnable)</code>
|
|
<div class="block">Starts a new span and runs the given <code>Runnable</code> with the newly created <code>Span</code> as
|
|
the current <code>Span</code>, and ends the <code>Span</code> after the <code>Runnable</code> is run.</div>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="details">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<!-- ============ METHOD DETAIL ========== -->
|
|
<ul class="blockList">
|
|
<li class="blockList"><a name="method.detail">
|
|
<!-- -->
|
|
</a>
|
|
<h3>Method Detail</h3>
|
|
<a name="setSampler-openconsensus.trace.Sampler-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>setSampler</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a> setSampler(<a href="../../openconsensus/trace/Sampler.html" title="class in openconsensus.trace">Sampler</a> sampler)</pre>
|
|
<div class="block">Sets the <a href="../../openconsensus/trace/Sampler.html" title="class in openconsensus.trace"><code>Sampler</code></a> to use. If not set, the implementation will provide a default.
|
|
|
|
<p>Observe this is used only as a hint for the underlying implementation, which will decide
|
|
whether to sample or not this <code>Span</code>.</div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>sampler</code> - the <code>Sampler</code> to use when determining sampling for a <code>Span</code>.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>this.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="addLink-openconsensus.trace.Link-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>addLink</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a> addLink(<a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace">Link</a> link)</pre>
|
|
<div class="block">Adds a <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a> to the newly created <code>Span</code>.
|
|
|
|
<p>Links are used to link <a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><code>Span</code></a>s in different traces. Used (for example) in batching
|
|
operations, where a single batch handler processes multiple requests from different traces.</div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>link</code> - the <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a> to be added.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>this.</dd>
|
|
<dt><span class="throwsLabel">Throws:</span></dt>
|
|
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</a></code> - if <code>link</code> is <code>null</code>.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="addLinks-java.util.List-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>addLinks</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a> addLinks(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/List.html?is-external=true" title="class or interface in java.util">List</a><<a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace">Link</a>> links)</pre>
|
|
<div class="block">Adds a <code>List</code> of <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a>s to the newly created <code>Span</code>.</div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>links</code> - the <code>List</code> of <a href="../../openconsensus/trace/Link.html" title="class in openconsensus.trace"><code>Link</code></a>s to be added.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>this.</dd>
|
|
<dt><span class="throwsLabel">Throws:</span></dt>
|
|
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</a></code> - if <code>link</code> is <code>null</code>.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
<dt><span class="seeLabel">See Also:</span></dt>
|
|
<dd><a href="../../openconsensus/trace/Span.Builder.html#addLink-openconsensus.trace.Link-"><code>addLink(Link)</code></a></dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="setRecordEvents-boolean-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>setRecordEvents</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a> setRecordEvents(boolean recordEvents)</pre>
|
|
<div class="block">Sets the option to record events even if not sampled for the newly created <code>Span</code>. If
|
|
not called, the implementation will provide a default.</div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>recordEvents</code> - new value determining if this <code>Span</code> should have events recorded.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>this.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="setSpanKind-openconsensus.trace.Span.Kind-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>setSpanKind</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.Builder.html" title="interface in openconsensus.trace">Span.Builder</a> setSpanKind(<a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace">Span.Kind</a> spanKind)</pre>
|
|
<div class="block">Sets the <a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace"><code>Span.Kind</code></a> for the newly created <code>Span</code>. If not called, the
|
|
implementation will provide a default value <a href="../../openconsensus/trace/Span.Kind.html#INTERNAL"><code>Span.Kind.INTERNAL</code></a>.</div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>spanKind</code> - the kind of the newly created <code>Span</code>.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>this.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="startSpan--">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>startSpan</h4>
|
|
<pre><a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace">Span</a> startSpan()</pre>
|
|
<div class="block">Starts a new <a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><code>Span</code></a>.
|
|
|
|
<p>Users <b>must</b> manually call <a href="../../openconsensus/trace/Span.html#end--"><code>Span.end()</code></a> to end this <code>Span</code>.
|
|
|
|
<p>Does not install the newly created <code>Span</code> to the current Context.
|
|
|
|
<p>Example of usage:
|
|
|
|
<pre><code>
|
|
class MyClass {
|
|
private static final Tracer tracer = Trace.getTracer();
|
|
void DoWork(Span parent) {
|
|
Span childSpan = tracer.spanBuilderWithExplicitParent("MyChildSpan", parent).startSpan();
|
|
childSpan.addEvent("my event");
|
|
try {
|
|
doSomeWork(childSpan); // Manually propagate the new span down the stack.
|
|
} finally {
|
|
// To make sure we end the span even in case of an exception.
|
|
childSpan.end(); // Manually end the span.
|
|
}
|
|
}
|
|
}
|
|
</code></pre></div>
|
|
<dl>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>the newly created <code>Span</code>.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="startSpanAndRun-java.lang.Runnable-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>startSpanAndRun</h4>
|
|
<pre>void startSpanAndRun(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html?is-external=true" title="class or interface in java.lang">Runnable</a> runnable)</pre>
|
|
<div class="block">Starts a new span and runs the given <code>Runnable</code> with the newly created <code>Span</code> as
|
|
the current <code>Span</code>, and ends the <code>Span</code> after the <code>Runnable</code> is run.
|
|
|
|
<p>Any error will end up as a <a href="../../openconsensus/trace/Status.html#UNKNOWN"><code>Status.UNKNOWN</code></a>.
|
|
|
|
<pre><code>
|
|
tracer.spanBuilder("MyRunnableSpan").startSpanAndRun(myRunnable);
|
|
</code></pre>
|
|
|
|
<p>It is equivalent with the following code:
|
|
|
|
<pre><code>
|
|
Span span = tracer.spanBuilder("MyRunnableSpan").startSpan();
|
|
Runnable newRunnable = tracer.withSpan(span, myRunnable);
|
|
try {
|
|
newRunnable.run();
|
|
} finally {
|
|
span.end();
|
|
}
|
|
</code></pre></div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>runnable</code> - the <code>Runnable</code> to run in the <code>Span</code>.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
<a name="startSpanAndCall-java.util.concurrent.Callable-">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockListLast">
|
|
<li class="blockList">
|
|
<h4>startSpanAndCall</h4>
|
|
<pre><V> V startSpanAndCall(<a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Callable.html?is-external=true" title="class or interface in java.util.concurrent">Callable</a><V> callable)
|
|
throws <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</a></pre>
|
|
<div class="block">Starts a new span and calls the given <code>Callable</code> with the newly created <code>Span</code> as
|
|
the current <code>Span</code>, and ends the <code>Span</code> after the <code>Callable</code> is called.
|
|
|
|
<p>Any error will end up as a <a href="../../openconsensus/trace/Status.html#UNKNOWN"><code>Status.UNKNOWN</code></a>.
|
|
|
|
<pre><code>
|
|
MyResult myResult = tracer.spanBuilder("MyCallableSpan").startSpanAndCall(myCallable);
|
|
</code></pre>
|
|
|
|
<p>It is equivalent with the following code:
|
|
|
|
<pre><code>
|
|
Span span = tracer.spanBuilder("MyCallableSpan").startSpan();
|
|
Callable<MyResult> newCallable = tracer.withSpan(span, myCallable);
|
|
MyResult myResult = null;
|
|
try {
|
|
myResult = newCallable.call();
|
|
} finally {
|
|
span.end();
|
|
}
|
|
);
|
|
</code></pre></div>
|
|
<dl>
|
|
<dt><span class="paramLabel">Type Parameters:</span></dt>
|
|
<dd><code>V</code> - the result type of method call.</dd>
|
|
<dt><span class="paramLabel">Parameters:</span></dt>
|
|
<dd><code>callable</code> - the <code>Callable</code> to run in the <code>Span</code>.</dd>
|
|
<dt><span class="returnLabel">Returns:</span></dt>
|
|
<dd>the result of the <code>Callable#call</code>.</dd>
|
|
<dt><span class="throwsLabel">Throws:</span></dt>
|
|
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html?is-external=true" title="class or interface in java.lang">Exception</a></code> - if the <code>Callable</code> throws an exception.</dd>
|
|
<dt><span class="simpleTagLabel">Since:</span></dt>
|
|
<dd>0.1.0</dd>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
|
<div class="bottomNav"><a name="navbar.bottom">
|
|
<!-- -->
|
|
</a>
|
|
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
|
|
<a name="navbar.bottom.firstrow">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="navList" title="Navigation">
|
|
<li><a href="../../overview-summary.html">Overview</a></li>
|
|
<li><a href="package-summary.html">Package</a></li>
|
|
<li class="navBarCell1Rev">Class</li>
|
|
<li><a href="package-tree.html">Tree</a></li>
|
|
<li><a href="../../deprecated-list.html">Deprecated</a></li>
|
|
<li><a href="../../index-all.html">Index</a></li>
|
|
<li><a href="../../help-doc.html">Help</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="subNav">
|
|
<ul class="navList">
|
|
<li><a href="../../openconsensus/trace/Span.html" title="interface in openconsensus.trace"><span class="typeNameLink">Prev Class</span></a></li>
|
|
<li><a href="../../openconsensus/trace/Span.Kind.html" title="enum in openconsensus.trace"><span class="typeNameLink">Next Class</span></a></li>
|
|
</ul>
|
|
<ul class="navList">
|
|
<li><a href="../../index.html?openconsensus/trace/Span.Builder.html" target="_top">Frames</a></li>
|
|
<li><a href="Span.Builder.html" target="_top">No Frames</a></li>
|
|
</ul>
|
|
<ul class="navList" id="allclasses_navbar_bottom">
|
|
<li><a href="../../allclasses-noframe.html">All Classes</a></li>
|
|
</ul>
|
|
<div>
|
|
<script type="text/javascript"><!--
|
|
allClassesLink = document.getElementById("allclasses_navbar_bottom");
|
|
if(window==top) {
|
|
allClassesLink.style.display = "block";
|
|
}
|
|
else {
|
|
allClassesLink.style.display = "none";
|
|
}
|
|
//-->
|
|
</script>
|
|
</div>
|
|
<div>
|
|
<ul class="subNavList">
|
|
<li>Summary: </li>
|
|
<li>Nested | </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method.summary">Method</a></li>
|
|
</ul>
|
|
<ul class="subNavList">
|
|
<li>Detail: </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method.detail">Method</a></li>
|
|
</ul>
|
|
</div>
|
|
<a name="skip.navbar.bottom">
|
|
<!-- -->
|
|
</a></div>
|
|
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
|
</body>
|
|
</html>
|