Skip to content

Commit

Permalink
Initialize runtimeMetricsV2 with statsd "direct" client
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolebeuzon committed Dec 4, 2024
1 parent 076462a commit 818069b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,15 @@ func newTracer(opts ...StartOption) *tracer {
}
if c.runtimeMetricsV2 {
l := slog.New(slogHandler{})
if err := runtimemetrics.Start(t.statsd, l); err == nil {
l.Debug("Runtime metrics v2 enabled.")
} else {
statsdDirect, err := globalinternal.NewStatsdClientDirect(t.config.dogstatsdAddr, statsTags(t.config))
if err != nil {
l.Error("Failed to enable runtime metrics v2", "err", err.Error())
} else {
if err := runtimemetrics.Start(statsdDirect, l); err == nil {
l.Debug("Runtime metrics v2 enabled.")
} else {
l.Error("Failed to enable runtime metrics v2", "err", err.Error())
}
}
}
if c.debugAbandonedSpans {
Expand Down
16 changes: 16 additions & 0 deletions internal/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ func NewStatsdClient(addr string, globalTags []string) (StatsdClient, error) {
}
return client, nil
}

type StatsdClientDirect interface {
StatsdClient
statsd.ClientDirectInterface
}

func NewStatsdClientDirect(addr string, globalTags []string) (StatsdClientDirect, error) {
if addr == "" {
addr = DefaultDogstatsdAddr
}
client, err := statsd.NewDirect(addr, statsd.WithMaxMessagesPerPayload(40), statsd.WithTags(globalTags))
if err != nil {
return &statsd.NoOpClientDirect{}, err
}
return client, nil
}

0 comments on commit 818069b

Please sign in to comment.