stackdriver

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 7 Imported by: 0

README

Stackdriver error handler

GitHub Workflow Status Codecov Go Report Card GolangCI Go Version GoDoc

Error handler integration for Stackdriver

Installation

go get emperror.dev/handler/stackdriver

Usage

package main

import (
	"context"

	"cloud.google.com/go/errorreporting"
	"emperror.dev/handler/stackdriver"
	"golang.org/x/oauth2/google"
	"google.golang.org/api/option"
)

func main() {
	// Create the client
	ctx := context.Background()
	client, err := errorreporting.NewClient(
		ctx,
		"my-gcp-project",
		errorreporting.Config{
			ServiceName:    "myservice",
			ServiceVersion: "v1.0",
		},
		option.WithCredentialsFile("path/to/google_credentials.json"),
	)
	if err != nil {
		// TODO: handle error
	}
	defer client.Close()

	// Create the handler
	_ = stackdriver.New(client)
}

Development

When all coding and testing is done, please run the test suite:

$ make check

License

The MIT License (MIT). Please see License File for more information.

Documentation

Overview

Package stackdriver provides an error handler integration for Stackdriver.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler sends errors to Stackdriver.

func New

func New(client *errorreporting.Client) *Handler

New returns a new Handler.

Example
package main

import (
	"context"

	"cloud.google.com/go/errorreporting"

	"emperror.dev/handler/stackdriver"
)

func main() {
	// Create the client
	ctx := context.Background()
	client, err := errorreporting.NewClient(ctx, "my-gcp-project", errorreporting.Config{
		ServiceName:    "myservice",
		ServiceVersion: "v1.0",
	})
	if err != nil {
		// TODO: handle error
		return
	}
	defer client.Close()

	// Create the handler
	_ = stackdriver.New(client)

}
Output:

Example (WithCredentials)
package main

import (
	"context"

	"cloud.google.com/go/errorreporting"
	"golang.org/x/oauth2/google"
	"google.golang.org/api/option"

	"emperror.dev/handler/stackdriver"
)

func main() {
	// Create the client
	ctx := context.Background()
	client, err := errorreporting.NewClient(
		ctx,
		"my-gcp-project",
		errorreporting.Config{
			ServiceName:    "myservice",
			ServiceVersion: "v1.0",
		},
		option.WithCredentials(&google.Credentials{}),
		// OR
		// option.WithCredentialsFile("path/to/google_credentials.json"),
	)
	if err != nil {
		// TODO: handle error
		return
	}
	defer client.Close()

	// Create the handler
	_ = stackdriver.New(client)

}
Output:

func (*Handler) Close

func (h *Handler) Close() error

Close calls Close on the underlying client.

func (*Handler) Handle

func (h *Handler) Handle(err error)

Handle sends an error to Stackdriver.

func (*Handler) HandleContext added in v0.3.0

func (h *Handler) HandleContext(_ context.Context, err error)

HandleContext sends an error to Stackdriver.

Jump to

Keyboard shortcuts

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