Skip to content

Commit

Permalink
feat: Add DataDog profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
andriiiz committed Jul 21, 2020
1 parent e2ae105 commit 9452058
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/instrumentation/profiler.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit 9452058

Please sign in to comment.