internal/telemetry/export/ocagent: add traces to tutorial

This change updates the metrics tutorial to include example code for
exporting traces from go tools.

Change-Id: Ie1d3c373ed4308ef0160f6389b74c642b348bed6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225061
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Nathan Dias 2020-03-24 00:02:44 -05:00 committed by Emmanuel Odeke
parent dbf25ea225
commit 5c746ccfa2
1 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# Exporting Metrics with OpenCensus and Prometheus
# Exporting Metrics and Traces with OpenCensus, Zipkin, and Prometheus
This tutorial provides a minimum example to verify that metrics can be exported to OpenCensus from Go tools.
This tutorial provides a minimum example to verify that metrics and traces
can be exported to OpenCensus from Go tools.
## Setting up oragent
@ -23,7 +24,7 @@ Starting oragent_prometheus_1 ... done
4. To shut down oragent, hit Ctrl+C in the terminal.
5. You can also start oragent in detached mode by running `docker-compose up -d`. To stop oragent while detached, run `docker-compose down`.
## Exporting Metrics
## Exporting Metrics and Traces
1. Clone the [tools](https://golang.org/x/tools) subrepository.
1. Inside `internal`, create a file named `main.go` with the following contents:
```go
@ -81,7 +82,9 @@ func main() {
for {
sleep := randomSleep()
_, end := event.StartSpan(ctx, "main.randomSleep()")
time.Sleep(time.Duration(sleep) * time.Millisecond)
end()
event.Record(ctx, mLatency.Of(float64(sleep)))
fmt.Println("Latency: ", float64(sleep))
@ -132,3 +135,5 @@ promdemo_latencyDistribution_sum{vendor="otc"} 1641
promdemo_latencyDistribution_count{vendor="otc"} 15
```
5. After a few more seconds, Prometheus should start displaying your new metrics. You can view the distribution at http://localhost:9445/graph?g0.range_input=5m&g0.stacked=1&g0.expr=rate(oragent_latencyDistribution_bucket%5B5m%5D)&g0.tab=0.
6. Zipkin should also start displaying traces. You can view them at http://localhost:9444/zipkin/?limit=10&lookback=300000&serviceName=go-tools-test.