trace/trace_quickstart: AlwaysSample and PORT
@@ -38,6 +38,16 @@ func main() {
}
trace.RegisterExporter(exporter)
+ // By default, traces will be sampled relatively rarely. To change the
+ // sampling frequency for your entire program, call ApplyConfig. Use a
+ // ProbabilitySampler to sample a subset of traces, or use AlwaysSample to
+ // collect a trace on every run.
+ //
+ // Be careful about using trace.AlwaysSample in a production application
+ // with significant traffic: a new trace will be started and exported for
+ // every request.
+ trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
+
client := &http.Client{
Transport: &ochttp.Transport{
// Use Google Cloud propagation format.
@@ -46,7 +56,7 @@ func main() {
}
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- req, _ := http.NewRequest("GET", "https://metadata/users", nil)
+ req, _ := http.NewRequest("GET", "https://www.google.com", nil)
// The trace ID from the incoming request will be
// propagated to the outgoing request.
@@ -61,7 +71,13 @@ func main() {
resp.Body.Close()
})
http.Handle("/foo", handler)
- log.Fatal(http.ListenAndServe(":6060", &ochttp.Handler{}))
+
+ port := os.Getenv("PORT")
+ if port == "" {
+ port = ":8080"
+ }
+ log.Printf("Listening on localhost%s", port)
+ log.Fatal(http.ListenAndServe("localhost"+port, &ochttp.Handler{}))
}
// [END trace_setup_go_quickstart]
