stackdriver

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 6 Imported by: 0

README

Stackdriver error handler

CircleCI Go Report Card GolangCI 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.

Jump to

Keyboard shortcuts

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