英文:
Datastore calls in Trace Golang
问题
当我使用go111时,我可以追踪到我所有的Datastore调用(类似于下面的图片)。但是当我升级到go115并开始使用cloud.google.com/go/datastore时,我完全失去了这些信息。我尝试在我的主函数中设置遥测:
projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
exporter, err := texporter.NewExporter(texporter.WithProjectID(projectID))
if err != nil {
log.Fatalf(bgCtx, "texporter.NewExporter of '%v': %v", projectID, err)
}
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
defer tp.ForceFlush(bgCtx)
otel.SetTracerProvider(tp)
但是这并没有起作用。我是否漏掉了一些东西来告诉datastore库导出这些调用?
谢谢!
英文:
when I was using go111, I had traces of all my Datastore calls (similar to image below). But as soon as I upgraded to go115 and started using cloud.google.com/go/datastore, I lost this information completely. I tried to set up telemetry by adding in my main:
projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
exporter, err := texporter.NewExporter(texporter.WithProjectID(projectID))
if err != nil {
log.Fatalf(bgCtx, "texporter.NewExporter of '%v': %v", projectID, err)
}
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exporter))
defer tp.ForceFlush(bgCtx)
otel.SetTracerProvider(tp)
But this didn't work. Am I missing anything to tell the datastore library to export those calls?
Thank you!
答案1
得分: 0
我终于找到了https://github.com/GoogleCloudPlatform/golang-samples/blob/master/trace/trace_quickstart/main.go,并意识到我漏掉了以下内容:
trace.RegisterExporter(exporter)
这解决了我的问题。然后我还在本地添加了以下内容:
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
以确保跟踪所有请求:
httpHandler := &ochttp.Handler{
// 使用Google Cloud传播格式。
Propagation: &propagation.HTTPFormat{},
}
if err := http.ListenAndServe(":"+port, httpHandler); err != nil
英文:
I finally found https://github.com/GoogleCloudPlatform/golang-samples/blob/master/trace/trace_quickstart/main.go
and realized I was missing the following:
trace.RegisterExporter(exporter)
This solved my problem. Then I also added the following on localhost
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
To make sure all requests are traced:
httpHandler := &ochttp.Handler{
// Use the Google Cloud propagation format.
Propagation: &propagation.HTTPFormat{},
}
if err := http.ListenAndServe(":"+port, httpHandler); err != nil {
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论