From 94520581911c3d69205f212a7e9af0615ae4b32b Mon Sep 17 00:00:00 2001 From: Andrii Zakharov Date: Thu, 2 Jul 2020 12:00:39 +0200 Subject: [PATCH] feat: Add DataDog profiler --- pkg/instrumentation/profiler.go | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/instrumentation/profiler.go diff --git a/pkg/instrumentation/profiler.go b/pkg/instrumentation/profiler.go new file mode 100644 index 00000000..11aa48d5 --- /dev/null +++ b/pkg/instrumentation/profiler.go @@ -0,0 +1,38 @@ +package instrumentation + +import "gopkg.in/DataDog/dd-trace-go.v1/profiler" + +// Profiler wraps DataDog profiles exporter. +type Profiler struct { + enabled bool + start func(options ...profiler.Option) error + stop func() + options []profiler.Option +} + +// Start calls DD profiler with options set during Profiler construction. +func (p *Profiler) Start() error { + if !p.enabled { + return nil + } + + return p.start(p.options...) +} + +// Stop DataDog profiles exporter. +func (p *Profiler) Stop() { + p.stop() +} + +// NewProfiler constructs new profiler with options. +// You can include common options like: profiler.WithService(appName), profiler.WithVersion(version). +func NewProfiler(config *Config, options ...profiler.Option) *Profiler { + options = append(options, profiler.WithEnv(config.environment)) + + return &Profiler{ + enabled: config.Enabled, + start: profiler.Start, + stop: profiler.Stop, + options: options, + } +}