Skip to content

Commit

Permalink
refactor(internal/log): add (Debug|Info|Warn|Error)F variants and acc…
Browse files Browse the repository at this point in the history
…ept only a string in non-F variants
  • Loading branch information
darccio committed Dec 17, 2024
1 parent 1fcfcf3 commit 0e76e64
Show file tree
Hide file tree
Showing 116 changed files with 389 additions and 353 deletions.
6 changes: 3 additions & 3 deletions contrib/IBM/sarama.v1/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/IBM/sarama: Wrapping Partition Consumer: %#v", cfg)
log.Debugf("contrib/IBM/sarama: Wrapping Partition Consumer: %#v", cfg)
wrapped := &partitionConsumer{
PartitionConsumer: pc,
messages: make(chan *sarama.ConsumerMessage),
Expand Down Expand Up @@ -170,7 +170,7 @@ func WrapSyncProducer(saramaConfig *sarama.Config, producer sarama.SyncProducer,
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/IBM/sarama: Wrapping Sync Producer: %#v", cfg)
log.Debugf("contrib/IBM/sarama: Wrapping Sync Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func WrapAsyncProducer(saramaConfig *sarama.Config, p sarama.AsyncProducer, opts
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/IBM/sarama: Wrapping Async Producer: %#v", cfg)
log.Debugf("contrib/IBM/sarama: Wrapping Async Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
saramaConfig.Version = sarama.V0_11_0_0
Expand Down
6 changes: 3 additions & 3 deletions contrib/Shopify/sarama/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Partition Consumer: %#v", cfg)
log.Debugf("contrib/Shopify/sarama: Wrapping Partition Consumer: %#v", cfg)
wrapped := &partitionConsumer{
PartitionConsumer: pc,
messages: make(chan *sarama.ConsumerMessage),
Expand Down Expand Up @@ -173,7 +173,7 @@ func WrapSyncProducer(saramaConfig *sarama.Config, producer sarama.SyncProducer,
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Sync Producer: %#v", cfg)
log.Debugf("contrib/Shopify/sarama: Wrapping Sync Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func WrapAsyncProducer(saramaConfig *sarama.Config, p sarama.AsyncProducer, opts
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Async Producer: %#v", cfg)
log.Debugf("contrib/Shopify/sarama: Wrapping Async Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
saramaConfig.Version = sarama.V0_11_0_0
Expand Down
2 changes: 1 addition & 1 deletion contrib/aws/aws-sdk-go-v2/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (mw *traceMiddleware) startTraceMiddleware(stack *middleware.Stack) error {
}
k, v, err := resourceNameFromParams(in, serviceID)
if err != nil {
log.Debug("Error: %v", err)
log.Debugf("Error: %v", err)
} else {
opts = append(opts, tracer.Tag(k, v))
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/aws/aws-sdk-go/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func WrapSession(s *session.Session, opts ...Option) *session.Session {
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/aws/aws-sdk-go/aws: Wrapping Session: %#v", cfg)
log.Debugf("contrib/aws/aws-sdk-go/aws: Wrapping Session: %#v", cfg)
h := &handlers{cfg: cfg}
s = s.Copy()
s.Handlers.Send.PushFrontNamed(request.NamedHandler{
Expand Down Expand Up @@ -183,7 +183,7 @@ func extraTagsForService(req *request.Request) map[string]interface{} {
return nil
}
if err != nil {
log.Debug("failed to extract tags for AWS service %q: %v", service, err)
log.Debugf("failed to extract tags for AWS service %q: %v", service, err)
return nil
}
return extraTags
Expand Down
9 changes: 5 additions & 4 deletions contrib/aws/internal/eventbridge/eventbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ package eventbridge
import (
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eventbridge"
"github.com/aws/aws-sdk-go-v2/service/eventbridge/types"
"github.com/aws/smithy-go/middleware"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"strconv"
"time"
)

const (
Expand Down Expand Up @@ -43,7 +44,7 @@ func handlePutEvents(span tracer.Span, in middleware.InitializeInput) {
carrier := tracer.TextMapCarrier{}
err := tracer.Inject(span.Context(), carrier)
if err != nil {
log.Debug("Unable to inject trace context: %s", err)
log.Debugf("Unable to inject trace context: %s", err)
return
}

Expand All @@ -53,7 +54,7 @@ func handlePutEvents(span tracer.Span, in middleware.InitializeInput) {

carrierJSON, err := json.Marshal(carrier)
if err != nil {
log.Debug("Unable to marshal trace context: %s", err)
log.Debugf("Unable to marshal trace context: %s", err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/aws/internal/sfn/sfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func injectTraceContext(span tracer.Span, input *string) *string {
}
traceCtxCarrier := tracer.TextMapCarrier{}
if err := tracer.Inject(span.Context(), traceCtxCarrier); err != nil {
log.Debug("Unable to inject trace context: %s", err)
log.Debugf("Unable to inject trace context: %s", err)
return input
}

traceCtxJSON, err := json.Marshal(traceCtxCarrier)
if err != nil {
log.Debug("Unable to marshal trace context: %s", err)
log.Debugf("Unable to marshal trace context: %s", err)
return input
}

Expand Down
7 changes: 4 additions & 3 deletions contrib/aws/internal/sns/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package sns

import (
"encoding/json"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sns"
"github.com/aws/aws-sdk-go-v2/service/sns/types"
Expand All @@ -32,13 +33,13 @@ func EnrichOperation(span tracer.Span, in middleware.InitializeInput, operation
func handlePublish(span tracer.Span, in middleware.InitializeInput) {
params, ok := in.Parameters.(*sns.PublishInput)
if !ok {
log.Debug("Unable to read PublishInput params")
log.Debugf("Unable to read PublishInput params")
return
}

traceContext, err := getTraceContext(span)
if err != nil {
log.Debug("Unable to get trace context: %s", err.Error())
log.Debugf("Unable to get trace context: %s", err.Error())
return
}

Expand All @@ -58,7 +59,7 @@ func handlePublishBatch(span tracer.Span, in middleware.InitializeInput) {

traceContext, err := getTraceContext(span)
if err != nil {
log.Debug("Unable to get trace context: %s", err.Error())
log.Debugf("Unable to get trace context: %s", err.Error())
return
}

Expand Down
5 changes: 3 additions & 2 deletions contrib/aws/internal/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package sqs

import (
"encoding/json"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/sqs"
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
Expand Down Expand Up @@ -38,7 +39,7 @@ func handleSendMessage(span tracer.Span, in middleware.InitializeInput) {

traceContext, err := getTraceContext(span)
if err != nil {
log.Debug("Unable to get trace context: %s", err.Error())
log.Debugf("Unable to get trace context: %s", err.Error())
return
}

Expand All @@ -58,7 +59,7 @@ func handleSendMessageBatch(span tracer.Span, in middleware.InitializeInput) {

traceContext, err := getTraceContext(span)
if err != nil {
log.Debug("Unable to get trace context: %s", err.Error())
log.Debugf("Unable to get trace context: %s", err.Error())
return
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/bradfitz/gomemcache/memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func WrapClient(client *memcache.Client, opts ...ClientOption) *Client {
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/bradfitz/gomemcache/memcache: Wrapping Client: %#v", cfg)
log.Debugf("contrib/bradfitz/gomemcache/memcache: Wrapping Client: %#v", cfg)
return &Client{
Client: client,
cfg: cfg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TracePublish(ctx context.Context, topic Topic, msg *Message, opts ...Option
msg.Attributes = make(map[string]string)
}
if err := tracer.Inject(span.Context(), tracer.TextMapCarrier(msg.Attributes)); err != nil {
log.Debug("contrib/cloud.google.com/go/pubsub.v1/trace: failed injecting tracing attributes: %v", err)
log.Debugf("contrib/cloud.google.com/go/pubsub.v1/trace: failed injecting tracing attributes: %v", err)
}
span.SetTag("num_attributes", len(msg.Attributes))

Expand All @@ -96,7 +96,7 @@ func TraceReceiveFunc(s Subscription, opts ...Option) func(ctx context.Context,
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/cloud.google.com/go/pubsub.v1/trace: Wrapping Receive Handler: %#v", cfg)
log.Debugf("contrib/cloud.google.com/go/pubsub.v1/trace: Wrapping Receive Handler: %#v", cfg)
return func(ctx context.Context, msg *Message) (context.Context, func()) {
parentSpanCtx, _ := tracer.Extract(tracer.TextMapCarrier(msg.Attributes))
opts := []ddtrace.StartSpanOption{
Expand Down
4 changes: 2 additions & 2 deletions contrib/confluentinc/confluent-kafka-go/kafka.v2/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func WrapConsumer(c *kafka.Consumer, opts ...Option) *Consumer {
Consumer: c,
tracer: newKafkaTracer(opts...),
}
log.Debug("%s: Wrapping Consumer: %#v", logPrefix, wrapped.tracer)
log.Debugf("%s: Wrapping Consumer: %#v", logPrefix, wrapped.tracer)
wrapped.events = tracing.WrapConsumeEventsChannel(wrapped.tracer, c.Events(), c, wrapEvent)
return wrapped
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func WrapProducer(p *kafka.Producer, opts ...Option) *Producer {
tracer: newKafkaTracer(opts...),
events: p.Events(),
}
log.Debug("%s: Wrapping Producer: %#v", logPrefix, wrapped.tracer)
log.Debugf("%s: Wrapping Producer: %#v", logPrefix, wrapped.tracer)
wrapped.produceChannel = tracing.WrapProduceChannel(wrapped.tracer, p.ProduceChannel(), wrapMessage)
if wrapped.tracer.DSMEnabled() {
wrapped.events = tracing.WrapProduceEventsChannel(wrapped.tracer, p.Events(), wrapEvent)
Expand Down
4 changes: 2 additions & 2 deletions contrib/confluentinc/confluent-kafka-go/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func WrapConsumer(c *kafka.Consumer, opts ...Option) *Consumer {
Consumer: c,
tracer: newKafkaTracer(opts...),
}
log.Debug("%s: Wrapping Consumer: %#v", logPrefix, wrapped.tracer)
log.Debugf("%s: Wrapping Consumer: %#v", logPrefix, wrapped.tracer)
wrapped.events = tracing.WrapConsumeEventsChannel(wrapped.tracer, c.Events(), c, wrapEvent)
return wrapped
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func WrapProducer(p *kafka.Producer, opts ...Option) *Producer {
tracer: newKafkaTracer(opts...),
events: p.Events(),
}
log.Debug("%s: Wrapping Producer: %#v", logPrefix, wrapped.tracer)
log.Debugf("%s: Wrapping Producer: %#v", logPrefix, wrapped.tracer)
wrapped.produceChannel = tracing.WrapProduceChannel(wrapped.tracer, p.ProduceChannel(), wrapMessage)
if wrapped.tracer.DSMEnabled() {
wrapped.events = tracing.WrapProduceEventsChannel(wrapped.tracer, p.Events(), wrapEvent)
Expand Down
2 changes: 1 addition & 1 deletion contrib/database/sql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (tc *TracedConn) injectComments(ctx context.Context, query string, mode tra
carrier := tracer.SQLCommentCarrier{Query: query, Mode: mode, DBServiceName: tc.cfg.serviceName, PeerDBHostname: tc.meta[ext.TargetHost], PeerDBName: tc.meta[ext.DBName], PeerService: tc.providedPeerService(ctx)}
if err := carrier.Inject(spanCtx); err != nil {
// this should never happen
log.Warn("contrib/database/sql: failed to inject query comments: %v", err)
log.Warnf("contrib/database/sql: failed to inject query comments: %v", err)
}
return carrier.Query, carrier.SpanID
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/database/sql/internal/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ func ParseDSN(driverName, dsn string) (meta map[string]string, err error) {
case "mysql":
meta, err = parseMySQLDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for mysql: %v", err)
log.Debugf("Error parsing DSN for mysql: %v", err)
return
}
case "postgres", "pgx":
meta, err = parsePostgresDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for postgres: %v", err)
log.Debugf("Error parsing DSN for postgres: %v", err)
return
}
case "sqlserver":
meta, err = parseSQLServerDSN(dsn)
if err != nil {
log.Debug("Error parsing DSN for sqlserver: %v", err)
log.Debugf("Error parsing DSN for sqlserver: %v", err)
return
}
default:
// Try to parse the DSN and see if the scheme contains a known driver name.
u, e := url.Parse(dsn)
if e != nil {
// dsn is not a valid URL, so just ignore
log.Debug("Error parsing driver name from DSN: %v", e)
log.Debugf("Error parsing driver name from DSN: %v", e)
return
}
if driverName != u.Scheme {
Expand Down
2 changes: 1 addition & 1 deletion contrib/database/sql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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) {
log.Debug("DB stats will be gathered and sent every %v.", interval)
log.Debugf("DB stats will be gathered and sent every %v.", interval)
for range time.NewTicker(interval).C {
log.Debug("Reporting DB.Stats metrics...")
stat := db.Stats()
Expand Down
6 changes: 3 additions & 3 deletions contrib/database/sql/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (c *config) checkStatsdRequired() {
sc, err := internal.NewStatsdClient(globalconfig.DogstatsdAddr(), statsTags(c))
if err == nil {
c.statsdClient = sc
log.Debug("Metrics from the database/sql contrib will be sent to %v", globalconfig.DogstatsdAddr())
log.Debugf("Metrics from the database/sql contrib will be sent to %v", globalconfig.DogstatsdAddr())
} else {
log.Warn("Error creating statsd client for database/sql contrib; DB Stats disabled: %v", err)
log.Warnf("Error creating statsd client for database/sql contrib; DB Stats disabled: %v", err)
c.dbStats = false
}
}
Expand All @@ -57,7 +57,7 @@ func (c *config) checkDBMPropagation(driverName string, driver driver.Driver, ds
dsn = c.dsn
}
if dbSystem, ok := dbmFullModeUnsupported(driverName, driver, dsn); ok {
log.Warn("Using DBM_PROPAGATION_MODE in 'full' mode is not supported for %s, downgrading to 'service' mode. "+
log.Warnf("Using DBM_PROPAGATION_MODE in 'full' mode is not supported for %s, downgrading to 'service' mode. "+
"See https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info.",
dbSystem,
)
Expand Down
2 changes: 1 addition & 1 deletion contrib/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func Register(driverName string, driver driver.Driver, opts ...RegisterOption) {
cfg := new(config)
defaults(cfg, driverName, nil)
processOptions(cfg, driverName, driver, "", opts...)
log.Debug("contrib/database/sql: Registering driver: %s %#v", driverName, cfg)
log.Debugf("contrib/database/sql: Registering driver: %s %#v", driverName, cfg)
registeredDrivers.add(driverName, driver, cfg)
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/dimfeld/httptreemux.v5/httptreemux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func New(opts ...RouterOption) *Router {
cfg.spanOpts = append(cfg.spanOpts, tracer.Measured())
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.SpanKind, ext.SpanKindServer))
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.Component, componentName))
log.Debug("contrib/dimfeld/httptreemux.v5: Configuring Router: %#v", cfg)
log.Debugf("contrib/dimfeld/httptreemux.v5: Configuring Router: %#v", cfg)
return &Router{httptreemux.New(), cfg}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func NewWithContext(opts ...RouterOption) *ContextRouter {
cfg.spanOpts = append(cfg.spanOpts, tracer.Measured())
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.SpanKind, ext.SpanKindServer))
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.Component, componentName))
log.Debug("contrib/dimfeld/httptreemux.v5: Configuring ContextRouter: %#v", cfg)
log.Debugf("contrib/dimfeld/httptreemux.v5: Configuring ContextRouter: %#v", cfg)
return &ContextRouter{httptreemux.NewContextMux(), cfg}
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/emicklei/go-restful.v3/restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func FilterFunc(configOpts ...Option) restful.FilterFunction {
for _, opt := range configOpts {
opt(cfg)
}
log.Debug("contrib/emicklei/go-restful/v3: Creating tracing filter: %#v", cfg)
log.Debugf("contrib/emicklei/go-restful/v3: Creating tracing filter: %#v", cfg)
spanOpts := []ddtrace.StartSpanOption{tracer.ServiceName(cfg.serviceName)}
return func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
spanOpts := append(
Expand Down
2 changes: 1 addition & 1 deletion contrib/emicklei/go-restful/restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func FilterFunc(configOpts ...Option) restful.FilterFunction {
for _, opt := range configOpts {
opt(cfg)
}
log.Debug("contrib/emicklei/go-restful: Creating tracing filter: %#v", cfg)
log.Debugf("contrib/emicklei/go-restful: Creating tracing filter: %#v", cfg)
spanOpts := []ddtrace.StartSpanOption{tracer.ServiceName(cfg.serviceName)}
return func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
spanOpts := append(spanOpts, tracer.ResourceName(req.SelectedRoutePath()))
Expand Down
4 changes: 2 additions & 2 deletions contrib/garyburd/redigo/redigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseOptions(options ...interface{}) ([]redis.DialOption, *dialConfig) {
// The set of supported options must be either of type redis.DialOption or this package's DialOption.
func Dial(network, address string, options ...interface{}) (redis.Conn, error) {
dialOpts, cfg := parseOptions(options...)
log.Debug("contrib/garyburd/redigo: Dialing %s %s, %#v", network, address, cfg)
log.Debugf("contrib/garyburd/redigo: Dialing %s %s, %#v", network, address, cfg)
c, err := redis.Dial(network, address, dialOpts...)
if err != nil {
return nil, err
Expand All @@ -86,7 +86,7 @@ func Dial(network, address string, options ...interface{}) (redis.Conn, error) {
// The returned redis.Conn is traced.
func DialURL(rawurl string, options ...interface{}) (redis.Conn, error) {
dialOpts, cfg := parseOptions(options...)
log.Debug("contrib/garyburd/redigo: Dialing %s, %#v", rawurl, cfg)
log.Debugf("contrib/garyburd/redigo: Dialing %s, %#v", rawurl, cfg)
u, err := url.Parse(rawurl)
if err != nil {
return Conn{}, err
Expand Down
2 changes: 1 addition & 1 deletion contrib/gin-gonic/gin/gintrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/gin-gonic/gin: Configuring Middleware: Service: %s, %#v", cfg.serviceName, cfg)
log.Debugf("contrib/gin-gonic/gin: Configuring Middleware: Service: %s, %#v", cfg.serviceName, cfg)
spanOpts := []tracer.StartSpanOption{
tracer.ServiceName(cfg.serviceName),
tracer.Tag(ext.Component, componentName),
Expand Down
Loading

0 comments on commit 0e76e64

Please sign in to comment.