Being able to collect traces is integral to implementing tracing in your distributed system. If we don't aggregate these traces somewhere, we won't be able to make sense of them at scale. There are three methods with which we can collect trace data:
- Manually invoking the tracing of the data by calling trace.Start and trace.Stop
- Using the test flag -trace=[OUTPUTFILE]
- Instrumenting the runtime/trace package
In order to understand how to implement tracing around your code, let's take a look at a simple example program:
- We first instantiate our package and import the necessary packages:
package mainimport ( "os" "runtime/trace")
- We then invoke our main function. We write the trace output to a file, trace.out ...