Once we have our application credentials all set up; we are off to the races to write our first trace that will be captured by our APM:
- First, we instantiate the necessary packages and set a server host/port constant:
package mainimport ( "context" "fmt" "log" "net/http" "os" "time" "contrib.go.opencensus.io/exporter/stackdriver" "go.opencensus.io/trace")const server = ":1234"
- Next, in our init() function, we set up our StackDriver exporter and register our tracer to sample every web request that comes in. In production, we should probably sample fewer requests, as sampling adds additional latency to our requests:
func init() { exporter, err := stackdriver.NewExporter(stackdriver.Options{ ProjectID: os.Getenv("GOOGLE_CLOUD_PROJECT"), ...