Skip to content

Commit

Permalink
Add datadog apm support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzhuojie committed Jan 29, 2019
1 parent c4188c6 commit 6aed959
Show file tree
Hide file tree
Showing 61 changed files with 10,901 additions and 18 deletions.
239 changes: 225 additions & 14 deletions Gopkg.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions pkg/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ var Config = struct {
NewRelicKey string `env:"FLAGR_NEWRELIC_KEY" envDefault:""`

// StatsdEnabled - enable statsd metrics for all the endpoints and DB operations
StatsdEnabled bool `env:"FLAGR_STATSD_ENABLED" envDefault:"false"`
StatsdHost string `env:"FLAGR_STATSD_HOST" envDefault:"127.0.0.1"`
StatsdPort string `env:"FLAGR_STATSD_PORT" envDefault:"8125"`
StatsdPrefix string `env:"FLAGR_STATSD_PREFIX" envDefault:"flagr."`
StatsdEnabled bool `env:"FLAGR_STATSD_ENABLED" envDefault:"false"`
StatsdHost string `env:"FLAGR_STATSD_HOST" envDefault:"127.0.0.1"`
StatsdPort string `env:"FLAGR_STATSD_PORT" envDefault:"8125"`
StatsdPrefix string `env:"FLAGR_STATSD_PREFIX" envDefault:"flagr."`
StatsdAPMEnabled bool `env:"FLAGR_STATSD_APM_ENABLED" envDefault:"false"`
StatsdAPMPort string `env:"FLAGR_STATSD_APM_PORT" envDefault:"8126"`
StatsdAPMServiceName string `env:"FLAGR_STATSD_APM_SERVICE_NAME" envDefault:"flagr"`

// RecorderEnabled - enable data records logging
RecorderEnabled bool `env:"FLAGR_RECORDER_ENABLED" envDefault:"false"`
Expand Down
16 changes: 16 additions & 0 deletions pkg/config/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/negroni"
"github.com/yadvendar/negroni-newrelic-go-agent"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

// ServerShutdown is a callback function that will be called when
// we tear down the flagr server
func ServerShutdown() {
if Config.StatsdEnabled && Config.StatsdAPMEnabled {
tracer.Stop()
}
}

// SetupGlobalMiddleware setup the global middleware
func SetupGlobalMiddleware(handler http.Handler) http.Handler {
n := negroni.New()
Expand All @@ -33,6 +42,13 @@ func SetupGlobalMiddleware(handler http.Handler) http.Handler {

if Config.StatsdEnabled {
n.Use(&statsdMiddleware{StatsdClient: Global.StatsdClient})

if Config.StatsdAPMEnabled {
tracer.Start(
tracer.WithAgentAddr(fmt.Sprintf("%s:%s", Config.StatsdHost, Config.StatsdAPMPort)),
tracer.WithServiceName(Config.StatsdAPMServiceName),
)
}
}

if Config.NewRelicEnabled {
Expand Down
1 change: 1 addition & 0 deletions swagger_gen/restapi/configure_flagr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/philhofer/fwd/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

315 changes: 315 additions & 0 deletions vendor/github.com/philhofer/fwd/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6aed959

Please sign in to comment.