Go Release Notes

Go Agent Release Notes

Thursday, October 24, 2019 - 14:00 Download


New Features

  • Added support for monitoring MongoDB queries with the new _integrations/nrmongo package.

  • Added new method Transaction.IsSampled() that returns a boolean that indicates if the transaction is sampled. A sampled transaction records a span event for each segment. Distributed tracing must be enabled for transactions to be sampled. false is returned if the transaction has finished. This sampling flag is needed for B3 trace propagation and future support of W3C Trace Context.

  • Added support for adding B3 Headers to outgoing requests. This is helpful if the service you are calling uses B3 for trace state propagation (for example, it uses Zipkin instrumentation). You can use the new _integrations/nrb3 package's nrb3.NewRoundTripper like this:

    // When defining the client, set the Transport to the NewRoundTripper. This
    // will create ExternalSegments and add B3 headers for each request.
    client := &http.Client{
      Transport: nrb3.NewRoundTripper(nil),
    // Distributed Tracing must be enabled for this application.
    // (see https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/enable-configure/enable-distributed-tracing)
    txn := currentTxn()
    req, err := http.NewRequest("GET", "http://example.com", nil)
    if nil != err {
    // Be sure to add the transaction to the request context.  This step is
    // required.
    req = newrelic.RequestWithTransactionContext(req, txn)
    resp, err := client.Do(req)
    if nil != err {
    defer resp.Body.Close()
Tuesday, October 15, 2019 - 14:52 Download


Bug Fixes

  • Removed the hidden "NEW_RELIC_DEBUG_LOGGING" environment variable setting which was broken in release 2.14.0.
Monday, October 14, 2019 - 14:27 Download


New Features

  • Added support for a new segment type, MessageProducerSegment, to be used to track time spent adding messages to message queuing systems like RabbitMQ or Kafka.

    seg := &newrelic.MessageProducerSegment{
      StartTime:       newrelic.StartSegmentNow(txn),
      Library:         "RabbitMQ",
      DestinationType: newrelic.MessageExchange,
      DestinationName: "myExchange",
    // add message to queue here
  • Added new attribute constants for use with message consumer transactions. These attributes can be used to add more detail to a transaction that tracks time spent consuming a message off a message queuing system like RabbitMQ or Kafka. They can be added using txn.AddAttribute.

    // The routing key of the consumed message.
    txn.AddAttribute(newrelic.AttributeMessageRoutingKey, "myRoutingKey")
    // The name of the queue the message was consumed from.
    txn.AddAttribute(newrelic.AttributeMessageQueueName, "myQueueName")
    // The type of exchange used for the consumed message (direct, fanout,
    // topic, or headers).
    txn.AddAttribute(newrelic.AttributeMessageExchangeType, "myExchangeType")
    // The callback queue used in RPC configurations.
    txn.AddAttribute(newrelic.AttributeMessageReplyTo, "myReplyTo")
    // The application-generated identifier used in RPC configurations.
    txn.AddAttribute(newrelic.AttributeMessageCorrelationID, "myCorrelationID")

    It is recommended that at most one message is consumed per transaction.

  • Added support for Go 1.13's Error wrapping. Transaction.NoticeError now uses Unwrap recursively to identify the error's cause (the deepest wrapped error) when generating the error's class field. This functionality will help group your errors usefully.

    For example, when using Go 1.13, the following code:

    type socketError struct{}
    func (e socketError) Error() string { return "socket error" }
    func gamma() error { return socketError{} }
    func beta() error  { return fmt.Errorf("problem in beta: %w", gamma()) }
    func alpha() error { return fmt.Errorf("problem in alpha: %w", beta()) }
    func execute(txn newrelic.Transaction) {
    err := alpha()

    captures an error with message "problem in alpha: problem in beta: socket error" and class "main.socketError". Previously, the class was recorded as "*fmt.wrapError".

  • A Stack field has been added to Error, which can be assigned using the new NewStackTrace function. This allows your error stack trace to show where the error happened, rather than the location of the NoticeError call.

    Transaction.NoticeError not only checks for a stack trace (using StackTracer) in the error parameter, but in the error's cause as well. This means that you can create an Error where your error occurred, wrap it multiple times to add information, notice it with NoticeError, and still have a useful stack trace. Take a look!

    func gamma() error {
    return newrelic.Error{
        Message: "something went very wrong",
        Class:   "socketError",
        Stack:   newrelic.NewStackTrace(),
    func beta() error  { return fmt.Errorf("problem in beta: %w", gamma()) }
    func alpha() error { return fmt.Errorf("problem in alpha: %w", beta()) }
    func execute(txn newrelic.Transaction) {
    err := alpha()

    In this example, the topmost stack trace frame recorded is "gamma", rather than "execute".

  • Added support for configuring a maximum number of transaction events per minute to be sent to New Relic. It can be configured as follows:

    config := newrelic.NewConfig("Application Name", os.Getenv("NEW_RELIC_LICENSE_KEY"))  
    config.TransactionEvents.MaxSamplesStored = 100
    • For additional configuration information, see our documentation


Monday, September 23, 2019 - 16:15 Download


New Features

Tuesday, September 17, 2019 - 11:00 Download

New Features

  • Added new methods to expose Transaction details:

    • Transaction.GetTraceMetadata() returns a TraceMetadata which contains distributed tracing identifiers.
    • Transaction.GetLinkingMetadata() returns a LinkingMetadata which contains the fields needed to link data to a trace or entity.
  • Added a new plugin for the Logrus logging framework with the new _integrations/logcontext/nrlogrusplugin package. This plugin leverages the new GetTraceMetadata and GetLinkingMetadata above to decorate logs.

    To enable, set your log's formatter to the nrlogrusplugin.ContextFormatter{}

    logger := logrus.New()

    The logger will now look for a newrelic.Transaction inside its context and decorate logs accordingly. Therefore, the Transaction must be added to the context and passed to the logger. For example, this logging call

    logger.Info("Hello New Relic!")

    must be transformed to include the context, such as:

    ctx := newrelic.NewContext(context.Background(), txn)
    logger.WithContext(ctx).Info("Hello New Relic!")

    For full documentation see the godocs or view the example.

  • Added support for NATS and NATS Streaming monitoring with the new _integrations/nrnats and _integrations/nrstan packages. These packages support instrumentation of publishers and subscribers.

  • Enables ability to migrate to Configurable Security Policies (CSP) on a per agent basis for accounts already using High Security Mode (HSM).

    • Previously, if CSP was configured for an account, New Relic would not allow an agent to connect without the security_policies_token. This led to agents not being able to connect during the period between when CSP was enabled for an account and when each agent is configured with the correct token.
    • With this change, when both HSM and CSP are enabled for an account, an agent (this version or later) can successfully connect with either high_security: true or the appropriate security_policies_token configured - allowing the agent to continue to connect after CSP is configured on the account but before the appropriate security_policies_token is configured for each agent.
Thursday, August 22, 2019 - 14:30 Download

New Features

  • Added support for Micro monitoring with the new _integrations/nrmicro package. This package supports instrumentation for servers, clients, publishers, and subscribers.

  • Added support for creating static WebRequest instances manually via the NewStaticWebRequest function. This can be useful when you want to create a web transaction but don't have an http.Request object. Here's an example of creating a static WebRequest and using it to mark a transaction as a web transaction:

    hdrs := http.Headers{}
    u, _ := url.Parse("http://example.com")
    webReq := newrelic.NewStaticWebRequest(hdrs, u, "GET", newrelic.TransportHTTP)
    txn := app.StartTransaction("My-Transaction", nil, nil)
Wednesday, July 31, 2019 - 15:11 Download


New Features

  • Added support for custom events when using nrlambda. Example Lambda handler which creates custom event:

    func handler(ctx context.Context) {
        if txn := newrelic.FromContext(ctx); nil != txn {
            txn.Application().RecordCustomEvent("myEvent", map[string]interface{}{
                "zip": "zap",
        fmt.Println("hello world!")
Wednesday, July 10, 2019 - 11:42 Download


New Features

  • Added support for gRPC monitoring with the new _integrations/nrgrpc package. This package supports instrumentation for servers and clients.

  • Added new ExternalSegment fields Host, Procedure, and Library. These optional fields are automatically populated from the segment's URL or Request if unset. Use them if you don't have access to a request or URL but still want useful external metrics, transaction segment attributes, and span attributes.

    • Host is used for external metrics, transaction trace segment names, and span event names. The host of segment's Request or URL is the default.
    • Procedure is used for transaction breakdown metrics. If set, it should be set to the remote procedure being called. The HTTP method of the segment's Request is the default.
    • Library is used for external metrics and the "component" span attribute. If set, it should be set to the framework making the call. "http" is the default.

    With the addition of these new fields, external transaction breakdown metrics are changed: External/myhost.com/all will now report as External/myhost.com/http/GET (provided the HTTP method is GET).

  • HTTP Response codes below 100, except 0 and 5, are now recorded as errors. This is to support gRPC status codes. If you start seeing new status code errors that you would like to ignore, add them to Config.ErrorCollector.IgnoreStatusCodes or your server side configuration settings.

  • Improve logrus support by introducing nrlogrus.Transform, a function which allows you to turn a logrus.Logger instance into a newrelic.Logger. Example use:

    l := logrus.New()
    cfg := newrelic.NewConfig("Your Application Name", "__YOUR_NEW_RELIC_LICENSE_KEY__")
    cfg.Logger = nrlogrus.Transform(l)

    As a result of this change, the nrlogrus package requires logrus version v1.1.0 and above.

Tuesday, June 18, 2019 - 09:45 Download


Bug Fixes

  • Removed nrmysql.NewConnector since go-sql-driver/mysql has not yet released mysql.NewConnector.
Tuesday, June 11, 2019 - 14:19 Download


New Features

  • Introduce support for databases using database/sql. This new functionality allows you to instrument MySQL, PostgreSQL, and SQLite calls without manually creating DatastoreSegments.
Database Library Supported Integration Package
go-sql-driver/mysql _integrations/nrmysql
lib/pq _integrations/nrpq
mattn/go-sqlite3 _integrations/nrsqlite3

Using these database integration packages is easy! First replace the driver with our integration version:

  import (
    // import our integration package
    _ "github.com/newrelic/go-agent/_integrations/nrmysql"

  func main() {
    // open "nrmysql" in place of "mysql"
    db, err := sql.Open("nrmysql", "user@unix(/path/to/socket)/dbname")

Second, use the ExecContext, QueryContext, and QueryRowContext methods of sql.DB, sql.Conn, sql.Tx, and sql.Stmt and provide a transaction-containing context. Calls to Exec, Query, and QueryRow do not get instrumented.

  ctx := newrelic.NewContext(context.Background(), txn)
  row := db.QueryRowContext(ctx, "SELECT count(*) from tables")

If you are using a database/sql database not listed above, you can write your own instrumentation for it using InstrumentSQLConnector, InstrumentSQLDriver, and SQLDriverSegmentBuilder. The integration packages act as examples of how to do this.

For more information, see the Go agent documentation on instrumenting datastore segments.

Bug Fixes

Tuesday, March 26, 2019 - 11:42 Download


New Features

  • Added support for server side configuration. Server side configuration allows you to set the following configuration settings in the New Relic APM UI:

    • Config.TransactionTracer.Enabled
    • Config.ErrorCollector.Enabled
    • Config.CrossApplicationTracer.Enabled
    • Config.TransactionTracer.Threshold
    • Config.TransactionTracer.StackTraceThreshold
    • Config.ErrorCollector.IgnoreStatusCodes

    For more information see the server side configuration documentation.

  • Added support for AWS Lambda functions in the new nrlambda package. Please email lambda_preview@newrelic.com if you are interested in learning more or previewing New Relic Lambda monitoring. This instrumentation package requires aws-lambda-go version v1.9.0 or higher.

Tuesday, March 12, 2019 - 16:00 Download


New Features

  • Added support for async: the ability to instrument multiple concurrent goroutines, or goroutines that access or manipulate the same Transaction.

    The new Transaction.NewGoroutine() Transaction method allows transactions to create segments in multiple goroutines!

    NewGoroutine returns a new reference to the Transaction. This must be called any time you are passing the Transaction to another goroutine which makes segments. Each segment-creating goroutine must have its own Transaction reference. It does not matter if you call this before or after the other goroutine has started.

    All Transaction methods can be used in any Transaction reference. The Transaction will end when End() is called in any goroutine.

    Example passing a new Transaction reference directly to another goroutine:

    go func(txn newrelic.Transaction) {
        defer newrelic.StartSegment(txn, "async").End()
        time.Sleep(100 * time.Millisecond)

    Example passing a new Transaction reference on a channel to another goroutine:

    ch := make(chan newrelic.Transaction)
    go func() {
        txn := <-ch
        defer newrelic.StartSegment(txn, "async").End()
        time.Sleep(100 * time.Millisecond)
    ch <- txn.NewGoroutine()
  • Added integration support for aws-sdk-go and aws-sdk-go-v2.

    When using these SDKs, a segment will be created for each out going request. For DynamoDB calls, these will be Datastore segments and for all others they will be External segments.

    • v1 Documentation
    • v2 Documentation

    • Added span event and transaction trace segment attribute configuration. You may control which attributes are captured in span events and transaction trace segments using the Config.SpanEvents.Attributes and Config.TransactionTracer.Segments.Attributes settings. For example, if you want to disable the collection of "db.statement" in your span events, modify your config like this:

    cfg.SpanEvents.Attributes.Exclude = append(cfg.SpanEvents.Attributes.Exclude,

    To disable the collection of all attributes from your transaction trace segments, modify your config like this:

    cfg.TransactionTracer.Segments.Attributes.Enabled = false

Bug Fixes

  • Fixed a bug that would prevent External Segments from being created under certain error conditions related to Cross Application Tracing.


  • Improved linking between Cross Application Transaction Traces in the APM UI. When Config.CrossApplicationTracer.Enabled = true, External segments in the Transaction Traces details will now link to the downstream Transaction Trace if there is one. Additionally, the segment name will now include the name of the downstream application and the name of the downstream transaction.

  • Update attribute names of Datastore and External segments on Transaction Traces to be in line with attribute names on Spans. Specifically:

    • "uri" => "http.url"
    • "query" => "db.statement"
    • "database_name" => "db.instance"
    • "host" => "peer.hostname"
    • "port_path_or_id" + "host" => "peer.address"
Thursday, February 14, 2019 - 15:00 Download


  • Added support for New Relic Browser using the new BrowserTimingHeader method on the Transaction which returns a BrowserTimingHeader. The New Relic Browser JavaScript code measures page load timing, also known as real user monitoring. The Pro version of this feature measures AJAX requests, single-page applications, JavaScript errors, and much more! Example use:
func browser(w http.ResponseWriter, r *http.Request) {
    hdr, err := w.(newrelic.Transaction).BrowserTimingHeader()
    if nil != err {
        log.Printf("unable to create browser timing header: %v", err)
    // BrowserTimingHeader() will always return a header whose methods can
    // be safely called.
    if js := hdr.WithTags(); js != nil {
    io.WriteString(w, "browser header page")
  • The Go agent now collects an attribute named request.uri on Transaction Traces, Transaction Events, Error Traces, and Error Events. request.uri will never contain user, password, query parameters, or fragment. To prevent the request's URL from being collected in any data, modify your Config like this:
cfg.Attributes.Exclude = append(cfg.Attributes.Exclude, newrelic.AttributeRequestURI)
Thursday, January 31, 2019 - 15:00 Download

2.4.0 Notes

  • Introduced Transaction.Application method which returns the Application that started the Transaction. This method is useful since it may prevent having to pass the Application to code that already has access to the Transaction. Example use:
txn.Application().RecordCustomEvent("customerOrder", map[string]interface{}{
    "numItems":   2,
    "totalPrice": 13.75,
  • The Transaction.AddAttribute method no longer accepts nil values since our backend ignores them.
Thursday, January 24, 2019 - 15:00 Download

2.3.0 Notes

  • Added support for Echo in the new nrecho package.

  • Introduced Transaction.SetWebResponse(http.ResponseWriter) method which sets the transaction's response writer. After calling this method, the Transaction may be used in place of the http.ResponseWriter to intercept the response code. This method is useful when the http.ResponseWriter is not available at the beginning of the transaction (if so, it can be given as a parameter to Application.StartTransaction). This method will return a reference to the transaction which implements the combination of http.CloseNotifier, http.Flusher, http.Hijacker, and io.ReaderFrom implemented by the ResponseWriter. Example:

func setResponseDemo(txn newrelic.Transaction) {
    recorder := httptest.NewRecorder()
    txn = txn.SetWebResponse(recorder)
    fmt.Println("response code recorded:", recorder.Code)
  • The Transaction's http.ResponseWriter methods may now be called safely if a http.ResponseWriter has not been set. This allows you to add a response code to the transaction without using a http.ResponseWriter. Example:
func transactionWithResponseCode(app newrelic.Application) {
       txn := app.StartTransaction("hasResponseCode", nil, nil)
       defer txn.End()
       txn.WriteHeader(200) // Safe!
  • The agent will now collect environment variables prefixed by NEW_RELIC_METADATA_ and KUBERNETES_SERVICE_HOST. These will be added to Transaction events to provide context between your Kubernetes cluster and your services. For details on the benefits (currently in beta) see this blog post

  • The agent now collects the fully qualified domain name of the host and local IP addresses for improved linking with our Infrastructure product.

Tuesday, December 18, 2018 - 11:00 Download

2.2 Notes

  • The Transaction parameter to NewRoundTripper and StartExternalSegment is now optional: If it is nil, then a Transaction will be looked for in the request's context (using FromContext). Passing a nil transaction is STRONGLY recommended when using NewRoundTripper since it allows one http.Client.Transport to be used for multiple transactions. Example use:
client := &http.Client{}
client.Transport = newrelic.NewRoundTripper(nil, client.Transport)
request, _ := http.NewRequest("GET", "http://example.com", nil)
request = newrelic.RequestWithTransactionContext(request, txn)
resp, err := client.Do(request)
  • Introduced Transaction.SetWebRequest(WebRequest) method which marks the transaction as a web transaction. If the WebRequest parameter is non-nil, SetWebRequest will collect details on request attributes, url, and method. This method is useful if you don't have access to the request at the beginning of the transaction, or if your request is not an *http.Request (just add methods to your request that satisfy WebRequest). To use an *http.Request as the parameter, use the NewWebRequest transformation function. Example:
var request *http.Request = getInboundRequest()
  • Fixed Debug in nrlogrus package. Previous versions of the New Relic Go Agent incorrectly logged to Info level instead of Debug. This has now been fixed. Thanks to @paddycarey for catching this.

  • nrgin.Transaction may now be called with either a context.Context or a *gin.Context. If you were passing a *gin.Context around your functions as a context.Context, you may access the Transaction by calling either nrgin.Transaction or FromContext. These functions now work nicely together. For example, FromContext will return the Transaction added by nrgin.Middleware. Thanks to @rodriguezgustavo for the suggestion.

Tuesday, August 28, 2018 - 12:10 Download

2.1.0 New

Go Agent now supports distributed tracing

Distributed tracing lets you see the path that a request takes as it travels through your distributed system. By showing the distributed activity through a unified view, you can troubleshoot and understand a complex system better than ever before.

Distributed tracing is available with an APM Pro or equivalent subscription. To see a complete distributed trace, you need to enable the feature on a set of neighboring services. Enabling distributed tracing changes the behavior of some New Relic features, so carefully consult the transition guide before you enable this feature.

To enable distributed tracing, set the following fields in your config. Note that distributed tracing and cross application tracing cannot be used simultaneously.

  config := newrelic.NewConfig("Your Application Name", "__YOUR_NEW_RELIC_LICENSE_KEY__")
  config.CrossApplicationTracer.Enabled = false
  config.DistributedTracer.Enabled = true

Please refer to the distributed tracing section of the guide for more detail on how to ensure you get the most out of the Go agent's distributed tracing support.

New distributed trace calls/functions

Added functions NewContext and FromContext for adding and retrieving the Transaction from a Context. Handlers instrumented by WrapHandle, WrapHandleFunc, and nrgorilla.InstrumentRoutes may use FromContext on the request's context to access the Transaction. Thanks to @caarlos0 for the contribution! Though NewContext and FromContext require Go 1.7+ (when context was added), RequestWithTransactionContext is always exported so that it can be used in all framework and library instrumentation.

Tuesday, May 15, 2018 - 12:10 Download

2.0.0 New

  • The End() functions defined on the Segment, DatastoreSegment, and ExternalSegment types now receive the segment as a pointer, rather than as a value. This prevents unexpected behaviour when a call to End() is deferred before one or more fields are changed on the segment.

    In practice, this is likely to only affect this pattern:

    defer newrelic.DatastoreSegment{
      // ...

    Instead, you will now need to separate the literal from the deferred call:

    ds := newrelic.DatastoreSegment{
      // ...
    defer ds.End()

    When creating custom and external segments, we recommend using newrelic.StartSegment() and newrelic.StartExternalSegment(), respectively.

  • Added GoDoc badge to README. Thanks to @mrhwick for the contribution!

  • Config.UseTLS configuration setting has been removed to increase security. TLS will now always be used in communication with New Relic Servers.

Wednesday, November 29, 2017 - 09:10 Download

New Features

  • Added support for Cross Application Tracing (CAT). Please refer to the upgrading section of the guide for more detail on how to ensure you get the most out of the Go agent's new CAT support.

  • The agent now collects additional metadata when running within Amazon Web Services, Google Cloud Platform, Microsoft Azure, and Pivotal Cloud Foundry. This information is used to provide an enhanced experience when the agent is deployed on those platforms.

Tuesday, October 24, 2017 - 04:22 Download


  • Added new RecordCustomMetric method to Application. This functionality can be used to track averages or counters without using custom events. See Custom Metric Documentation
  • Fixed import needed for logrus. The import Sirupsen/logrus had been renamed to sirupsen/logrus. Thanks to @alfred-landrum for spotting this.
  • Added ErrorAttributer, an optional interface that can be implemented by errors provided to Transaction.NoticeError to attach additional attributes. These attributes are subject to attribute configuration.
  • Added Error, a type that allows direct control of error fields.
  • Updated license to address scope of usage.