1

我正嘗試在Go中記錄錯誤報告給Stackdriver錯誤報告。在錯誤報告的第一頁上,聲明「通過將應用程序錯誤記錄到Google Stackdriver Logging或...」(https://cloud.google.com/error-reporting/docs/),可以實現應用程序的報告錯誤。我如何使用Go客戶端庫來做到這一點?如何將錯誤記錄到Stackdriver錯誤報告通過Stackdriver記錄

記錄庫提供的Entry構造是這樣的:

github.com/GoogleCloudPlatform/.../logging.go#L412

type Entry struct { 
    Timestamp time.Time 
    Severity Severity 
    Payload interface{} 
    Labels map[string]string 
    InsertID string 
    HTTPRequest *HTTPRequest 
    Operation *logpb.LogEntryOperation 
    LogName string 
    Resource *mrpb.MonitoredResource 
} 

我需要元帥this JSON結構到有效載荷?或者我可以插入stacktrace作爲字符串?

回答

2

a dedicated Go package,應該幫助你實現這一點。 import "cloud.google.com/go/errors"

您可以將其配置爲通過Stackdriver Logging報告錯誤,並且它將負責發送正確的日誌結構。

1

docs

// Payload must be either a string or something that 
// marshals via the encoding/json package to a JSON object 
// (and not any other type of JSON value). 

看起來像一個字符串是要走的路將堆棧跟蹤。