Skip to content

Commit c7c147c

Browse files
committed
doc: update go1.11.html with user annotation API additions
Change-Id: I357eea0efb04392e1a4671d20190a2052bf548de Reviewed-on: https://go-review.googlesource.com/124706 Reviewed-by: Andrew Bonventre <[email protected]>
1 parent 96b5f6d commit c7c147c

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

doc/go1.11.html

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,58 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
666666
<dl id="runtime/trace"><dt><a href="/pkg/runtime/trace/">runtime/trace</a></dt>
667667
<dd>
668668
<p><!-- CL 63274 -->
669-
TODO: <a href="https://golang.org/cl/63274">https://golang.org/cl/63274</a>: user annotation API
669+
This release adds a new user annotation API.
670+
It introduces three basic building blocks: Log, Span, and Task.
671+
</p>
672+
673+
<p>
674+
Log is for basic logging. When called, the message will be recorded
675+
to the trace along with timestamp, goroutine id, and stack info.
676+
</p>
677+
678+
<pre>trace.Log(ctx, messageType message)</pre>
679+
680+
<p>
681+
Span can be thought as an extension of log to record interesting
682+
time interval during a goroutine's execution. A span is local to a
683+
goroutine by definition.
684+
</p>
685+
686+
<pre>
687+
trace.WithSpan(ctx, "doVeryExpensiveOp", func(ctx context) {
688+
/* do something very expensive */
689+
})</pre>
690+
691+
<p>
692+
Task is higher-level concept that aids tracing of complex operations
693+
that encompass multiple goroutines or are asynchronous.
694+
For example, an RPC request, a HTTP request, a file write, or a
695+
batch job can be traced with a Task.
696+
</p>
697+
698+
<p>
699+
Note we chose to design the API around context.Context so it allows
700+
easier integration with other tracing tools, often designed around
701+
context.Context as well. Log and WithSpan APIs recognize the task
702+
information embedded in the context and record it in the trace as
703+
well. That allows the Go execution tracer to associate and group
704+
the spans and log messages based on the task information.
705+
</p>
706+
707+
<p>
708+
In order to create a Task,
709+
</p>
710+
711+
<pre>ctx, end := trace.NewContext(ctx, "myTask")
712+
defer end()</pre>
713+
714+
<p>
715+
The Go execution tracer measures the time between the task created
716+
and the task ended for the task latency.
717+
</p>
718+
719+
<p>
720+
More discussion history is in <a href="https://golang.org/cl/59572">golang.org/cl/59572</a>.
670721
</p>
671722

672723
</dl><!-- runtime/trace -->

0 commit comments

Comments
 (0)