The New Relic Go agent monitors your Go language applications and microservices to help you identify and solve performance issues. The Go agent API is one of several available New Relic APIs.
重要
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.
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 | |
Stop timing a transaction | |
Prevent a transaction from reporting to New Relic | |
Use the standard HTTP library package to monitor transactions |
Time specific methods using segments
If a transaction is already visible in New Relic, 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:
If the work is happening in a different goroutine from where the transaction started, you must use the NewGoroutine()
API.
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, add custom attributes.
If you want to... | Use this... | |
---|---|---|
Change the name of a transaction | ||
Add metadata (such as your customer’s account name or subscription level) to your transactions |
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) | |
Connect activity to another app instrumented by a New Relic agent | |
See the path that a request takes as it travels through a distributed system. |
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 | |
Prevent the agent from reporting an error at all |
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 | |
Tag your events with metadata to filter and facet them | |
Report custom performance data for a specified period of time |
See related logs
To see logs directly within the context of your application's errors and traces, use these API calls to annotate your logs:
For more information about correlating log data with other telemetry data, see our logs in context documentation.
Monitor browser performance with browser monitoring
To monitor browser performance for your app using browser monitoring and the Go agent, you can use any of the following methods:
If you want to... | Use this... |
---|---|
Install the browser agent | Use the browser copy/paste method |
Add the browser monitoring JavaScript code directly to HTML pages |
Change the configuration settings for the Go agent
To manage some aspects of New Relic monitoring, you can change your Go agent configuration settings; for example:
- Turning on high security mode
- Adding custom labels for filtering and sorting
- Managing what information is reported