Repository: traefik/traefik (language: go)

Issue:
Datadog tracer logs are not json formatted
### Welcome!

- [X] Yes, I've searched similar issues on [GitHub](https://github.com/traefik/traefik/issues) and didn't find any.
- [X] Yes, I've searched similar issues on the [Traefik community forum](https://community.traefik.io) and didn't find any.

### What did you do?

Hello, I've been investigating an issue we initially spotted in our Fluentd log collector and traced it down to usage of the datadog tracer in Traefik.

We have Traefik configured in our kubernetes as the ingress controller, and in this cluster we are also running datadog.

In order to get traces from Traefik to Datadog, we enabled the traces in Traefik by adding the following to the traefik container `args:`

```
      - --tracing.datadog=true
      - --tracing.datadog.localAgentHostPort=$(DD_AGENT_HOST):8126
      - --tracing.datadog.prioritySampling=true
```

And we set the `DD_AGENT_HOST` environment variable:

```
      env:
      - name: DD_ENTITY_ID
        valueFrom:
          fieldRef:
            apiVersion: v1
            fieldPath: metadata.uid
      - name: DD_AGENT_HOST
        value: datadog.datadog.svc.cluster.local
```

In Traefik, we use json logging format:

```
      - --log.format=json
```

However, we're noticing some log parsing errors in Fluentd due to logs coming from Traefik which aren't json-formatted.

On investigation, we found that traefik is outputting messages which are initially created by the datadog tracer. So I opened an issue with their team to ask for a fix and from what I understood in the [response](https://github.com/DataDog/dd-trace-go/issues/2152#issuecomment-1790586933), Traefik simply needs to provide its json logger to the tracer in order to make the logs json formatted.

Could this be implemented wherever is appropriate in order to ensure that logs output from external tooling are json formatted?

### What did you see instead?

Log messages which are not json formatted

### What version of Traefik are you using?

2.10.4

### What is your environment & configuration?

```yaml
# (paste your configuration here)
```

Add more configuration information here.


### If applicable, please paste the log output in DEBUG level

_No response_


Discussion / hints:
Hey @tspearconquest,

Thanks for the bug report.
If any community member can help us find verified steps to reproduce and fix the issue if possible, we would love the help.

@nmengin I tried to reproduce this issue, it is occuring for branch `v2.10` . Will raise a PR.

Fix patch:
diff --git a/pkg/log/datadog.go b/pkg/log/datadog.go
new file mode 100644
index 0000000000..dda0fed5d2
--- /dev/null
+++ b/pkg/log/datadog.go
@@ -0,0 +1,13 @@
+package log
+
+type DatadogLogger struct {
+	logger Logger
+}
+
+func NewDatadogLogger(logger Logger) *DatadogLogger {
+	return &DatadogLogger{logger: logger}
+}
+
+func (d DatadogLogger) Log(msg string) {
+	d.logger.Debug(msg)
+}
diff --git a/pkg/tracing/datadog/datadog.go b/pkg/tracing/datadog/datadog.go
index b0c32643fb..30e99fcdad 100644
--- a/pkg/tracing/datadog/datadog.go
+++ b/pkg/tracing/datadog/datadog.go
@@ -1,6 +1,7 @@
 package datadog
 
 import (
+	"context"
 	"io"
 	"net"
 	"os"
@@ -47,6 +48,8 @@ func (c *Config) SetDefaults() {
 
 // Setup sets up the tracer.
 func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
+	ctx := log.With(context.Background(), log.Str(log.MetricsProviderName, "datadog"))
+
 	opts := []datadog.StartOption{
 		datadog.WithService(serviceName),
 		datadog.WithDebugMode(c.Debug),
@@ -56,6 +59,7 @@ func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error
 			PriorityHeader: c.SamplingPriorityHeaderName,
 			BaggagePrefix:  c.BagagePrefixHeaderName,
 		})),
+		datadog.WithLogger(log.NewDatadogLogger(log.FromContext(ctx))),
 	}
 
 	if c.LocalAgentSocket != "" {


Test patch: