go-agent: github.com/newrelic/go-agent/_integrations/nrpkgerrors Index | Examples | Files | Directories

package nrpkgerrors

import "github.com/newrelic/go-agent/_integrations/nrpkgerrors"

Package nrpkgerrors introduces support for https://github.com/pkg/errors.

This package improves the class and stack-trace fields of pkg/error errors when they are recorded with Transaction.NoticeError.

Code:

package main

import (
    newrelic "github.com/newrelic/go-agent"
    "github.com/newrelic/go-agent/_integrations/nrpkgerrors"
    "github.com/pkg/errors"
)

type rootError string

func (e rootError) Error() string { return string(e) }

func makeRootError() error {
    return errors.WithStack(rootError("this is the original error"))
}

func main() {
    var txn newrelic.Transaction
    e := errors.Wrap(makeRootError(), "extra information")
    // Wrap the error to record stack-trace and class type information from
    // the error's root cause.  Here, "rootError" will be recored as the
    // class and top stack-trace frame will be inside makeRootError().
    // Without nrpkgerrors.Wrap, "*errors.withStack" would be recorded as
    // the class and the top stack-trace frame would be site of the
    // NoticeError call.
    txn.NoticeError(nrpkgerrors.Wrap(e))
}

Index

Examples

Package Files

nrpkgerrors.go

func Wrap Uses

func Wrap(e error) error

Wrap wraps a pkg/errors error so that when noticed by newrelic.Transaction.NoticeError it gives an improved stacktrace and class type.

Directories

PathSynopsis
example

Package nrpkgerrors imports 4 packages (graph) and is imported by 1 packages. Updated 2019-10-16. Refresh now. Tools for package owners.