Repository: traefik/traefik (language: go)

Issue:
Docs mention `--tracing.otlp.http=true` flag but it is not accepted
### 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?

I ran Traefik with the `--tracing.otlp.http=true` flag as suggested [in the docs](https://github.com/traefik/traefik/blob/master/docs/content/observability/tracing/opentelemetry.md#http-configuration) and it failed to start.

```bash
docker run --rm -p 8080:80 traefik:v3.0 --log.level=DEBUG --tracing.otlp.http=true
```

In fact, I initially came across this bug when I used the helm chart which [can add this flag](https://github.com/traefik/traefik-helm-chart/blob/master/traefik/templates/_podtemplate.tpl#L386C2-L386C39). I get a similar issue when using `--tracing.otlp.grpc=true`.

### What did you see instead?

Traefik immediately exited with the following error
```
{"level":"error","error":"command traefik error: failed to decode configuration from flags: http cannot be a standalone element (type *types.OtelHTTP)","time":"2024-05-15T09:58:49Z","message":"Command error"}
```

### What version of Traefik are you using?

Version:      3.0.0
Codename:     beaufort
Go version:   go1.22.2
Built:        2024-04-29T14:25:59Z
OS/Arch:      linux/amd64


### What is your environment & configuration?

no config

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

_No response_


Discussion / hints:
Hello,

the option depends on another option that is required: https://doc.traefik.io/traefik/observability/metrics/opentelemetry/#endpoint
When I add the option you linked to (`--metrics.otlp.http.endpoint=http://localhost:4318/v1/metrics`) I get the same error.

In any case, my issue wasn’t that I did not get OpenTemeletry to work but that the documentation mentions options that are not accepted by traefik which led to a [downstream bug in the helm chart](https://github.com/traefik/traefik-helm-chart/pull/1067).
Hello @geigerzaehler,

Thank you for reaching out.
Indeed, there is an issue in the configuration management we will fix.

Fix patch:
diff --git a/docs/content/reference/static-configuration/cli-ref.md b/docs/content/reference/static-configuration/cli-ref.md
index 99065ee630..136f8dc8ef 100644
--- a/docs/content/reference/static-configuration/cli-ref.md
+++ b/docs/content/reference/static-configuration/cli-ref.md
@@ -339,6 +339,9 @@ Enable metrics on services. (Default: ```true```)
 `--metrics.otlp.explicitboundaries`:  
 Boundaries for latency metrics. (Default: ```0.005000, 0.010000, 0.025000, 0.050000, 0.075000, 0.100000, 0.250000, 0.500000, 0.750000, 1.000000, 2.500000, 5.000000, 7.500000, 10.000000```)
 
+`--metrics.otlp.grpc`:  
+gRPC configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `--metrics.otlp.grpc.endpoint`:  
 Sets the gRPC endpoint (host:port) of the collector. (Default: ```localhost:4317```)
 
@@ -360,6 +363,9 @@ TLS insecure skip verify (Default: ```false```)
 `--metrics.otlp.grpc.tls.key`:  
 TLS key
 
+`--metrics.otlp.http`:  
+HTTP configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `--metrics.otlp.http.endpoint`:  
 Sets the HTTP endpoint (scheme://host:port/path) of the collector. (Default: ```https://localhost:4318```)
 
@@ -1056,6 +1062,9 @@ Defines additional attributes (key:value) on all spans.
 `--tracing.otlp`:  
 Settings for OpenTelemetry. (Default: ```false```)
 
+`--tracing.otlp.grpc`:  
+gRPC configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `--tracing.otlp.grpc.endpoint`:  
 Sets the gRPC endpoint (host:port) of the collector. (Default: ```localhost:4317```)
 
@@ -1077,6 +1086,9 @@ TLS insecure skip verify (Default: ```false```)
 `--tracing.otlp.grpc.tls.key`:  
 TLS key
 
+`--tracing.otlp.http`:  
+HTTP configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `--tracing.otlp.http.endpoint`:  
 Sets the HTTP endpoint (scheme://host:port/path) of the collector. (Default: ```https://localhost:4318```)
 
diff --git a/docs/content/reference/static-configuration/env-ref.md b/docs/content/reference/static-configuration/env-ref.md
index 5d8313abbb..12636602c0 100644
--- a/docs/content/reference/static-configuration/env-ref.md
+++ b/docs/content/reference/static-configuration/env-ref.md
@@ -339,6 +339,9 @@ Enable metrics on services. (Default: ```true```)
 `TRAEFIK_METRICS_OTLP_EXPLICITBOUNDARIES`:  
 Boundaries for latency metrics. (Default: ```0.005000, 0.010000, 0.025000, 0.050000, 0.075000, 0.100000, 0.250000, 0.500000, 0.750000, 1.000000, 2.500000, 5.000000, 7.500000, 10.000000```)
 
+`TRAEFIK_METRICS_OTLP_GRPC`:  
+gRPC configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `TRAEFIK_METRICS_OTLP_GRPC_ENDPOINT`:  
 Sets the gRPC endpoint (host:port) of the collector. (Default: ```localhost:4317```)
 
@@ -360,6 +363,9 @@ TLS insecure skip verify (Default: ```false```)
 `TRAEFIK_METRICS_OTLP_GRPC_TLS_KEY`:  
 TLS key
 
+`TRAEFIK_METRICS_OTLP_HTTP`:  
+HTTP configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `TRAEFIK_METRICS_OTLP_HTTP_ENDPOINT`:  
 Sets the HTTP endpoint (scheme://host:port/path) of the collector. (Default: ```https://localhost:4318```)
 
@@ -1056,6 +1062,9 @@ Defines additional attributes (key:value) on all spans.
 `TRAEFIK_TRACING_OTLP`:  
 Settings for OpenTelemetry. (Default: ```false```)
 
+`TRAEFIK_TRACING_OTLP_GRPC`:  
+gRPC configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `TRAEFIK_TRACING_OTLP_GRPC_ENDPOINT`:  
 Sets the gRPC endpoint (host:port) of the collector. (Default: ```localhost:4317```)
 
@@ -1077,6 +1086,9 @@ TLS insecure skip verify (Default: ```false```)
 `TRAEFIK_TRACING_OTLP_GRPC_TLS_KEY`:  
 TLS key
 
+`TRAEFIK_TRACING_OTLP_HTTP`:  
+HTTP configuration for the OpenTelemetry collector. (Default: ```false```)
+
 `TRAEFIK_TRACING_OTLP_HTTP_ENDPOINT`:  
 Sets the HTTP endpoint (scheme://host:port/path) of the collector. (Default: ```https://localhost:4318```)
 
diff --git a/pkg/tracing/opentelemetry/opentelemetry.go b/pkg/tracing/opentelemetry/opentelemetry.go
index 3806ffcd4d..35f1a5f6ad 100644
--- a/pkg/tracing/opentelemetry/opentelemetry.go
+++ b/pkg/tracing/opentelemetry/opentelemetry.go
@@ -26,8 +26,8 @@ import (
 
 // Config provides configuration settings for the open-telemetry tracer.
 type Config struct {
-	GRPC *types.OtelGRPC `description:"gRPC configuration for the OpenTelemetry collector." json:"grpc,omitempty" toml:"grpc,omitempty" yaml:"grpc,omitempty" export:"true"`
-	HTTP *types.OtelHTTP `description:"HTTP configuration for the OpenTelemetry collector." json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" export:"true"`
+	GRPC *types.OtelGRPC `description:"gRPC configuration for the OpenTelemetry collector." json:"grpc,omitempty" toml:"grpc,omitempty" yaml:"grpc,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
+	HTTP *types.OtelHTTP `description:"HTTP configuration for the OpenTelemetry collector." json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
 }
 
 // SetDefaults sets the default values.
diff --git a/pkg/types/metrics.go b/pkg/types/metrics.go
index cde08e189e..b97ae92217 100644
--- a/pkg/types/metrics.go
+++ b/pkg/types/metrics.go
@@ -108,8 +108,8 @@ func (i *InfluxDB2) SetDefaults() {
 
 // OTLP contains specific configuration used by the OpenTelemetry Metrics exporter.
 type OTLP struct {
-	GRPC *OtelGRPC `description:"gRPC configuration for the OpenTelemetry collector." json:"grpc,omitempty" toml:"grpc,omitempty" yaml:"grpc,omitempty" export:"true"`
-	HTTP *OtelHTTP `description:"HTTP configuration for the OpenTelemetry collector." json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" export:"true"`
+	GRPC *OtelGRPC `description:"gRPC configuration for the OpenTelemetry collector." json:"grpc,omitempty" toml:"grpc,omitempty" yaml:"grpc,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
+	HTTP *OtelHTTP `description:"HTTP configuration for the OpenTelemetry collector." json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
 
 	AddEntryPointsLabels bool           `description:"Enable metrics on entry points." json:"addEntryPointsLabels,omitempty" toml:"addEntryPointsLabels,omitempty" yaml:"addEntryPointsLabels,omitempty" export:"true"`
 	AddRoutersLabels     bool           `description:"Enable metrics on routers." json:"addRoutersLabels,omitempty" toml:"addRoutersLabels,omitempty" yaml:"addRoutersLabels,omitempty" export:"true"`


Test patch: