Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer: runtime metrics v2 (exclude from release notes) #2772

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ type config struct {
// runtimeMetrics specifies whether collection of runtime metrics is enabled.
runtimeMetrics bool

// runtimeMetricsV2 specifies whether collection of runtime metrics v2 is enabled.
runtimeMetricsV2 bool

// dogstatsdAddr specifies the address to connect for sending metrics to the
// Datadog Agent. If not set, it defaults to "localhost:8125" or to the
// combination of the environment variables DD_AGENT_HOST and DD_DOGSTATSD_PORT.
Expand Down Expand Up @@ -378,6 +381,7 @@ func newConfig(opts ...StartOption) *config {
}
c.logStartup = internal.BoolEnv("DD_TRACE_STARTUP_LOGS", true)
c.runtimeMetrics = internal.BoolVal(getDDorOtelConfig("metrics"), false)
c.runtimeMetricsV2 = internal.BoolVal("DD_RUNTIME_METRICS_V2_ENABLED", false)
c.debug = internal.BoolVal(getDDorOtelConfig("debugMode"), false)
c.enabled = newDynamicConfig("tracing_enabled", internal.BoolVal(getDDorOtelConfig("enabled"), true), func(b bool) bool { return true }, equal[bool])
if _, ok := os.LookupEnv("DD_TRACE_ENABLED"); ok {
Expand Down
64 changes: 64 additions & 0 deletions ddtrace/tracer/slog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package tracer

import (
"context"
"log/slog"
"strings"

"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

// slogHandler implements the slog.Handler interface to dispatch messages to our
// internal logger.
type slogHandler struct {
attrs []string
groups []string
}

func (h slogHandler) Enabled(ctx context.Context, lvl slog.Level) bool {
if lvl <= slog.LevelDebug {
return log.DebugEnabled()
}
// TODO(fg): Implement generic log level checking in the internal logger.
// But we're we're not concerned with slog perf, so this is okay for now.
return true
}

func (h slogHandler) Handle(ctx context.Context, r slog.Record) error {
parts := make([]string, 0, 1+len(h.attrs)+r.NumAttrs())
parts = append(parts, r.Message)
parts = append(parts, h.attrs...)
r.Attrs(func(a slog.Attr) bool {
parts = append(parts, formatAttr(a, h.groups))
return true
})

msg := strings.Join(parts, " ")
switch r.Level {
case slog.LevelDebug:
log.Debug(msg)
case slog.LevelInfo:
log.Info(msg)
case slog.LevelWarn:
log.Warn(msg)
case slog.LevelError:
log.Error(msg)
}
return nil
}

func (h slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
for _, a := range attrs {
h.attrs = append(h.attrs, formatAttr(a, h.groups))
}
return h
}

func (h slogHandler) WithGroup(name string) slog.Handler {
h.groups = append(h.groups, name)
return h
}

func formatAttr(a slog.Attr, groups []string) string {
return strings.Join(append(groups, a.String()), ".")
}
33 changes: 33 additions & 0 deletions ddtrace/tracer/slog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tracer

import (
"log/slog"
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

func Test_slogHandler(t *testing.T) {
// Create a record logger to capture the logs and restore the original
// logger at the end.
rl := &log.RecordLogger{}
defer log.UseLogger(rl)()

// Log a few messages at different levels. The debug message gets discarded
// because the internal logger does not have debug enabled by default.
l := slog.New(slogHandler{})
l = l.With("foo", "bar")
l = l.WithGroup("a").WithGroup("b")
l.Debug("debug test", "n", 0)
l.Info("info test", "n", 1)
l.Warn("warn test", "n", 2)
l.Error("error test", "n", 3)
log.Flush() // needed to get the error log flushed

// Check that the logs were written correctly.
require.Len(t, rl.Logs(), 3)
require.Contains(t, rl.Logs()[0], "info test foo=bar a.b.n=1")
require.Contains(t, rl.Logs()[1], "warn test foo=bar a.b.n=2")
require.Contains(t, rl.Logs()[2], "error test foo=bar a.b.n=3")
}
1 change: 1 addition & 0 deletions ddtrace/tracer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func startTelemetry(c *config) {
{Name: "agent_url", Value: c.agentURL.String()},
{Name: "agent_hostname", Value: c.hostname},
{Name: "runtime_metrics_enabled", Value: c.runtimeMetrics},
{Name: "runtime_metrics_v2_enabled", Value: c.runtimeMetricsV2},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: I think we also have a startup logging thing somewhere that tries to log all the config values. check if we need to log runtimeMetricsV2 there as well.

{Name: "dogstatsd_addr", Value: c.dogstatsdAddr},
{Name: "debug_stack_enabled", Value: !c.noDebugStack},
{Name: "profiling_hotspots_enabled", Value: c.profilerHotspots},
Expand Down
10 changes: 10 additions & 0 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package tracer
import (
gocontext "context"
"encoding/binary"
"log/slog"
"math"
"os"
"runtime/pprof"
Expand All @@ -32,6 +33,7 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/internal/traceprof"

"github.com/DataDog/datadog-agent/pkg/obfuscate"
"github.com/DataDog/go-runtime-metrics-internal/pkg/runtimemetrics"
)

var _ ddtrace.Tracer = (*tracer)(nil)
Expand Down Expand Up @@ -309,6 +311,14 @@ func newTracer(opts ...StartOption) *tracer {
t.reportRuntimeMetrics(defaultMetricsReportInterval)
}()
}
if c.runtimeMetricsV2 {
l := slog.New(slogHandler{})
if err := runtimemetrics.Start(t.statsd, l); err == nil {
l.Debug("Runtime metrics v2 enabled.")
} else {
l.Error("Failed to enable runtime metrics v2", "err", err.Error())
}
}
if c.debugAbandonedSpans {
log.Info("Abandoned spans logs enabled.")
t.abandonedSpansDebugger = newAbandonedSpansDebugger()
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,7 @@ func BenchmarkGenSpanID(b *testing.B) {

// startTestTracer returns a Tracer with a DummyTransport
func startTestTracer(t testing.TB, opts ...StartOption) (trc *tracer, transport *dummyTransport, flush func(n int), stop func()) {
oldLevel := log.GetLevel()
transport = newDummyTransport()
tick := make(chan time.Time)
o := append([]StartOption{
Expand Down Expand Up @@ -2160,6 +2161,7 @@ func startTestTracer(t testing.TB, opts ...StartOption) (trc *tracer, transport
tracer.Stop()
// clear any service name that was set: we want the state to be the same as startup
globalconfig.SetServiceName("")
log.SetLevel(oldLevel) // avoids test failures because of global state
}
}

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.48.1
github.com/DataDog/datadog-go/v5 v5.3.0
github.com/DataDog/go-libddwaf/v3 v3.3.0
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5
github.com/DataDog/gostackparse v0.7.0
github.com/DataDog/sketches-go v1.4.5
github.com/IBM/sarama v1.40.0
Expand Down Expand Up @@ -95,7 +96,7 @@ require (
go.opentelemetry.io/otel v1.20.0
go.opentelemetry.io/otel/trace v1.20.0
go.uber.org/atomic v1.11.0
golang.org/x/mod v0.14.0
golang.org/x/mod v0.16.0
golang.org/x/oauth2 v0.9.0
golang.org/x/sys v0.20.0
golang.org/x/time v0.3.0
Expand Down Expand Up @@ -260,10 +261,10 @@ require (
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ github.com/DataDog/datadog-go/v5 v5.3.0 h1:2q2qjFOb3RwAZNU+ez27ZVDwErJv5/VpbBPpr
github.com/DataDog/datadog-go/v5 v5.3.0/go.mod h1:XRDJk1pTc00gm+ZDiBKsjh7oOOtJfYfglVCmFb8C2+Q=
github.com/DataDog/go-libddwaf/v3 v3.3.0 h1:jS72fuQpFgJZEdEJDmHJCPAgNTEMZoz1EUvimPUOiJ4=
github.com/DataDog/go-libddwaf/v3 v3.3.0/go.mod h1:Bz/0JkpGf689mzbUjKJeheJINqsyyhM8p9PDuHdK2Ec=
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5 h1:2S3vDq1CtlmVMdq0+7TIwYKUSDJmBEsaB9gdnGI52yE=
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5/go.mod h1:quaQJ+wPN41xEC458FCpTwyROZm3MzmTZ8q8XOXQiPs=
github.com/DataDog/go-tuf v1.0.2-0.5.2 h1:EeZr937eKAWPxJ26IykAdWA4A0jQXJgkhUjqEI/w7+I=
github.com/DataDog/go-tuf v1.0.2-0.5.2/go.mod h1:zBcq6f654iVqmkk8n2Cx81E1JnNTMOAx1UEO/wZR+P0=
github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4=
Expand Down Expand Up @@ -2284,8 +2286,8 @@ golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -2420,8 +2422,8 @@ golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -2693,8 +2695,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
5 changes: 5 additions & 0 deletions internal/apps/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func (c Config) RunHTTP(handler func() http.Handler) {
os.Setenv("DD_PROFILING_EXECUTION_TRACE_PERIOD", "1s")
}

// Enabled runtime metrics v2 by default
if v := os.Getenv("DD_RUNTIME_METRICS_V2_ENABLED"); v == "" {
os.Setenv("DD_RUNTIME_METRICS_V2_ENABLED", "true")
}

// Setup context that gets canceled on receiving SIGINT
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
Expand Down
7 changes: 4 additions & 3 deletions internal/apps/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module github.com/DataDog/dd-trace-go/internal/apps
go 1.21

require (
golang.org/x/sync v0.5.0
golang.org/x/sync v0.6.0
gopkg.in/DataDog/dd-trace-go.v1 v1.64.0
)

require (
github.com/DataDog/appsec-internal-go v1.7.0 // indirect
github.com/DataDog/go-libddwaf/v3 v3.3.0 // indirect
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect
github.com/ebitengine/purego v0.6.0-alpha.5 // indirect
Expand All @@ -23,8 +24,8 @@ require (
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
14 changes: 8 additions & 6 deletions internal/apps/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/DataDog/datadog-go/v5 v5.3.0 h1:2q2qjFOb3RwAZNU+ez27ZVDwErJv5/VpbBPpr
github.com/DataDog/datadog-go/v5 v5.3.0/go.mod h1:XRDJk1pTc00gm+ZDiBKsjh7oOOtJfYfglVCmFb8C2+Q=
github.com/DataDog/go-libddwaf/v3 v3.3.0 h1:jS72fuQpFgJZEdEJDmHJCPAgNTEMZoz1EUvimPUOiJ4=
github.com/DataDog/go-libddwaf/v3 v3.3.0/go.mod h1:Bz/0JkpGf689mzbUjKJeheJINqsyyhM8p9PDuHdK2Ec=
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5 h1:2S3vDq1CtlmVMdq0+7TIwYKUSDJmBEsaB9gdnGI52yE=
github.com/DataDog/go-runtime-metrics-internal v0.0.0-20240819080326-9964da68e4b5/go.mod h1:quaQJ+wPN41xEC458FCpTwyROZm3MzmTZ8q8XOXQiPs=
github.com/DataDog/go-tuf v1.0.2-0.5.2 h1:EeZr937eKAWPxJ26IykAdWA4A0jQXJgkhUjqEI/w7+I=
github.com/DataDog/go-tuf v1.0.2-0.5.2/go.mod h1:zBcq6f654iVqmkk8n2Cx81E1JnNTMOAx1UEO/wZR+P0=
github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4=
Expand Down Expand Up @@ -135,8 +137,8 @@ golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOM
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand All @@ -147,8 +149,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -178,8 +180,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
7 changes: 7 additions & 0 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func SetLevel(lvl Level) {
level = lvl
}

// GetLevel returns the currrent log level.
func GetLevel() Level {
mu.Lock()
defer mu.Unlock()
return level
}

// DebugEnabled returns true if debug log messages are enabled. This can be used in extremely
// hot code paths to avoid allocating the ...interface{} argument.
func DebugEnabled() bool {
Expand Down
2 changes: 2 additions & 0 deletions internal/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const DefaultDogstatsdAddr = "localhost:8125"
type StatsdClient interface {
Incr(name string, tags []string, rate float64) error
Count(name string, value int64, tags []string, rate float64) error
CountWithTimestamp(name string, value int64, tags []string, rate float64, timestamp time.Time) error
Gauge(name string, value float64, tags []string, rate float64) error
GaugeWithTimestamp(name string, value float64, tags []string, rate float64, timestamp time.Time) error
Timing(name string, value time.Duration, tags []string, rate float64) error
Flush() error
Close() error
Expand Down
8 changes: 8 additions & 0 deletions internal/statsdtest/statsdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (tg *TestStatsdClient) Gauge(name string, value float64, tags []string, rat
})
}

func (tg *TestStatsdClient) GaugeWithTimestamp(name string, value float64, tags []string, rate float64, timestamp time.Time) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
unused-parameter: parameter 'name' seems to be unused, consider removing or renaming it as _ (revive)

panic("not implemented yet")
}

func (tg *TestStatsdClient) Incr(name string, tags []string, rate float64) error {
tg.addCount(name, 1)
return tg.addMetric(callTypeIncr, tags, TestStatsdCall{
Expand All @@ -81,6 +85,10 @@ func (tg *TestStatsdClient) Count(name string, value int64, tags []string, rate
})
}

func (tg *TestStatsdClient) CountWithTimestamp(name string, value int64, tags []string, rate float64, timestamp time.Time) error {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
unused-parameter: parameter 'name' seems to be unused, consider removing or renaming it as _ (revive)

panic("not implemented yet")
}

func (tg *TestStatsdClient) Timing(name string, value time.Duration, tags []string, rate float64) error {
return tg.addMetric(callTypeTiming, tags, TestStatsdCall{
name: name,
Expand Down
Loading