pyroscope

package
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 10 Imported by: 0

README

Pyroscope Component

Grafana Pyroscope continuous profiling integration for Go services.

Built on github.com/grafana/pyroscope-go.

Installation

go get github.com/pubgo/funk/v2/component/pyroscope

Quick Start

import (
    "github.com/pubgo/funk/v2/component/lifecycle"
    "github.com/pubgo/funk/v2/component/pyroscope"
    "github.com/pubgo/funk/v2/log"
)

func main() {
    lc := /* lifecycle from your app */
    client := pyroscope.New(pyroscope.Param{
        Cfg: &pyroscope.Config{
            Enabled:       true,
            ServerAddress: "http://pyroscope:4040",
        },
        Logger: log.GetLogger("app"),
        Lc:     lc,
    })
    _ = client

    pyroscope.TagWrapper(ctx, pyroscope.Labels("handler", "CreateOrder"), func(ctx context.Context) {
        // profiled code
    })
}

Configuration

Field Description
enabled Turn profiling on/off
application_name Pyroscope app name (default: {project}/{version})
server_address Pyroscope server URL
basic_auth_user / basic_auth_password HTTP basic auth (Grafana Cloud)
tenant_id Multi-tenant Pyroscope ID
upload_rate Profile upload interval (default: 1m)
profile_types CPU, heap, goroutine, etc. (defaults match pyroscope-go)
tags Extra labels merged with hostname/env/version/instance_id
disable_gc_runs Pass through to pyroscope-go
disable_log Silence pyroscope client logs

Example YAML:

pyroscope:
  enabled: true
  server_address: http://pyroscope:4040
  application_name: my-service
  profile_types:
    - cpu
    - alloc_objects
    - inuse_objects
  tags:
    team: platform

Lifecycle

When Param.Lc is set, BeforeStop calls profiler.Stop() to flush remaining profiles on shutdown.

Profiling Tags

Use TagWrapper or Labels (re-exported from pyroscope-go) to attach labels to hot paths:

pyroscope.TagWrapper(ctx, pyroscope.Labels("controller", "slow"), func(ctx context.Context) {
    handleSlowPath(ctx)
})

Pull Mode

For pull-based profiling, enable net/http/pprof in your HTTP server; no push client is required. See Pyroscope Go SDK docs.

Example

# requires a running Pyroscope server
PYROSCOPE_SERVER=http://localhost:4040 go run ./component/pyroscope/example

Documentation

Index

Constants

View Source
const Name = "pyroscope"

Variables

Functions

func TagWrapper

func TagWrapper(ctx context.Context, labels LabelSet, cb func(context.Context))

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(p Param) *Client

func (*Client) Enabled

func (c *Client) Enabled() bool

func (*Client) Flush

func (c *Client) Flush(wait bool)

func (*Client) Profiler

func (c *Client) Profiler() *pyroscope.Profiler

type Config

type Config struct {
	Enabled           bool              `yaml:"enabled"`
	ApplicationName   string            `yaml:"application_name"`
	ServerAddress     string            `yaml:"server_address"`
	BasicAuthUser     string            `yaml:"basic_auth_user"`
	BasicAuthPassword string            `yaml:"basic_auth_password"`
	TenantID          string            `yaml:"tenant_id"`
	UploadRate        time.Duration     `yaml:"upload_rate"`
	ProfileTypes      []string          `yaml:"profile_types"`
	Tags              map[string]string `yaml:"tags"`
	DisableGCRuns     bool              `yaml:"disable_gc_runs"`
	DisableLog        bool              `yaml:"disable_log"`
}

func DefaultConfig

func DefaultConfig() *Config

type LabelSet

type LabelSet = pyroscope.LabelSet

type Param

type Param struct {
	Cfg    *Config
	Logger log.Logger
	Lc     lifecycle.Lifecycle
}

Directories

Path Synopsis
Minimal push-mode profiling example.
Minimal push-mode profiling example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL