Go
Pyroscope uses the standard runtime/pprof
package to collect profiling data. Refer to
the official documentation for details.
#
Supported platformsSpy Name | Type | Linux | macOS | Windows | Docker |
---|---|---|---|---|---|
n/a | standalone | โ | โ | โ | โ |
#
Profiling Go applicationimportant
This current version of the Go integration requires you to run pyroscope server version 0.3.1
or higher.
We strongly recommend you to upgrade your pyroscope server version and use this new version of the golang client. It reduces both the number of dependancies and peformance overhead. The old documentation is still available here.
To start profiling a Go application, you need to include our go module in your app:
# make sure you also upgrade pyroscope server to version 0.3.1 or highergo get github.com/pyroscope-io/client/pyroscope
Then add the following code to your application:
package main
import "github.com/pyroscope-io/client/pyroscope"
func main() { pyroscope.Start(pyroscope.Config{ ApplicationName: "simple.golang.app",
// replace this with the address of pyroscope server ServerAddress: "http://pyroscope-server:4040",
// you can disable logging by setting this to nil Logger: pyroscope.StandardLogger,
// optionally, if authentication is enabled, specify the API key: // AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
// by default all profilers are enabled, // but you can select the ones you want to use: ProfileTypes: []pyroscope.ProfileType{ pyroscope.ProfileCPU, pyroscope.ProfileAllocObjects, pyroscope.ProfileAllocSpace, pyroscope.ProfileInuseObjects, pyroscope.ProfileInuseSpace, }, })
// your code goes here}
#
TagsIt is possible to add tags (labels) to the profiling data. These tags can be used to filter the data in the UI. We have a custom API that's in line with our other integrations (e.g Python or Ruby) as well as go-native pprof api:
// these two ways of adding tags are equivalent:pyroscope.TagWrapper(context.Background(), pyroscope.Labels("controller", "slow_controller"), func(c context.Context) { slowCode()})
pprof.Do(context.Background(), pprof.Labels("controller", "slow_controller"), func(c context.Context) { slowCode()})
#
Pull ModeGo integration supports pull mode, which means that you can profile applications without adding any extra code. For that to work you will need to make sure you have profiling routes (/debug/pprof
) enabled in your http server. Generally, that means that you need to add net/http/pprof
package:
import _ "net/http/pprof"
- For information on how to use
net/http/pprof
refer to official net/http/pprof documentation. - For more information on how to set up pyroscope server to pull data from your applications, refer to pull mode documentation.
#
Tracing IntegraitonPyroscope can integrate with distributed tracing systems supporting OpenTelemetry standard which allows you to link traces with the profiling data, and find specific lines of code related to a performance issue. For more information, refer to tracing integration documentation.
#
ExamplesCheck out the examples directory in our repository to learn more ๐ฅ