Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

No traces appear in Stackdriver, no errors in log output #123

Open
bmhatfield opened this issue Apr 2, 2019 · 1 comment
Open

No traces appear in Stackdriver, no errors in log output #123

bmhatfield opened this issue Apr 2, 2019 · 1 comment

Comments

@bmhatfield
Copy link

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
Copy link
Author

After reading this issue #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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant