Guide to using the Go agent API

The New Relic Go agent monitors your Go language applications and microservices to help you identify and solve performance issues.

Because Go applications run from a compiled, native binary file, you need to manually instrument your code to monitor transactions for your Go applications by adding New Relic methods to it.

For all available New Relic APIs, see Intro to APIs.

Monitor transactions

Before you manually instrument your code to monitor transactions, make sure that you meet the compatibility and requirements and that you are using the latest version of the Go agent.

If you want to...

Use this method...

Start timing a transaction

StartTransaction()

Stop timing a transaction

txn.End()

Prevent a transaction from reporting to New Relic

Ignore()

Use the standard HTTP library package to monitor transactions HTTP request wrapping

Time specific methods using segments

If a transaction is already visible in the New Relic UI, but you do not have enough data about a particular method that was called during that transaction, you can create segments. For example, if you want to time a method that has complex logic, you can create a segment for each of the methods in the transaction.

To instrument a method within an existing transaction, create segments for the following:

Enhance the metadata of a transaction

You can manage the metadata that New Relic reports for transactions. Here are some examples of when you might want a different level of detail for your transactions:

  • If you are experiencing a metric grouping issue, change the default names for your transactions to make them more identifiable.
  • If you want to create dashboards for your transactions in Insights, add custom attributes.

If you want to...

Use this...

Change the name of a transaction

SetName()

Add metadata (such as your customer’s account name or subscription level) to your transactions

AddAttribute()

Instrument calls to external services

Use these methods to collect data about your app’s connections to other apps or databases:

If you want to...

Use this...

Time a call to an external resource (such as an external service, database server, or message queue)

StartExternalSegment()

Connect activity to another app instrumented by a New Relic agent

Cross application tracing

See the path that a request takes as it travels through a distributed system. Distributed tracing

Collect or ignore errors

The agent detects errors automatically. If you want to change the way the Go agent reports errors to New Relic, change the error collector configuration.

If you want to...

Use this...

Report an error the agent does not report automatically

NoticeError()

Prevent the agent from reporting an error at all

ErrorCollector.IgnoreStatusCodes()

Send custom data from your app

To record custom data with the Go agent, you can use any of the following methods:

If you want to...

Use this...

Send data about an event so you can analyze it in New Relic Insights

RecordCustomEvent()

Tag your events with metadata to filter and facet them in Insights or error analytics

AddAttribute()

Report custom performance data for a specified period of time

RecordCustomMetric()

Monitor browser performance with New Relic Browser

To monitor browser performance for your app using New Relic Browser and the Go agent, install Browser using the copy/paste method.

Change the configuration settings for the Go agent

Change Go agent configuration settings to administer some aspects of New Relic monitoring, such as turning on high-security mode, adding custom labels for filtering and sorting, and managing what information is collected.

For more help

Recommendations for learning more: