在Trace Golang中的Datastore调用

huangapple go评论85阅读模式
英文:

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!

在Trace Golang中的Datastore调用

答案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 {

huangapple
  • 本文由 发表于 2021年9月16日 07:50:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/69200907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定