github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrpkgerrors/example_test.go (about) 1 // Copyright 2020 New Relic Corporation. All rights reserved. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package nrpkgerrors_test 5 6 import ( 7 newrelic "github.com/newrelic/go-agent" 8 "github.com/newrelic/go-agent/_integrations/nrpkgerrors" 9 "github.com/pkg/errors" 10 ) 11 12 type rootError string 13 14 func (e rootError) Error() string { return string(e) } 15 16 func makeRootError() error { 17 return errors.WithStack(rootError("this is the original error")) 18 } 19 20 func Example() { 21 var txn newrelic.Transaction 22 e := errors.Wrap(makeRootError(), "extra information") 23 // Wrap the error to record stack-trace and class type information from 24 // the error's root cause. Here, "rootError" will be recored as the 25 // class and top stack-trace frame will be inside makeRootError(). 26 // Without nrpkgerrors.Wrap, "*errors.withStack" would be recorded as 27 // the class and the top stack-trace frame would be site of the 28 // NoticeError call. 29 txn.NoticeError(nrpkgerrors.Wrap(e)) 30 }