New Relic Go Agent
Latest commit 7d12ae2 Nov 16, 2016 @willnewrelic willnewrelic Merge pull request #96 from will/changelog
Improve changelog
Failed to load latest commit information.
_integrations Add ability to track which integrations are used Oct 25, 2016
examples Merge pull request #93 from will/license-env-alternative Nov 15, 2016
internal Skip non-zero duration tests on Windows Nov 16, 2016 Improve changelog Nov 16, 2016 Fix broken markdown link Aug 5, 2016 Fix missing word in description Oct 19, 2016
LICENSE.txt Update license and add file Aug 2, 2016 Windows support cleanup Nov 15, 2016
application.go Add a timeout to Shutdown method Oct 7, 2016
attributes.go Shortened attribute constant names for ease of use Aug 5, 2016
config.go Implement slow query traces Oct 11, 2016
datastore.go Move attributes and datastore to top level Aug 5, 2016
instrumentation.go Refactor segment tracing Aug 1, 2016
internal_app.go Implement slow query traces Oct 11, 2016
internal_attributes_test.go Fix background trace apdex threshold bug Sep 30, 2016
internal_benchmark_test.go Implement transaction traces Sep 7, 2016
internal_config.go Implement transaction traces Sep 7, 2016
internal_config_test.go Implement slow query traces Oct 11, 2016
internal_response_writer.go Split internal.go for convenience Aug 5, 2016
internal_slow_queries_test.go Implement new datastore API cross agent tests Oct 31, 2016
internal_test.go Satisfy go vet Oct 26, 2016
internal_txn.go Don't use unknown for empty Host and PortPathOrID Oct 18, 2016
log.go Improve logging documentation Jul 21, 2016
segments.go Implement slow query traces Oct 11, 2016
transaction.go Refactor segment tracing Aug 1, 2016
version.go 1.5.0 Nov 15, 2016

New Relic Go Agent


The New Relic Go Agent allows you to monitor your Go applications with New Relic. It helps you track transactions, outbound requests, database calls, and other parts of your Go application's behavior and provides a running overview of garbage collection, goroutine activity, and memory use.


Go 1.3+ is required, due to the use of http.Client's Timeout field.

Linux, OS X, and Windows (Vista, Server 2008 and later) are supported.

Getting Started

Here are the basic steps to instrumenting your application. For more information, see

Step 0: Installation

Installing the Go Agent is the same as installing any other Go library. The simplest way is to run:

go get

Then import the package in your application.

Step 1: Create a Config and an Application

In your main function or an init block:

config := newrelic.NewConfig("Your Application Name", "__YOUR_NEW_RELIC_LICENSE_KEY__")
app, err := newrelic.NewApplication(config)

more info, application.go, config.go

Step 2: Add Transactions

Transactions time requests and background tasks. Use WrapHandle and WrapHandleFunc to create transactions for requests handled by the http standard library package.

http.HandleFunc(newrelic.WrapHandleFunc(app, "/users", usersHandler))

Alternatively, create transactions directly using the application's StartTransaction method:

txn := app.StartTransaction("myTxn", optionalResponseWriter, optionalRequest)
defer txn.End()

more info, transaction.go

Step 3: Instrument Segments

Segments show you where time in your transactions is being spent. At the beginning of important functions, add:

defer newrelic.StartSegment(txn, "mySegmentName").End()

more info, segments.go

Runnable Example

examples/server/main.go is an example that will appear as "My Go Application" in your New Relic applications list. To run it:

    go run examples/server/main.go

Some endpoints exposed are http://localhost:8000/ and http://localhost:8000/notice_error

Basic Example

Before Instrumentation

package main

import (

func helloHandler(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "hello, world")

func main() {
    http.HandleFunc("/", helloHandler)
    http.ListenAndServe(":8000", nil)

After Instrumentation

package main

import (


func helloHandler(w http.ResponseWriter, r *http.Request) {
    io.WriteString(w, "hello, world")

func main() {
    // Create a config.  You need to provide the desired application name
    // and your New Relic license key.
    cfg := newrelic.NewConfig("My Go Application", "__YOUR_NEW_RELIC_LICENSE_KEY__")

    // Create an application.  This represents an application in the New
    // Relic UI.
    app, err := newrelic.NewApplication(cfg)
    if err != nil {

    // Wrap helloHandler.  The performance of this handler will be recorded.
    http.HandleFunc(newrelic.WrapHandleFunc(app, "/", helloHandler))
    http.ListenAndServe(":8000", nil)


You can find more detailed documentation in the guide.

If you can't find what you're looking for there, reach out to us on our support site or our community forum and we'll be happy to help you.

Find a bug? Contact us via, or email