opencensus-go-exporter-stackdriver icon indicating copy to clipboard operation
opencensus-go-exporter-stackdriver copied to clipboard

No traces appear in Stackdriver, no errors in log output

Open bmhatfield opened this issue 6 years ago • 1 comments

Hi,

I am trying to get Stackdriver tracing working, however... nothing happens. I expect to see traces show up in the Stackdriver UI.

I'm using the instructions from Setting Up Stackdriver Tracing and running a simple local test. I have full access to this test project.

The slightly modified sample code looks like this:

package main

import (
	"log"
	"net/http"

	"contrib.go.opencensus.io/exporter/stackdriver"
	"contrib.go.opencensus.io/exporter/stackdriver/propagation"
	"go.opencensus.io/plugin/ochttp"
	"go.opencensus.io/trace"
)

func main() {
	// Create and register a OpenCensus Stackdriver Trace exporter.
	exporter, err := stackdriver.NewExporter(stackdriver.Options{
		ProjectID: "<A-CORRECT-PROJECT-ID>",
		Location:  "brians-mac",
		OnError: func(err error) {
			log.Println("Error: ", err)
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	trace.RegisterExporter(exporter)

	client := &http.Client{
		Transport: &ochttp.Transport{
			// Use Google Cloud propagation format.
			Propagation: &propagation.HTTPFormat{},
		},
	}

	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		req, _ := http.NewRequest("GET", "https://metadata/users", nil)

		// The trace ID from the incoming request will be
		// propagated to the outgoing request.
		req = req.WithContext(r.Context())

		// The outgoing request will be traced with r's trace ID.
		if _, err := client.Do(req); err != nil {
			log.Println(err)
		}
	})
	http.Handle("/foo", ochttp.WithRouteTag(handler, "/foo"))

	log.Println("Starting handler on 6060...")
	log.Fatal(http.ListenAndServe(":6060", &ochttp.Handler{}))
}

However, nothing happens at all. The only output in the log is because https://metadata/users doesn't exist on my mac, but that should not result in no spans at all sent to Stackdriver, right?

I have Google Application credentials configured via environment variable; however, GCP clients also generally "just work" without that step because I had GCloud enable service-account style access to my account.

I don't know what to troubleshoot, because I get no logged errors nor traces displayed in Stackdriver.

Help, pretty please! Thank you!

bmhatfield avatar Apr 02 '19 21:04 bmhatfield

After reading this issue https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/issues/100 which indicated that the examples don't work, and suggested that folks try this documentation, I was able to add the following line:

trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) and then traces appeared in Stackdriver.

This is my first foray into tracing and I didn't have enough context to know a priori that my traces will be dropped due to sampling. I'd like to add on to #100's concern that the examples are insufficient.

Leaving this ticket open as a documentation ticket.

bmhatfield avatar Apr 02 '19 21:04 bmhatfield