https://github.com/remind101/newrelic
DEPRECATED: Use the official lib here https://github.com/newrelic/go-agent
https://github.com/remind101/newrelic
Last synced: over 1 year ago
JSON representation
DEPRECATED: Use the official lib here https://github.com/newrelic/go-agent
- Host: GitHub
- URL: https://github.com/remind101/newrelic
- Owner: remind101
- License: bsd-2-clause
- Created: 2015-05-08T23:29:48.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-25T00:57:55.000Z (almost 10 years ago)
- Last Synced: 2023-08-11T23:38:33.566Z (almost 3 years ago)
- Language: Go
- Homepage:
- Size: 3.07 MB
- Stars: 19
- Watchers: 78
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## NewRelic Go Agent
A small convenience layer that sits on top of [newrelic-go-agent](https://github.com/paulsmith/newrelic-go-agent), to make
it easy to create transactions for NewRelic in Go.
## Caveats
This is alpha software. It has not been tested in a production environment, or any environment for that matter.
## Installing
You'll need to [install the nr_agent_sdk first](https://docs.newrelic.com/docs/agents/agent-sdk/installation-configuration/installing-agent-sdk).
This package will only work on linux platforms. It is also disabled by default. To enable it, use the build flag `newrelic_enabled`:
```
go build -tags newrelic_enabled ./...
```
## Example Usage
See `./example/main.go` for a more complete example.
``` go
import "github.com/remind101/newrelic"
func main() {
newrelic.Init("newrelic app name", "newrelic license key")
tx := newrelic.NewTx("/my/transaction/name")
tx.Start()
defer tx.End()
// Add a segment
tx.StartGeneric("middleware")
// Do some middleware stuff...
tx.EndSegment()
}
```
## Using with an http server
This packages works well as an [httpx middleware](https://github.com/remind101/pkg/blob/master/httpx/middleware/newrelic_tracer.go).
Here is an example using [httpx](https://github.com/remind101/pkg/tree/master/httpx), a context aware http handler.
``` go
r := httpx.NewRouter()
r.Handle("/articles", &ArticlesHandler{}).Methods("GET")
r.Handle("/articles/{id}", &ArticleHandler{}).Methods("GET")
var h httpx.Handler
// Add NewRelic tracing.
h = middleware.NewRelicTracing(r, r, &newrelic.NRTxTracer{})
// Wrap the route in middleware to add a context.Context.
h = middleware.BackgroundContext(h)
http.ListenAndServe(":8080", h)
```
The above example will create web transactions named `GET "/articles"` and `GET "/articles/{id}"`.