This is a cache of https://www.elastic.co/guide/en/apm/agent/go/current/introduction.html. It is a snapshot of the page at 2024-12-13T01:02:22.546+0000.
Introduction | APM Go Agent Reference [2.x] | Elastic

Introduction

edit

The Elastic APM Go Agent enables you to trace the execution of operations in your Go applications, sending performance metrics and errors to the Elastic APM server. It has built-in support for popular frameworks and toolkits, like Gorilla and Gin, as well as support for instrumenting Go’s built-in net/http, database/sql drivers. The Agent also offers an API Documentation for custom instrumentation.

How does the Agent work?

edit

The Agent includes instrumentation modules for Supported Technologies, each providing middleware or wrappers for recording interesting events, such as incoming HTTP requests, outgoing HTTP requests, and database queries.

To collect data about incoming HTTP requests, install router middleware for one of the supported web Frameworks. Incoming requests will be recorded as transactions, along with any related panics or errors.

To collect data for outgoing HTTP requests, instrument an http.Client or http.Transport using module/apmhttp. To collect data about database queries, use module/apmsql, which provides instrumentation for well known database drivers.

In order to connect transactions with related spans and errors, and propagate traces between services (distributed tracing), the agent relies on Go’s built-in context package: transactions and spans are stored in context objects. For example, for incoming HTTP requests, in-flight trace data will be recorded in the context object accessible through net/http.Context. Read more about this in Context propagation.

In addition to capturing events like those mentioned above, the agent also collects system and application metrics at regular intervals. This collection happens in a background goroutine that is automatically started when the agent is initialized.

Additional Components

edit

APM Agents work in conjunction with the APM Server, Elasticsearch, and Kibana. The APM Guide provides details on how these components work together, and provides a matrix outlining Agent and Server compatibility.