2016-11-10 49 views
1

以下是使用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) 

我缺少什麼?

回答