[英]Stackdriver Trace with Google App Engine Go 1.11 runtime
I would like to get Stackdriver Trace to work on the new Go 1.11 standard runtime on Google App Engine . 我想让Stackdriver Trace 在Google App Engine的新Go 1.11标准运行时上运行 。 This is all still labeled as beta so maybe it just doesn't quite work yet. 这些都仍被标记为beta,因此也许它还不能完全正常工作。 However, I followed the step-by-step directions and it isn't working. 但是,我按照分步说明进行操作 ,但是它不起作用。 I deployed the code (almost) exactly as it is listed in the link and my traces are flat (ie doesn't include the waterfall view I would expect with the incoming request at the top and the outgoing request nested underneath). 我(几乎)完全按照链接中列出的方式部署了代码,并且跟踪是平坦的(即,不包括我期望的瀑布视图,传入的请求位于顶部,传出的请求嵌套在下方)。
Sample code 样例代码
package main
import (
"fmt"
"log"
"net/http"
"os"
"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: os.Getenv("GOOGLE_CLOUD_PROJECT"),
})
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://www.google.com/robots.txt", 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.
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Fprint(w, "OK")
})
http.Handle("/foo", handler)
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), &ochttp.Handler{}))
}
As written in the reply comment in the original question, can you try the config for sampling?: trace.AlwaysSample()
如原始问题的回复注释中所述,您可以尝试进行采样配置吗?: trace.AlwaysSample()
You can find some comments about sampling rate in OpenCensus Trace documentation and godoc of OpenCensus Trace library : 您可以在OpenCensus Trace文档和OpenCensus Trace库的godoc中找到有关采样率的一些注释:
By default, traces will be sampled relatively rarely. 默认情况下,跟踪将相对很少地进行采样。 To change the sampling frequency for your entire program, call ApplyConfig. 若要更改整个程序的采样频率,请调用ApplyConfig。 Use a ProbabilitySampler to sample a subset of traces, or use AlwaysSample to collect a trace on every run: 使用ProbabilitySampler采样跟踪的子集,或使用AlwaysSample在每次运行时收集跟踪:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.