Documentation ¶
Overview ¶
Package nrcontext allows you to use the New Relic go-agent with context.Context
Description ¶
The go-agent from New Relic currently (as of 2017-08-30) does not have support for storing newrelic.Application and newrelic.Transaction in context.Context.
This package is an experiment in doing just that.
Installation ¶
Just go get the package:
go get -u github.com/TV4/nrcontext
Or more likely: use dep to vendor nrcontext
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Application ¶
func Application(ctx context.Context) newrelic.Application
Application returns newrelic.Application stored in ctx, returns nil if missing
Example ¶
package main import ( "context" "net/http/httptest" "github.com/TV4/nrcontext" "github.com/TV4/nrcontext/nrmock" ) func main() { // Get a context containing a newrelic.Application (a mock in this example) ctx := nrcontext.WithApplication(context.Background(), nrmock.NewApplication()) // Now you can retrieve the newrelic.Application from // ctx using the Application function app := nrcontext.Application(ctx) // Setup a http.ResponseWriter and a *http.Request for use in this example w, r := httptest.NewRecorder(), httptest.NewRequest("GET", "/foo", nil) // Start a transaction txn := app.StartTransaction("name", w, r) // End the transaction txn.End() }
Output:
func Transaction ¶
func Transaction(ctx context.Context) newrelic.Transaction
Transaction returns newrelic.Transaction stored in ctx, returns nil if missing
Example ¶
package main import ( "context" "errors" "github.com/TV4/nrcontext" "github.com/TV4/nrcontext/nrmock" ) func main() { // Get a context containing a newrelic.Transaction (a mock in this example) ctx := nrcontext.WithTransaction(context.Background(), nrmock.NewTransaction("name")) // Now you can retrieve the newrelic.Transaction from the context txn := nrcontext.Transaction(ctx) // You can now use the transaction to notice errors txn.NoticeError(errors.New("some error you want to notice")) // And to add attributes txn.AddAttribute("foo", "bar") }
Output:
func WithApplication ¶
WithApplication returns a copy of parent in which the value associated with appKey is app
Example ¶
package main import ( "context" "github.com/TV4/nrcontext" "github.com/TV4/nrcontext/nrmock" ) func main() { // Get a context containing a newrelic.Application (a mock in this example) ctx := nrcontext.WithApplication(context.Background(), nrmock.NewApplication()) ctx.Done() }
Output:
func WithTransaction ¶
WithTransaction returns a copy of parent in which the value associated with txnKey is txn
Example ¶
package main import ( "context" "github.com/TV4/nrcontext" "github.com/TV4/nrcontext/nrmock" ) func main() { // Get a context containing a newrelic.Transaction (a mock in this example) ctx := nrcontext.WithTransaction(context.Background(), nrmock.NewTransaction("name")) ctx.Done() }
Output:
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package nrmock contains mock implementations of newrelic.Application and newrelic.Transaction Links The newrelic.Application interface is defined here https://github.com/newrelic/go-agent/blob/master/application.go And the newrelic.Transaction interface is defined here https://github.com/newrelic/go-agent/blob/master/transaction.go
|
Package nrmock contains mock implementations of newrelic.Application and newrelic.Transaction Links The newrelic.Application interface is defined here https://github.com/newrelic/go-agent/blob/master/application.go And the newrelic.Transaction interface is defined here https://github.com/newrelic/go-agent/blob/master/transaction.go |