errorreporting

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package errorreporting is a Google Stackdriver Error Reporting library.

This package is still experimental and subject to change.

See https://cloud.google.com/error-reporting/ for more information.

Example
package main

import (
	"errors"
	"log"

	"cloud.google.com/go/errorreporting"
	"golang.org/x/net/context"
)

func main() {
	// Create the client.
	ctx := context.Background()
	ec, err := errorreporting.NewClient(ctx, "my-gcp-project", errorreporting.Config{
		ServiceName:    "myservice",
		ServiceVersion: "v1.0",
	})
	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")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 closes any resources held by the client. Close should be called when the client is no longer needed. It need not be called at program exit.

func (*Client) Flush added in v0.15.0

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 report the error via the (*Client).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 Client.OnError.

func (*Client) ReportSync added in v0.15.0

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

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

type Config added in v0.15.0

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 added in v0.15.0

type Entry struct {
	Error error
	Req   *http.Request // if error is associated with a request.
	Stack []byte        // if user does not provide a stack trace, runtime.Stack will be called
}

Entry holds information about the reported error.

Directories

Path Synopsis
Package errorreporting is an auto-generated package for the Stackdriver Error Reporting API.
Package errorreporting is an auto-generated package for the Stackdriver Error Reporting API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL