Skip to content

Commit

Permalink
Return error instead of panic when creating a datadog client
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jan 25, 2024
1 parent 95fe0da commit 068426a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/mtr/mtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/artie-labs/reader/lib/logger"
)

func New(namespace string, tags []string, samplingRate float64) Client {
func New(namespace string, tags []string, samplingRate float64) (Client, error) {
host := os.Getenv("TELEMETRY_HOST")
port := os.Getenv("TELEMETRY_PORT")
address := DefaultAddr
Expand All @@ -27,16 +27,19 @@ func New(namespace string, tags []string, samplingRate float64) Client {
statsd.WithTags(tags),
)
if err != nil {
logger.Fatal("Failed to create datadog client", slog.Any("err", err))
return nil, err
}
return &statsClient{
client: datadogClient,
rate: samplingRate,
}
}, nil
}

func InjectDatadogIntoCtx(ctx context.Context, namespace string, tags []string, samplingRate float64) context.Context {
metricsClient := New(namespace, tags, samplingRate)
metricsClient, err := New(namespace, tags, samplingRate)
if err != nil {
logger.Fatal("Failed to create metrics client", slog.Any("err", err))
}
return context.WithValue(ctx, constants.MtrKey, metricsClient)
}

Expand Down

0 comments on commit 068426a

Please sign in to comment.