Involved Source Files
Package errorreporting is a Google Stackdriver Error Reporting library.
Any provided stacktraces must match the format produced by https://golang.org/pkg/runtime/#Stack
or as per https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report#ReportedErrorEvent
for language specific stacktrace formats.
This package is still experimental and subject to change.
See https://cloud.google.com/error-reporting/ for more information.
Code Examples
package main
import (
"context"
"errors"
"log"
"cloud.google.com/go/errorreporting"
)
func main() {
// Create the client.
ctx := context.Background()
ec, err := errorreporting.NewClient(ctx, "my-gcp-project", errorreporting.Config{
ServiceName: "myservice",
ServiceVersion: "v1.0",
})
if err != nil {
// TODO: handle error
}
defer func() {
if err := ec.Close(); err != nil {
log.Printf("failed to report errors to Stackdriver: %v", err)
}
}()
// Report an error.
err = doSomething()
if err != nil {
ec.Report(errorreporting.Entry{
Error: err,
})
}
}
func doSomething() error {
return errors.New("something went wrong")
}
Package-Level Type Names (total 4, in which 3 are exported)
Config is additional configuration for Client.
OnError is the function to call if any background
tasks errored. By default, errors are logged.
ServiceName identifies the running program and is included in the error reports.
Optional.
ServiceVersion identifies the version of the running program and is
included in the error reports.
Optional.
func NewClient(ctx context.Context, projectID string, cfg Config, opts ...option.ClientOption) (*Client, error)
Entry holds information about the reported error.
Errorerror
// if error is associated with a request.
Stack specifies the stacktrace and call sequence correlated with
the error. Stack's content must match the format specified by
https://cloud.google.com/error-reporting/reference/rest/v1beta1/projects.events/report#ReportedErrorEvent.message
or at least for Go programs, it must match the format produced
by https://golang.org/pkg/runtime/debug/#Stack.
If Stack is blank, the result of runtime.Stack will be used instead.
// an identifier for the user affected by the error
func (*Client).Report(e Entry)
func (*Client).ReportSync(ctx context.Context, e Entry) error
func golang.org/x/pkgsite/internal/middleware.Reporter.Report(Entry)
func (*Client).newRequest(e Entry) *pb.ReportErrorEventRequest
Package-Level Functions (total 2, in which 1 are exported)
NewClient returns a new error reporting client. Generally you will want
to create a client on program initialization and use it through the lifetime
of the process.
chopStack trims a stack trace so that the function which panics or calls
Report is first.
Package-Level Variables (only one, which is unexported)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.