Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use original newrelic context functions #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
dist: trusty
dist: bionic
sudo: false

language: go
go: [ "1.11" ]
go: [ "1.15" ]
env:
global:
- PATH=$PATH:$HOME/gopath/bin
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/gettaxi/newrelicutil

go 1.15

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gorilla/context v1.1.1 // indirect
Expand Down
10 changes: 3 additions & 7 deletions newrelicutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@ import (
type key int

const (
transaction key = iota
segment
segment key = iota
externalSegment
datastoreSegment
)

// Transaction returns the New Relic Transaction object from context.
func Transaction(ctx context.Context) newrelic.Transaction {
if txn, ok := ctx.Value(transaction).(newrelic.Transaction); ok {
return txn
}
return nil
return newrelic.FromContext(ctx)
}

// WithTransaction puts the New Relic Transaction object to the given context
// and returns the new context.
func WithTransaction(ctx context.Context, txn newrelic.Transaction) context.Context {
return context.WithValue(ctx, transaction, txn)
return newrelic.NewContext(ctx, txn)
}

// WrapHandler return the given http handler that is wrapped to New Relic Transaction.
Expand Down
4 changes: 2 additions & 2 deletions newrelicutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"net/http/httptest"
"testing"

"github.com/gettaxi/newrelicutil"
newrelic "github.com/newrelic/go-agent"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gettaxi/newrelicutil"
"github.com/newrelic/go-agent"
)

func TestTransaction(t *testing.T) {
Expand Down