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). 

看起来像一个字符串是要走的路将堆栈跟踪。