diff --git a/contrib/database/sql/metrics.go b/contrib/database/sql/metrics.go index 10a4b18566..5d662ec9c6 100644 --- a/contrib/database/sql/metrics.go +++ b/contrib/database/sql/metrics.go @@ -10,7 +10,6 @@ import ( "time" "gopkg.in/DataDog/dd-trace-go.v1/internal" - "gopkg.in/DataDog/dd-trace-go.v1/internal/contribroutines" "gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" ) @@ -34,9 +33,8 @@ var interval = 10 * time.Second // pollDBStats calls (*DB).Stats on the db at a predetermined interval. It pushes the DBStats off to the statsd client. // the caller should always ensure that db & statsd are non-nil -func pollDBStats(statsd internal.StatsdClient, db *sql.DB) { +func pollDBStats(statsd internal.StatsdClient, db *sql.DB, stop chan struct{}) { log.Debug("DB stats will be gathered and sent every %v.", interval) - stop := contribroutines.GetStopChan() ticker := time.NewTicker(interval) defer ticker.Stop() for { diff --git a/contrib/database/sql/sql.go b/contrib/database/sql/sql.go index b26318d0d3..01c0459ada 100644 --- a/contrib/database/sql/sql.go +++ b/contrib/database/sql/sql.go @@ -25,6 +25,7 @@ import ( sqlinternal "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql/internal" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" + "gopkg.in/DataDog/dd-trace-go.v1/internal/contribroutines" "gopkg.in/DataDog/dd-trace-go.v1/internal/log" "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry" ) @@ -211,7 +212,7 @@ func OpenDB(c driver.Connector, opts ...Option) *sql.DB { } db := sql.OpenDB(tc) if cfg.dbStats && cfg.statsdClient != nil { - go pollDBStats(cfg.statsdClient, db) + go pollDBStats(cfg.statsdClient, db, contribroutines.GetStopChan()) } return db }