【问题标题】:minimal stackdriver trace client usage failing最小的堆栈驱动程序跟踪客户端使用失败
【发布时间】:2017-03-25 00:25:01
【问题描述】:

这是使用 stackdriver trace go 客户端包的缩图。

看起来这个简单的例子应该可以工作,但它会产生错误。

package main

import (
    "context"
    "flag"
    "log"
    "net/http"

    "cloud.google.com/go/trace"
    "github.com/davecgh/go-spew/spew"
    "google.golang.org/api/option"
)

var (
    projectID         = flag.String("projectID", "", "projcect id")
    serviceAccountKey = flag.String("serviceAccountKey", "", "path to serviceacount json")
)

func main() {
    flag.Parse()
    mux := http.NewServeMux()
    log.Fatalln(http.ListenAndServe(":9000", Trace(*projectID, *serviceAccountKey, mux)))
}

func Trace(projectID string, keyPath string, h http.Handler) http.HandlerFunc {
    client, err := trace.NewClient(context.Background(), projectID, option.WithServiceAccountFile(keyPath))
    if err != nil {
        panic(err)
    }
    return func(w http.ResponseWriter, r *http.Request) {
        s := client.SpanFromRequest(r)
        defer func() { err := s.FinishWait(); spew.Dump(err) }()
        h.ServeHTTP(w, r)
    }
}

我将其运行为:

$ teststackdrivertrace -projectID ${GCLOUD_PROJECT_ID} -serviceAccountKey ${PATH_TO_SERVICEACCOUNT_JSON}

并卷曲它产生:

$ curl -s --header "X-Cloud-Trace-Context: 205445aa7843bc8bf206b120001000/0;o=1" localhost:9000

$ (*googleapi.Error)(0xc4203a2c80)(googleapi: Error 400: Request contains an invalid argument., badRequest)

我错过了什么?

【问题讨论】:

    标签: google-cloud-platform google-cloud-trace


    【解决方案1】:

    我的 traceId 的长度是 30 个字节而不是 32 个。我从 https://cloud.google.com/trace/docs/faq 中获取了示例 curl,它也只有 30 个字节。

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 2017-08-26
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多