Back to / errorreporting

Package errorreporting

Latest Go to latest

The latest major version is .

Published: Sep 15, 2020 | License: Apache-2.0 | Module:


Package errorreporting is a Google Stackdriver Error Reporting library.

Any provided stacktraces must match the format produced by or as per for language specific stacktrace formats.

This package is still experimental and subject to change.

See for more information.



package main

import (


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 {
			Error: err,

func doSomething() error {
	return errors.New("something went wrong")



type Client

type Client struct {
	// contains filtered or unexported fields

Client represents a Google Cloud Error Reporting client.

func NewClient

func NewClient(ctx context.Context, projectID string, cfg Config, opts ...option.ClientOption) (*Client, error)

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.

func (*Client) Close

func (c *Client) Close() error

Close calls Flush, then closes any resources held by the client. Close should be called when the client is no longer needed.

func (*Client) Flush

func (c *Client) Flush()

Flush blocks until all currently buffered error reports are sent.

If any errors occurred since the last call to Flush, or the creation of the client if this is the first call, then Flush reports the error via the Config.OnError handler.

func (*Client) Report

func (c *Client) Report(e Entry)

Report writes an error report. It doesn't block. Errors in writing the error report can be handled via Config.OnError.

func (*Client) ReportSync

func (c *Client) ReportSync(ctx context.Context, e Entry) error

ReportSync writes an error report. It blocks until the entry is written.

type Config

type Config struct {
	// ServiceName identifies the running program and is included in the error reports.
	// Optional.
	ServiceName string

	// ServiceVersion identifies the version of the running program and is
	// included in the error reports.
	// Optional.
	ServiceVersion string

	// OnError is the function to call if any background
	// tasks errored. By default, errors are logged.
	OnError func(err error)

Config is additional configuration for Client.

type Entry

type Entry struct {
	Error error
	Req   *http.Request // if error is associated with a request.
	User  string        // an identifier for the user affected by the error

	// Stack specifies the stacktrace and call sequence correlated with
	// the error. Stack's content must match the format specified by
	// or at least for Go programs, it must match the format produced
	// by
	// If Stack is blank, the result of runtime.Stack will be used instead.
	Stack []byte

Entry holds information about the reported error.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier