trail

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package trail integrates trace errors with GRPC

Example server that sends the GRPC error and attaches metadata:

func (s *server) Echo(ctx context.Context, message *gw.StringMessage) (*gw.StringMessage, error) {
    trace.SetDebug(true) // to tell trace to start attaching metadata
    // Send sends metadata via grpc header and converts error to GRPC compatible one
    return nil, trail.Send(ctx, trace.AccessDenied("missing authorization"))
}

Example client reading error and trace debug info:

 var header metadata.MD
	r, err := c.Echo(context.Background(), &gw.StringMessage{Value: message}, grpc.Header(&header))
	if err != nil {
     // FromGRPC reads error, converts it back to trace error and attaches debug metadata
     // like stack trace of the error origin back to the error
		err = trail.FromGRPC(err, header)

/ // this line will log original trace of the error

	log.Errorf("error saying echo: %v", trace.DebugReport(err))
	return
}

Index

Constants

View Source
const DebugReportMetadata = "trace-debug-report"

DebugReportMetadata is a key in metadata holding debug information about the error - stack traces and original error

Variables

This section is empty.

Functions

func DecodeDebugInfo

func DecodeDebugInfo(err error, meta metadata.MD) error

DecodeDebugInfo decodes debug information about error from the metadata and returns error with enriched metadata about it

func FromGRPC

func FromGRPC(err error, args ...interface{}) error

FromGRPC converts error from GRPC error back to trace.Error Debug information will be retrieved from the metadata if specified in args

func Send

func Send(ctx context.Context, err error) error

Send is a high level function that: * converts error to GRPC error * attaches debug metadata to existing metadata if possible * sends the header to GRPC

func SetDebugInfo

func SetDebugInfo(err error, meta metadata.MD)

SetDebugInfo adds debug metadata about error (traces, original error) to request metadata as encoded property

func ToGRPC

func ToGRPC(err error) error

ToGRPC converts error to GRPC-compatible error

Types

This section is empty.

Jump to

Keyboard shortcuts

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