github.com/prysmaticlabs/prysm@v1.4.4/shared/tracing/README.md (about) 1 #### How to view collected traces 2 3 ##### Prerequisites: 4 - [Docker](https://www.docker.com/get-started) (For Jaeger image) 5 - [Go](https://golang.org/) 1.11+ (For execution traces collected by pprof) 6 7 ##### Using Jaeger 8 Tracing is disabled by default, to enable, you can use the option `--enable-tracing`. 9 Jaeger endpoint can be configured with the `--tracing-endpoint` option and defaults to `http://127.0.0.1:14268`. 10 11 Run Jaeger: 12 ```sh 13 $ docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:1.6 14 ``` 15 16 This will start the UI at `http://localhost:16686` 17 18 ##### Using the Go tool 19 Tracing is disabled by default, to enable, you can use the option `--enable-tracing`. 20 Run the application using the `--pprof` option to enable pprof (for trace collection). 21 22 To collect traces for 5 seconds: 23 ```sh 24 $ curl http://localhost:6060/debug/pprof/trace?seconds=5 -o trace.out 25 ``` 26 27 View the trace with: 28 ```sh 29 $ go tool trace trace.out 30 2018/05/04 10:39:59 Parsing trace... 31 2018/05/04 10:39:59 Splitting trace... 32 2018/05/04 10:39:59 Opening browser. Trace viewer is listening on http://127.0.0.1:51803 33 ``` 34 35 #### How to collect additional traces 36 37 We use the OpenCensus library to create traces. To trace the execution of a p2p 38 message through the system, we must define [spans](https://godoc.org/go.opencensus.io/trace#Span) around the code that handles the message. To correlate the trace with other spans defined for the same message, use the context passed inside the [Message](https://godoc.org/github.com/prysmaticlabs/prysm/shared/deprecated-p2p#Message) struct to create a span: 39 40 ```go 41 var msg p2p.Message 42 var mySpan *trace.Span 43 msg.Ctx, mySpan = trace.StartSpan(msg.Ctx, "myOperation") 44 myOperation() 45 mySpan.End() 46 ``` 47 48 Another example on how to define spans can be found here: https://godoc.org/go.opencensus.io/trace#example-StartSpan