<!-- Thanks for sending a PR! Before submitting: 1. If this is your first PR, check out our contribution guide here https://docs.prylabs.network/docs/contribute/contribution-guidelines You will then need to sign our Contributor License Agreement (CLA), which will show up as a comment from a bot in this pull request after you open it. We cannot review code without a signed CLA. 2. Please file an associated tracking issue if this pull request is non-trivial and requires context for our team to understand. All features and most bug fixes should have an associated issue with a design discussed and decided upon. Small bug fixes and documentation improvements don't need issues. 3. New features and bug fixes must have tests. Documentation may need to be updated. If you're unsure what to update, send the PR, and we'll discuss in review. 4. Note that PRs updating dependencies and new Go versions are not accepted. Please file an issue instead. 5. A changelog entry is required for user facing issues. --> **What type of PR is this?** > Bug fix **What does this PR do? Why is it needed?** It's just a simple fix. I was looking at how prysm uses OpenTelemetry and I noticed it. **Which issues(s) does this PR fix?** **Other notes for review** **Acknowledgements** - [x] I have read [CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md). - [x] I have included a uniquely named [changelog fragment file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd). - [x] I have added a description with sufficient context for reviewers to understand this PR. - [x] I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).
How to view collected traces
Prerequisites:
Using Jaeger
Tracing is disabled by default, to enable, you can use the option --enable-tracing.
Jaeger endpoint can be configured with the --tracing-endpoint option and defaults to http://127.0.0.1:14268.
Run Jaeger:
$ 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
This will start the UI at http://localhost:16686
Using the Go tool
Tracing is disabled by default, to enable, you can use the option --enable-tracing.
Run the application using the --pprof option to enable pprof (for trace collection).
To collect traces for 5 seconds:
$ curl http://localhost:6060/debug/pprof/trace?seconds=5 -o trace.out
View the trace with:
$ go tool trace trace.out
2018/05/04 10:39:59 Parsing trace...
2018/05/04 10:39:59 Splitting trace...
2018/05/04 10:39:59 Opening browser. Trace viewer is listening on http://127.0.0.1:51803
How to collect additional traces
We use the OpenCensus library to create traces. To trace the execution of a p2p message through the system, we must define spans 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 struct to create a span:
var msg p2p.Message
var mySpan *trace.Span
msg.Ctx, mySpan = trace.StartSpan(msg.Ctx, "myOperation")
myOperation()
mySpan.End()
Another example on how to define spans can be found here: https://godoc.org/go.opencensus.io/trace#example-StartSpan