All Projects → remind101 → newrelic

remind101 / newrelic

Licence: BSD-2-Clause license
DEPRECATED: Use the official lib here https://github.com/newrelic/go-agent

Programming Languages

go
31211 projects - #10 most used programming language
c
50402 projects - #5 most used programming language
Makefile
30231 projects

NewRelic Go Agent

A small convenience layer that sits on top of 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.

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.

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.

Here is an example using httpx, a context aware http handler.

    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}".

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].