fix: otel not working without USER

This commit is contained in:
Michael 2025-10-03 14:48:04 +02:00 committed by GitHub
parent ad566ee9ef
commit c5ed376d5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
127 changed files with 347 additions and 305 deletions

View File

@ -263,7 +263,7 @@ linters:
- path: pkg/provider/kubernetes/(crd|gateway)/client.go - path: pkg/provider/kubernetes/(crd|gateway)/client.go
linters: linters:
- interfacebloat - interfacebloat
- path: pkg/metrics/metrics.go - path: pkg/observability/metrics/metrics.go
linters: linters:
- interfacebloat - interfacebloat
- path: integration/healthcheck_test.go - path: integration/healthcheck_test.go

View File

@ -14,7 +14,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"gopkg.in/natefinch/lumberjack.v2" "gopkg.in/natefinch/lumberjack.v2"
) )

View File

@ -9,7 +9,7 @@ import (
"github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/go-retryablehttp"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/plugins" "github.com/traefik/traefik/v3/pkg/plugins"
) )

View File

@ -30,9 +30,11 @@ import (
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/config/runtime"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/metrics"
"github.com/traefik/traefik/v3/pkg/middlewares/accesslog" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/observability/metrics"
"github.com/traefik/traefik/v3/pkg/observability/tracing"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/provider/acme" "github.com/traefik/traefik/v3/pkg/provider/acme"
"github.com/traefik/traefik/v3/pkg/provider/aggregator" "github.com/traefik/traefik/v3/pkg/provider/aggregator"
"github.com/traefik/traefik/v3/pkg/provider/tailscale" "github.com/traefik/traefik/v3/pkg/provider/tailscale"
@ -46,8 +48,6 @@ import (
"github.com/traefik/traefik/v3/pkg/server/service" "github.com/traefik/traefik/v3/pkg/server/service"
"github.com/traefik/traefik/v3/pkg/tcp" "github.com/traefik/traefik/v3/pkg/tcp"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/tracing"
"github.com/traefik/traefik/v3/pkg/types"
"github.com/traefik/traefik/v3/pkg/version" "github.com/traefik/traefik/v3/pkg/version"
) )
@ -505,7 +505,7 @@ func initTailscaleProviders(cfg *static.Configuration, providerAggregator *aggre
return providers return providers
} }
func registerMetricClients(metricsConfig *types.Metrics) []metrics.Registry { func registerMetricClients(metricsConfig *otypes.Metrics) []metrics.Registry {
if metricsConfig == nil { if metricsConfig == nil {
return nil return nil
} }
@ -586,7 +586,7 @@ func appendCertMetric(gauge gokitmetrics.Gauge, certificate *x509.Certificate) {
gauge.With(labels...).Set(notAfter) gauge.With(labels...).Set(notAfter)
} }
func setupAccessLog(ctx context.Context, conf *types.AccessLog) *accesslog.Handler { func setupAccessLog(ctx context.Context, conf *otypes.AccessLog) *accesslog.Handler {
if conf == nil { if conf == nil {
return nil return nil
} }

View File

@ -13,12 +13,12 @@ import (
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/config/runtime" "github.com/traefik/traefik/v3/pkg/config/runtime"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/provider/docker" "github.com/traefik/traefik/v3/pkg/provider/docker"
"github.com/traefik/traefik/v3/pkg/provider/file" "github.com/traefik/traefik/v3/pkg/provider/file"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/ingress" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/ingress"
"github.com/traefik/traefik/v3/pkg/provider/rest" "github.com/traefik/traefik/v3/pkg/provider/rest"
"github.com/traefik/traefik/v3/pkg/types"
) )
func TestHandler_Overview(t *testing.T) { func TestHandler_Overview(t *testing.T) {
@ -255,8 +255,8 @@ func TestHandler_Overview(t *testing.T) {
confStatic: static.Configuration{ confStatic: static.Configuration{
Global: &static.Global{}, Global: &static.Global{},
API: &static.API{}, API: &static.API{},
Metrics: &types.Metrics{ Metrics: &otypes.Metrics{
Prometheus: &types.Prometheus{}, Prometheus: &otypes.Prometheus{},
}, },
Tracing: &static.Tracing{}, Tracing: &static.Tracing{},
}, },

View File

@ -5,6 +5,7 @@ import (
"time" "time"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@ -97,12 +98,12 @@ type RouterObservabilityConfig struct {
// TraceVerbosity defines the verbosity level of the tracing for this router. // TraceVerbosity defines the verbosity level of the tracing for this router.
// +kubebuilder:validation:Enum=minimal;detailed // +kubebuilder:validation:Enum=minimal;detailed
// +kubebuilder:default=minimal // +kubebuilder:default=minimal
TraceVerbosity types.TracingVerbosity `json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` TraceVerbosity otypes.TracingVerbosity `json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"`
} }
// SetDefaults Default values for a RouterObservabilityConfig. // SetDefaults Default values for a RouterObservabilityConfig.
func (r *RouterObservabilityConfig) SetDefaults() { func (r *RouterObservabilityConfig) SetDefaults() {
r.TraceVerbosity = types.MinimalVerbosity r.TraceVerbosity = otypes.MinimalVerbosity
} }
// +k8s:deepcopy-gen=true // +k8s:deepcopy-gen=true

View File

@ -6,7 +6,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// Status of the router/service. // Status of the router/service.

View File

@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// GetRoutersByEntryPoints returns all the http routers by entry points name and routers name. // GetRoutersByEntryPoints returns all the http routers by entry points name and routers name.

View File

@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// GetTCPRoutersByEntryPoints returns all the tcp routers by entry points name and routers name. // GetTCPRoutersByEntryPoints returns all the tcp routers by entry points name and routers name.

View File

@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// GetUDPRoutersByEntryPoints returns all the UDP routers by entry points name and routers name. // GetUDPRoutersByEntryPoints returns all the UDP routers by entry points name and routers name.

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
) )
@ -165,10 +166,10 @@ func (u *UDPConfig) SetDefaults() {
// ObservabilityConfig holds the observability configuration for an entry point. // ObservabilityConfig holds the observability configuration for an entry point.
type ObservabilityConfig struct { type ObservabilityConfig struct {
AccessLogs *bool `description:"Enables access-logs for this entryPoint." json:"accessLogs,omitempty" toml:"accessLogs,omitempty" yaml:"accessLogs,omitempty" export:"true"` AccessLogs *bool `description:"Enables access-logs for this entryPoint." json:"accessLogs,omitempty" toml:"accessLogs,omitempty" yaml:"accessLogs,omitempty" export:"true"`
Metrics *bool `description:"Enables metrics for this entryPoint." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` Metrics *bool `description:"Enables metrics for this entryPoint." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"`
Tracing *bool `description:"Enables tracing for this entryPoint." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" export:"true"` Tracing *bool `description:"Enables tracing for this entryPoint." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" export:"true"`
TraceVerbosity types.TracingVerbosity `description:"Defines the tracing verbosity level for this entryPoint." json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"` TraceVerbosity otypes.TracingVerbosity `description:"Defines the tracing verbosity level for this entryPoint." json:"traceVerbosity,omitempty" toml:"traceVerbosity,omitempty" yaml:"traceVerbosity,omitempty" export:"true"`
} }
// SetDefaults sets the default values. // SetDefaults sets the default values.
@ -177,5 +178,5 @@ func (o *ObservabilityConfig) SetDefaults() {
o.AccessLogs = &defaultValue o.AccessLogs = &defaultValue
o.Metrics = &defaultValue o.Metrics = &defaultValue
o.Tracing = &defaultValue o.Tracing = &defaultValue
o.TraceVerbosity = types.MinimalVerbosity o.TraceVerbosity = otypes.MinimalVerbosity
} }

View File

@ -11,7 +11,8 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/ping" "github.com/traefik/traefik/v3/pkg/ping"
acmeprovider "github.com/traefik/traefik/v3/pkg/provider/acme" acmeprovider "github.com/traefik/traefik/v3/pkg/provider/acme"
"github.com/traefik/traefik/v3/pkg/provider/consulcatalog" "github.com/traefik/traefik/v3/pkg/provider/consulcatalog"
@ -64,13 +65,13 @@ type Configuration struct {
EntryPoints EntryPoints `description:"Entry points definition." json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"` EntryPoints EntryPoints `description:"Entry points definition." json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"`
Providers *Providers `description:"Providers configuration." json:"providers,omitempty" toml:"providers,omitempty" yaml:"providers,omitempty" export:"true"` Providers *Providers `description:"Providers configuration." json:"providers,omitempty" toml:"providers,omitempty" yaml:"providers,omitempty" export:"true"`
API *API `description:"Enable api/dashboard." json:"api,omitempty" toml:"api,omitempty" yaml:"api,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` API *API `description:"Enable api/dashboard." json:"api,omitempty" toml:"api,omitempty" yaml:"api,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
Metrics *types.Metrics `description:"Enable a metrics exporter." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"` Metrics *otypes.Metrics `description:"Enable a metrics exporter." json:"metrics,omitempty" toml:"metrics,omitempty" yaml:"metrics,omitempty" export:"true"`
Ping *ping.Handler `description:"Enable ping." json:"ping,omitempty" toml:"ping,omitempty" yaml:"ping,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` Ping *ping.Handler `description:"Enable ping." json:"ping,omitempty" toml:"ping,omitempty" yaml:"ping,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
Log *types.TraefikLog `description:"Traefik log settings." json:"log,omitempty" toml:"log,omitempty" yaml:"log,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` Log *otypes.TraefikLog `description:"Traefik log settings." json:"log,omitempty" toml:"log,omitempty" yaml:"log,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
AccessLog *types.AccessLog `description:"Access log settings." json:"accessLog,omitempty" toml:"accessLog,omitempty" yaml:"accessLog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` AccessLog *otypes.AccessLog `description:"Access log settings." json:"accessLog,omitempty" toml:"accessLog,omitempty" yaml:"accessLog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
Tracing *Tracing `description:"Tracing configuration." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` Tracing *Tracing `description:"Tracing configuration." json:"tracing,omitempty" toml:"tracing,omitempty" yaml:"tracing,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
HostResolver *types.HostResolverConfig `description:"Enable CNAME Flattening." json:"hostResolver,omitempty" toml:"hostResolver,omitempty" yaml:"hostResolver,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` HostResolver *types.HostResolverConfig `description:"Enable CNAME Flattening." json:"hostResolver,omitempty" toml:"hostResolver,omitempty" yaml:"hostResolver,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
@ -205,14 +206,14 @@ func (a *LifeCycle) SetDefaults() {
// Tracing holds the tracing configuration. // Tracing holds the tracing configuration.
type Tracing struct { type Tracing struct {
ServiceName string `description:"Defines the service name resource attribute." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"` ServiceName string `description:"Defines the service name resource attribute." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"`
ResourceAttributes map[string]string `description:"Defines additional resource attributes (key:value)." json:"resourceAttributes,omitempty" toml:"resourceAttributes,omitempty" yaml:"resourceAttributes,omitempty" export:"true"` ResourceAttributes map[string]string `description:"Defines additional resource attributes (key:value)." json:"resourceAttributes,omitempty" toml:"resourceAttributes,omitempty" yaml:"resourceAttributes,omitempty" export:"true"`
CapturedRequestHeaders []string `description:"Request headers to add as attributes for server and client spans." json:"capturedRequestHeaders,omitempty" toml:"capturedRequestHeaders,omitempty" yaml:"capturedRequestHeaders,omitempty" export:"true"` CapturedRequestHeaders []string `description:"Request headers to add as attributes for server and client spans." json:"capturedRequestHeaders,omitempty" toml:"capturedRequestHeaders,omitempty" yaml:"capturedRequestHeaders,omitempty" export:"true"`
CapturedResponseHeaders []string `description:"Response headers to add as attributes for server and client spans." json:"capturedResponseHeaders,omitempty" toml:"capturedResponseHeaders,omitempty" yaml:"capturedResponseHeaders,omitempty" export:"true"` CapturedResponseHeaders []string `description:"Response headers to add as attributes for server and client spans." json:"capturedResponseHeaders,omitempty" toml:"capturedResponseHeaders,omitempty" yaml:"capturedResponseHeaders,omitempty" export:"true"`
SafeQueryParams []string `description:"Query params to not redact." json:"safeQueryParams,omitempty" toml:"safeQueryParams,omitempty" yaml:"safeQueryParams,omitempty" export:"true"` SafeQueryParams []string `description:"Query params to not redact." json:"safeQueryParams,omitempty" toml:"safeQueryParams,omitempty" yaml:"safeQueryParams,omitempty" export:"true"`
SampleRate float64 `description:"Sets the rate between 0.0 and 1.0 of requests to trace." json:"sampleRate,omitempty" toml:"sampleRate,omitempty" yaml:"sampleRate,omitempty" export:"true"` SampleRate float64 `description:"Sets the rate between 0.0 and 1.0 of requests to trace." json:"sampleRate,omitempty" toml:"sampleRate,omitempty" yaml:"sampleRate,omitempty" export:"true"`
AddInternals bool `description:"Enables tracing for internal services (ping, dashboard, etc...)." json:"addInternals,omitempty" toml:"addInternals,omitempty" yaml:"addInternals,omitempty" export:"true"` AddInternals bool `description:"Enables tracing for internal services (ping, dashboard, etc...)." json:"addInternals,omitempty" toml:"addInternals,omitempty" yaml:"addInternals,omitempty" export:"true"`
OTLP *types.OTelTracing `description:"Settings for OpenTelemetry." json:"otlp,omitempty" toml:"otlp,omitempty" yaml:"otlp,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` OTLP *otypes.OTelTracing `description:"Settings for OpenTelemetry." json:"otlp,omitempty" toml:"otlp,omitempty" yaml:"otlp,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
// Deprecated: please use ResourceAttributes instead. // Deprecated: please use ResourceAttributes instead.
GlobalAttributes map[string]string `description:"(Deprecated) Defines additional resource attributes (key:value)." json:"globalAttributes,omitempty" toml:"globalAttributes,omitempty" yaml:"globalAttributes,omitempty" export:"true"` GlobalAttributes map[string]string `description:"(Deprecated) Defines additional resource attributes (key:value)." json:"globalAttributes,omitempty" toml:"globalAttributes,omitempty" yaml:"globalAttributes,omitempty" export:"true"`
@ -223,7 +224,7 @@ func (t *Tracing) SetDefaults() {
t.ServiceName = "traefik" t.ServiceName = "traefik"
t.SampleRate = 1.0 t.SampleRate = 1.0
t.OTLP = &types.OTelTracing{} t.OTLP = &otypes.OTelTracing{}
t.OTLP.SetDefaults() t.OTLP.SetDefaults()
} }

View File

@ -5,8 +5,8 @@ import (
"time" "time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/vulcand/oxy/v2/utils" "github.com/vulcand/oxy/v2/utils"
) )

View File

@ -19,9 +19,10 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/observability/logs"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
"go.opentelemetry.io/contrib/bridges/otellogrus" "go.opentelemetry.io/contrib/bridges/otellogrus"
@ -64,7 +65,7 @@ type handlerParams struct {
// Handler will write each request and its response to the access log. // Handler will write each request and its response to the access log.
type Handler struct { type Handler struct {
config *types.AccessLog config *otypes.AccessLog
logger *logrus.Logger logger *logrus.Logger
file io.WriteCloser file io.WriteCloser
mu sync.Mutex mu sync.Mutex
@ -88,7 +89,7 @@ func (h *Handler) AliceConstructor() alice.Constructor {
} }
// NewHandler creates a new Handler. // NewHandler creates a new Handler.
func NewHandler(ctx context.Context, config *types.AccessLog) (*Handler, error) { func NewHandler(ctx context.Context, config *otypes.AccessLog) (*Handler, error) {
var file io.WriteCloser = noopCloser{os.Stdout} var file io.WriteCloser = noopCloser{os.Stdout}
if len(config.FilePath) > 0 { if len(config.FilePath) > 0 {
f, err := openAccessLogFile(config.FilePath) f, err := openAccessLogFile(config.FilePath)
@ -423,9 +424,9 @@ func (h *Handler) redactHeaders(headers http.Header, fields logrus.Fields, prefi
for k := range headers { for k := range headers {
v := h.config.Fields.KeepHeader(k) v := h.config.Fields.KeepHeader(k)
switch v { switch v {
case types.AccessLogKeep: case otypes.AccessLogKeep:
fields[prefix+k] = strings.Join(headers.Values(k), ",") fields[prefix+k] = strings.Join(headers.Values(k), ",")
case types.AccessLogRedact: case otypes.AccessLogRedact:
fields[prefix+k] = "REDACTED" fields[prefix+k] = "REDACTED"
} }
} }

View File

@ -26,7 +26,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"go.opentelemetry.io/collector/pdata/plog/plogotlp" "go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/codes"
@ -117,12 +117,12 @@ func TestOTelAccessLogWithBody(t *testing.T) {
})) }))
t.Cleanup(collector.Close) t.Cleanup(collector.Close)
config := &types.AccessLog{ config := &otypes.AccessLog{
Format: test.format, Format: test.format,
OTLP: &types.OTelLog{ OTLP: &otypes.OTelLog{
ServiceName: "test", ServiceName: "test",
ResourceAttributes: map[string]string{"resource": "attribute"}, ResourceAttributes: map[string]string{"resource": "attribute"},
HTTP: &types.OTelHTTP{ HTTP: &otypes.OTelHTTP{
Endpoint: collector.URL, Endpoint: collector.URL,
}, },
}, },
@ -188,7 +188,7 @@ func TestLogRotation(t *testing.T) {
fileName := filepath.Join(t.TempDir(), "traefik.log") fileName := filepath.Join(t.TempDir(), "traefik.log")
rotatedFileName := fileName + ".rotated" rotatedFileName := fileName + ".rotated"
config := &types.AccessLog{FilePath: fileName, Format: CommonFormat} config := &otypes.AccessLog{FilePath: fileName, Format: CommonFormat}
logHandler, err := NewHandler(t.Context(), config) logHandler, err := NewHandler(t.Context(), config)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
@ -276,18 +276,18 @@ func TestLoggerHeaderFields(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
accessLogFields types.AccessLogFields accessLogFields otypes.AccessLogFields
header string header string
expected string expected string
}{ }{
{ {
desc: "with default mode", desc: "with default mode",
header: "User-Agent", header: "User-Agent",
expected: types.AccessLogDrop, expected: otypes.AccessLogDrop,
accessLogFields: types.AccessLogFields{ accessLogFields: otypes.AccessLogFields{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Names: map[string]string{}, Names: map[string]string{},
}, },
}, },
@ -295,13 +295,13 @@ func TestLoggerHeaderFields(t *testing.T) {
{ {
desc: "with exact header name", desc: "with exact header name",
header: "User-Agent", header: "User-Agent",
expected: types.AccessLogKeep, expected: otypes.AccessLogKeep,
accessLogFields: types.AccessLogFields{ accessLogFields: otypes.AccessLogFields{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Names: map[string]string{ Names: map[string]string{
"User-Agent": types.AccessLogKeep, "User-Agent": otypes.AccessLogKeep,
}, },
}, },
}, },
@ -309,13 +309,13 @@ func TestLoggerHeaderFields(t *testing.T) {
{ {
desc: "with case-insensitive match on header name", desc: "with case-insensitive match on header name",
header: "User-Agent", header: "User-Agent",
expected: types.AccessLogKeep, expected: otypes.AccessLogKeep,
accessLogFields: types.AccessLogFields{ accessLogFields: otypes.AccessLogFields{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: types.AccessLogDrop, DefaultMode: otypes.AccessLogDrop,
Names: map[string]string{ Names: map[string]string{
"user-agent": types.AccessLogKeep, "user-agent": otypes.AccessLogKeep,
}, },
}, },
}, },
@ -327,7 +327,7 @@ func TestLoggerHeaderFields(t *testing.T) {
logFile, err := os.CreateTemp(t.TempDir(), "*.log") logFile, err := os.CreateTemp(t.TempDir(), "*.log")
require.NoError(t, err) require.NoError(t, err)
config := &types.AccessLog{ config := &otypes.AccessLog{
FilePath: logFile.Name(), FilePath: logFile.Name(),
Format: CommonFormat, Format: CommonFormat,
Fields: &test.accessLogFields, Fields: &test.accessLogFields,
@ -376,7 +376,7 @@ func TestLoggerHeaderFields(t *testing.T) {
logData, err := os.ReadFile(logFile.Name()) logData, err := os.ReadFile(logFile.Name())
require.NoError(t, err) require.NoError(t, err)
if test.expected == types.AccessLogDrop { if test.expected == otypes.AccessLogDrop {
assert.NotContains(t, string(logData), strings.Join(expectedValues, ",")) assert.NotContains(t, string(logData), strings.Join(expectedValues, ","))
} else { } else {
assert.Contains(t, string(logData), strings.Join(expectedValues, ",")) assert.Contains(t, string(logData), strings.Join(expectedValues, ","))
@ -387,7 +387,7 @@ func TestLoggerHeaderFields(t *testing.T) {
func TestCommonLogger(t *testing.T) { func TestCommonLogger(t *testing.T) {
logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix)
config := &types.AccessLog{FilePath: logFilePath, Format: CommonFormat} config := &otypes.AccessLog{FilePath: logFilePath, Format: CommonFormat}
doLogging(t, config, false) doLogging(t, config, false)
logData, err := os.ReadFile(logFilePath) logData, err := os.ReadFile(logFilePath)
@ -399,7 +399,7 @@ func TestCommonLogger(t *testing.T) {
func TestCommonLoggerWithBufferingSize(t *testing.T) { func TestCommonLoggerWithBufferingSize(t *testing.T) {
logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix)
config := &types.AccessLog{FilePath: logFilePath, Format: CommonFormat, BufferingSize: 1024} config := &otypes.AccessLog{FilePath: logFilePath, Format: CommonFormat, BufferingSize: 1024}
doLogging(t, config, false) doLogging(t, config, false)
// wait a bit for the buffer to be written in the file. // wait a bit for the buffer to be written in the file.
@ -414,7 +414,7 @@ func TestCommonLoggerWithBufferingSize(t *testing.T) {
func TestLoggerGenericCLF(t *testing.T) { func TestLoggerGenericCLF(t *testing.T) {
logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix)
config := &types.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat} config := &otypes.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat}
doLogging(t, config, false) doLogging(t, config, false)
logData, err := os.ReadFile(logFilePath) logData, err := os.ReadFile(logFilePath)
@ -426,7 +426,7 @@ func TestLoggerGenericCLF(t *testing.T) {
func TestLoggerGenericCLFWithBufferingSize(t *testing.T) { func TestLoggerGenericCLFWithBufferingSize(t *testing.T) {
logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix) logFilePath := filepath.Join(t.TempDir(), logFileNameSuffix)
config := &types.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat, BufferingSize: 1024} config := &otypes.AccessLog{FilePath: logFilePath, Format: GenericCLFFormat, BufferingSize: 1024}
doLogging(t, config, false) doLogging(t, config, false)
// wait a bit for the buffer to be written in the file. // wait a bit for the buffer to be written in the file.
@ -474,14 +474,14 @@ func assertFloat64NotZero() func(t *testing.T, actual interface{}) {
func TestLoggerJSON(t *testing.T) { func TestLoggerJSON(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
config *types.AccessLog config *otypes.AccessLog
tls bool tls bool
tracing bool tracing bool
expected map[string]func(t *testing.T, value interface{}) expected map[string]func(t *testing.T, value interface{})
}{ }{
{ {
desc: "default config without tracing", desc: "default config without tracing",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
}, },
@ -520,7 +520,7 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config with tracing", desc: "default config with tracing",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
}, },
@ -562,7 +562,7 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config, with TLS request", desc: "default config, with TLS request",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
}, },
@ -605,10 +605,10 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config drop all fields", desc: "default config drop all fields",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
}, },
}, },
@ -623,12 +623,12 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config drop all fields and headers", desc: "default config drop all fields and headers",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "drop", DefaultMode: "drop",
}, },
}, },
@ -641,12 +641,12 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config drop all fields and redact headers", desc: "default config drop all fields and redact headers",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "redact", DefaultMode: "redact",
}, },
}, },
@ -662,15 +662,15 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "default config drop all fields and headers but kept someone", desc: "default config drop all fields and headers but kept someone",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
RequestHost: "keep", RequestHost: "keep",
}, },
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
"Referer": "keep", "Referer": "keep",
@ -688,15 +688,15 @@ func TestLoggerJSON(t *testing.T) {
}, },
{ {
desc: "fields and headers with unconventional letter case", desc: "fields and headers with unconventional letter case",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: JSONFormat, Format: JSONFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
"rEqUeStHoSt": "keep", "rEqUeStHoSt": "keep",
}, },
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
"ReFeReR": "keep", "ReFeReR": "keep",
@ -778,7 +778,7 @@ func TestLogger_AbortedRequest(t *testing.T) {
"downstream_Cache-Control": assertString("no-cache"), "downstream_Cache-Control": assertString("no-cache"),
} }
config := &types.AccessLog{ config := &otypes.AccessLog{
FilePath: filepath.Join(t.TempDir(), logFileNameSuffix), FilePath: filepath.Join(t.TempDir(), logFileNameSuffix),
Format: JSONFormat, Format: JSONFormat,
} }
@ -804,12 +804,12 @@ func TestLogger_AbortedRequest(t *testing.T) {
func TestNewLogHandlerOutputStdout(t *testing.T) { func TestNewLogHandlerOutputStdout(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
config *types.AccessLog config *otypes.AccessLog
expectedLog string expectedLog string
}{ }{
{ {
desc: "default config", desc: "default config",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
}, },
@ -817,19 +817,19 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "default config with empty filters", desc: "default config with empty filters",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{}, Filters: &otypes.AccessLogFilters{},
}, },
expectedLog: `TestHost - TestUser [13/Apr/2016:07:14:19 -0700] "POST testpath HTTP/0.0" 123 12 "testReferer" "testUserAgent" 23 "testRouter" "http://127.0.0.1/testService" 1ms`, expectedLog: `TestHost - TestUser [13/Apr/2016:07:14:19 -0700] "POST testpath HTTP/0.0" 123 12 "testReferer" "testUserAgent" 23 "testRouter" "http://127.0.0.1/testService" 1ms`,
}, },
{ {
desc: "Status code filter not matching", desc: "Status code filter not matching",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{ Filters: &otypes.AccessLogFilters{
StatusCodes: []string{"200"}, StatusCodes: []string{"200"},
}, },
}, },
@ -837,10 +837,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Status code filter matching", desc: "Status code filter matching",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{ Filters: &otypes.AccessLogFilters{
StatusCodes: []string{"123"}, StatusCodes: []string{"123"},
}, },
}, },
@ -848,10 +848,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Duration filter not matching", desc: "Duration filter not matching",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{ Filters: &otypes.AccessLogFilters{
MinDuration: ptypes.Duration(1 * time.Hour), MinDuration: ptypes.Duration(1 * time.Hour),
}, },
}, },
@ -859,10 +859,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Duration filter matching", desc: "Duration filter matching",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{ Filters: &otypes.AccessLogFilters{
MinDuration: ptypes.Duration(1 * time.Millisecond), MinDuration: ptypes.Duration(1 * time.Millisecond),
}, },
}, },
@ -870,10 +870,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Retry attempts filter matching", desc: "Retry attempts filter matching",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Filters: &types.AccessLogFilters{ Filters: &otypes.AccessLogFilters{
RetryAttempts: true, RetryAttempts: true,
}, },
}, },
@ -881,10 +881,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode keep", desc: "Default mode keep",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "keep", DefaultMode: "keep",
}, },
}, },
@ -892,10 +892,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode keep with override", desc: "Default mode keep with override",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "keep", DefaultMode: "keep",
Names: map[string]string{ Names: map[string]string{
ClientHost: "drop", ClientHost: "drop",
@ -906,10 +906,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode drop", desc: "Default mode drop",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
}, },
}, },
@ -917,10 +917,10 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode drop with override", desc: "Default mode drop with override",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
ClientHost: "drop", ClientHost: "drop",
@ -932,16 +932,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode drop with header dropped", desc: "Default mode drop with header dropped",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
ClientHost: "drop", ClientHost: "drop",
ClientUsername: "keep", ClientUsername: "keep",
}, },
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "drop", DefaultMode: "drop",
}, },
}, },
@ -950,16 +950,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode drop with header redacted", desc: "Default mode drop with header redacted",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
ClientHost: "drop", ClientHost: "drop",
ClientUsername: "keep", ClientUsername: "keep",
}, },
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "redact", DefaultMode: "redact",
}, },
}, },
@ -968,16 +968,16 @@ func TestNewLogHandlerOutputStdout(t *testing.T) {
}, },
{ {
desc: "Default mode drop with header redacted", desc: "Default mode drop with header redacted",
config: &types.AccessLog{ config: &otypes.AccessLog{
FilePath: "", FilePath: "",
Format: CommonFormat, Format: CommonFormat,
Fields: &types.AccessLogFields{ Fields: &otypes.AccessLogFields{
DefaultMode: "drop", DefaultMode: "drop",
Names: map[string]string{ Names: map[string]string{
ClientHost: "drop", ClientHost: "drop",
ClientUsername: "keep", ClientUsername: "keep",
}, },
Headers: &types.FieldHeaders{ Headers: &otypes.FieldHeaders{
DefaultMode: "keep", DefaultMode: "keep",
Names: map[string]string{ Names: map[string]string{
"Referer": "redact", "Referer": "redact",
@ -1084,7 +1084,7 @@ func captureStdout(t *testing.T) (out *os.File, restoreStdout func()) {
return file, restoreStdout return file, restoreStdout
} }
func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS, tracing bool) { func doLoggingTLSOpt(t *testing.T, config *otypes.AccessLog, enableTLS, tracing bool) {
t.Helper() t.Helper()
logger, err := NewHandler(t.Context(), config) logger, err := NewHandler(t.Context(), config)
require.NoError(t, err) require.NoError(t, err)
@ -1145,13 +1145,13 @@ func doLoggingTLSOpt(t *testing.T, config *types.AccessLog, enableTLS, tracing b
handler.ServeHTTP(httptest.NewRecorder(), req) handler.ServeHTTP(httptest.NewRecorder(), req)
} }
func doLoggingTLS(t *testing.T, config *types.AccessLog, tracing bool) { func doLoggingTLS(t *testing.T, config *otypes.AccessLog, tracing bool) {
t.Helper() t.Helper()
doLoggingTLSOpt(t, config, true, tracing) doLoggingTLSOpt(t, config, true, tracing)
} }
func doLogging(t *testing.T, config *types.AccessLog, tracing bool) { func doLogging(t *testing.T, config *otypes.AccessLog, tracing bool) {
t.Helper() t.Helper()
doLoggingTLSOpt(t, config, false, tracing) doLoggingTLSOpt(t, config, false, tracing)
@ -1180,7 +1180,7 @@ func logWriterTestHandlerFunc(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(testStatus) rw.WriteHeader(testStatus)
} }
func doLoggingWithAbortedStream(t *testing.T, config *types.AccessLog) { func doLoggingWithAbortedStream(t *testing.T, config *otypes.AccessLog) {
t.Helper() t.Helper()
logger, err := NewHandler(t.Context(), config) logger, err := NewHandler(t.Context(), config)

View File

@ -17,8 +17,8 @@ import (
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/middlewares/accesslog" "github.com/traefik/traefik/v3/pkg/middlewares/accesslog"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/observability/tracing"
"github.com/traefik/traefik/v3/pkg/proxy/httputil" "github.com/traefik/traefik/v3/pkg/proxy/httputil"
"github.com/traefik/traefik/v3/pkg/tracing"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
"github.com/vulcand/oxy/v2/forward" "github.com/vulcand/oxy/v2/forward"
"github.com/vulcand/oxy/v2/utils" "github.com/vulcand/oxy/v2/utils"

View File

@ -17,9 +17,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/observability/tracing"
"github.com/traefik/traefik/v3/pkg/proxy/httputil" "github.com/traefik/traefik/v3/pkg/proxy/httputil"
"github.com/traefik/traefik/v3/pkg/testhelpers" "github.com/traefik/traefik/v3/pkg/testhelpers"
"github.com/traefik/traefik/v3/pkg/tracing"
"github.com/vulcand/oxy/v2/forward" "github.com/vulcand/oxy/v2/forward"
"go.opentelemetry.io/contrib/propagators/autoprop" "go.opentelemetry.io/contrib/propagators/autoprop"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"

View File

@ -6,8 +6,8 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/observability/logs"
oxybuffer "github.com/vulcand/oxy/v2/buffer" oxybuffer "github.com/vulcand/oxy/v2/buffer"
) )

View File

@ -8,9 +8,9 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/vulcand/oxy/v2/cbreaker" "github.com/vulcand/oxy/v2/cbreaker"
) )

View File

@ -8,7 +8,7 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
const xTraefikRouter = "X-Traefik-Router" const xTraefikRouter = "X-Traefik-Router"

View File

@ -7,8 +7,8 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/vulcand/oxy/v2/connlimit" "github.com/vulcand/oxy/v2/connlimit"
) )

View File

@ -12,11 +12,11 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
gokitmetrics "github.com/go-kit/kit/metrics" gokitmetrics "github.com/go-kit/kit/metrics"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/metrics"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/middlewares/retry" "github.com/traefik/traefik/v3/pkg/middlewares/retry"
"github.com/traefik/traefik/v3/pkg/observability/metrics"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
) )

View File

@ -5,7 +5,7 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// GetLogger creates a logger with the middleware fields. // GetLogger creates a logger with the middleware fields.

View File

@ -8,7 +8,7 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop" "go.opentelemetry.io/otel/trace/noop"

View File

@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
) )

View File

@ -6,8 +6,8 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )

View File

@ -5,9 +5,9 @@ import (
"net/http" "net/http"
"github.com/containous/alice" "github.com/containous/alice"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0" semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"

View File

@ -10,10 +10,10 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/metrics"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/observability/metrics"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0" semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
"go.opentelemetry.io/otel/semconv/v1.37.0/httpconv" "go.opentelemetry.io/otel/semconv/v1.37.0/httpconv"

View File

@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/metrics"
"github.com/traefik/traefik/v3/pkg/middlewares/capture" "github.com/traefik/traefik/v3/pkg/middlewares/capture"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/observability/metrics"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
sdkmetric "go.opentelemetry.io/otel/sdk/metric" sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/metric/metricdata"
@ -54,7 +54,7 @@ func TestSemConvServerMetrics(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
var cfg types.OTLP var cfg otypes.OTLP
(&cfg).SetDefaults() (&cfg).SetDefaults()
cfg.AddRoutersLabels = true cfg.AddRoutersLabels = true
cfg.PushInterval = ptypes.Duration(10 * time.Millisecond) cfg.PushInterval = ptypes.Duration(10 * time.Millisecond)

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )

View File

@ -15,7 +15,7 @@ import (
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/middlewares/observability" "github.com/traefik/traefik/v3/pkg/middlewares/observability"
"github.com/traefik/traefik/v3/pkg/tracing" "github.com/traefik/traefik/v3/pkg/observability/tracing"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0" semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"

View File

@ -8,7 +8,8 @@ import (
"time" "time"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/observability"
"github.com/traefik/traefik/v3/pkg/observability/types"
otellog "go.opentelemetry.io/otel/log" otellog "go.opentelemetry.io/otel/log"
) )
@ -18,6 +19,9 @@ func SetupOTelLogger(ctx context.Context, logger zerolog.Logger, config *types.O
return logger, nil return logger, nil
} }
if err := observability.EnsureUserEnvVar(); err != nil {
return zerolog.Logger{}, err
}
provider, err := config.NewLoggerProvider(ctx) provider, err := config.NewLoggerProvider(ctx)
if err != nil { if err != nil {
return zerolog.Logger{}, fmt.Errorf("setting up OpenTelemetry logger provider: %w", err) return zerolog.Logger{}, fmt.Errorf("setting up OpenTelemetry logger provider: %w", err)

View File

@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"go.opentelemetry.io/collector/pdata/plog/plogotlp" "go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -160,10 +160,10 @@ func TestLog(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
config := &types.OTelLog{ config := &otypes.OTelLog{
ServiceName: "test", ServiceName: "test",
ResourceAttributes: map[string]string{"resource": "attribute"}, ResourceAttributes: map[string]string{"resource": "attribute"},
HTTP: &types.OTelHTTP{ HTTP: &otypes.OTelHTTP{
Endpoint: collector.URL, Endpoint: collector.URL,
}, },
} }

View File

@ -10,9 +10,9 @@ import (
"github.com/go-kit/kit/util/conn" "github.com/go-kit/kit/util/conn"
gokitlog "github.com/go-kit/log" gokitlog "github.com/go-kit/log"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/traefik/v3/pkg/types"
) )
const ( const (
@ -56,7 +56,7 @@ const (
) )
// RegisterDatadog registers the metrics pusher if this didn't happen yet and creates a datadog Registry instance. // RegisterDatadog registers the metrics pusher if this didn't happen yet and creates a datadog Registry instance.
func RegisterDatadog(ctx context.Context, config *types.Datadog) Registry { func RegisterDatadog(ctx context.Context, config *otypes.Datadog) Registry {
// Ensures there is only one DataDog client sending metrics at any given time. // Ensures there is only one DataDog client sending metrics at any given time.
StopDatadog() StopDatadog()
@ -109,7 +109,7 @@ func RegisterDatadog(ctx context.Context, config *types.Datadog) Registry {
return registry return registry
} }
func initDatadogClient(ctx context.Context, config *types.Datadog, logger gokitlog.LoggerFunc) { func initDatadogClient(ctx context.Context, config *otypes.Datadog, logger gokitlog.LoggerFunc) {
network, address := parseDatadogAddress(config.Address) network, address := parseDatadogAddress(config.Address)
ctx, datadogLoopCancelFunc = context.WithCancel(ctx) ctx, datadogLoopCancelFunc = context.WithCancel(ctx)

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stvp/go-udp-testing" "github.com/stvp/go-udp-testing"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
) )
func TestDatadog(t *testing.T) { func TestDatadog(t *testing.T) {
@ -19,7 +19,7 @@ func TestDatadog(t *testing.T) {
// This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond
udp.Timeout = 5 * time.Second udp.Timeout = 5 * time.Second
datadogRegistry := RegisterDatadog(t.Context(), &types.Datadog{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) datadogRegistry := RegisterDatadog(t.Context(), &otypes.Datadog{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true})
if !datadogRegistry.IsEpEnabled() || !datadogRegistry.IsRouterEnabled() || !datadogRegistry.IsSvcEnabled() { if !datadogRegistry.IsEpEnabled() || !datadogRegistry.IsRouterEnabled() || !datadogRegistry.IsSvcEnabled() {
t.Errorf("DatadogRegistry should return true for IsEnabled(), IsRouterEnabled() and IsSvcEnabled()") t.Errorf("DatadogRegistry should return true for IsEnabled(), IsRouterEnabled() and IsSvcEnabled()")
@ -34,7 +34,7 @@ func TestDatadogWithPrefix(t *testing.T) {
// This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond
udp.Timeout = 5 * time.Second udp.Timeout = 5 * time.Second
datadogRegistry := RegisterDatadog(t.Context(), &types.Datadog{Prefix: "testPrefix", Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) datadogRegistry := RegisterDatadog(t.Context(), &otypes.Datadog{Prefix: "testPrefix", Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true})
testDatadogRegistry(t, "testPrefix", datadogRegistry) testDatadogRegistry(t, "testPrefix", datadogRegistry)
} }

View File

@ -12,9 +12,9 @@ import (
influxdb2log "github.com/influxdata/influxdb-client-go/v2/log" influxdb2log "github.com/influxdata/influxdb-client-go/v2/log"
influxdb "github.com/influxdata/influxdb1-client/v2" influxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/traefik/v3/pkg/types"
) )
var ( var (
@ -52,7 +52,7 @@ const (
) )
// RegisterInfluxDB2 creates metrics exporter for InfluxDB2. // RegisterInfluxDB2 creates metrics exporter for InfluxDB2.
func RegisterInfluxDB2(ctx context.Context, config *types.InfluxDB2) Registry { func RegisterInfluxDB2(ctx context.Context, config *otypes.InfluxDB2) Registry {
logger := log.Ctx(ctx) logger := log.Ctx(ctx)
if influxDB2Client == nil { if influxDB2Client == nil {
@ -133,7 +133,7 @@ func StopInfluxDB2() {
} }
// newInfluxDB2Client creates an influxdb2.Client. // newInfluxDB2Client creates an influxdb2.Client.
func newInfluxDB2Client(config *types.InfluxDB2) (influxdb2.Client, error) { func newInfluxDB2Client(config *otypes.InfluxDB2) (influxdb2.Client, error) {
if config.Token == "" || config.Org == "" || config.Bucket == "" { if config.Token == "" || config.Org == "" || config.Bucket == "" {
return nil, errors.New("token, org or bucket property is missing") return nil, errors.New("token, org or bucket property is missing")
} }

View File

@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
) )
func TestInfluxDB2(t *testing.T) { func TestInfluxDB2(t *testing.T) {
@ -26,7 +26,7 @@ func TestInfluxDB2(t *testing.T) {
})) }))
influxDB2Registry := RegisterInfluxDB2(t.Context(), influxDB2Registry := RegisterInfluxDB2(t.Context(),
&types.InfluxDB2{ &otypes.InfluxDB2{
Address: ts.URL, Address: ts.URL,
Token: "test-token", Token: "test-token",
PushInterval: ptypes.Duration(10 * time.Millisecond), PushInterval: ptypes.Duration(10 * time.Millisecond),

View File

@ -11,6 +11,8 @@ import (
"github.com/go-kit/kit/metrics" "github.com/go-kit/kit/metrics"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/observability"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
"github.com/traefik/traefik/v3/pkg/version" "github.com/traefik/traefik/v3/pkg/version"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
@ -46,7 +48,11 @@ type SemConvMetricsRegistry struct {
} }
// NewSemConvMetricRegistry registers all stables semantic conventions metrics. // NewSemConvMetricRegistry registers all stables semantic conventions metrics.
func NewSemConvMetricRegistry(ctx context.Context, config *types.OTLP) (*SemConvMetricsRegistry, error) { func NewSemConvMetricRegistry(ctx context.Context, config *otypes.OTLP) (*SemConvMetricsRegistry, error) {
if err := observability.EnsureUserEnvVar(); err != nil {
return nil, err
}
if openTelemetryMeterProvider == nil { if openTelemetryMeterProvider == nil {
var err error var err error
if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil { if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil {
@ -96,7 +102,7 @@ func (s *SemConvMetricsRegistry) HTTPClientRequestDuration() httpconv.ClientRequ
} }
// RegisterOpenTelemetry registers all OpenTelemetry metrics. // RegisterOpenTelemetry registers all OpenTelemetry metrics.
func RegisterOpenTelemetry(ctx context.Context, config *types.OTLP) Registry { func RegisterOpenTelemetry(ctx context.Context, config *otypes.OTLP) Registry {
if openTelemetryMeterProvider == nil { if openTelemetryMeterProvider == nil {
var err error var err error
if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil { if openTelemetryMeterProvider, err = newOpenTelemetryMeterProvider(ctx, config); err != nil {
@ -189,7 +195,7 @@ func StopOpenTelemetry() {
} }
// newOpenTelemetryMeterProvider creates a new controller.Controller. // newOpenTelemetryMeterProvider creates a new controller.Controller.
func newOpenTelemetryMeterProvider(ctx context.Context, config *types.OTLP) (*sdkmetric.MeterProvider, error) { func newOpenTelemetryMeterProvider(ctx context.Context, config *otypes.OTLP) (*sdkmetric.MeterProvider, error) {
var ( var (
exporter sdkmetric.Exporter exporter sdkmetric.Exporter
err error err error
@ -250,7 +256,7 @@ func newOpenTelemetryMeterProvider(ctx context.Context, config *types.OTLP) (*sd
return meterProvider, nil return meterProvider, nil
} }
func newHTTPExporter(ctx context.Context, config *types.OTelHTTP) (sdkmetric.Exporter, error) { func newHTTPExporter(ctx context.Context, config *otypes.OTelHTTP) (sdkmetric.Exporter, error) {
endpoint, err := url.Parse(config.Endpoint) endpoint, err := url.Parse(config.Endpoint)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err) return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err)
@ -282,7 +288,7 @@ func newHTTPExporter(ctx context.Context, config *types.OTelHTTP) (sdkmetric.Exp
return otlpmetrichttp.New(ctx, opts...) return otlpmetrichttp.New(ctx, opts...)
} }
func newGRPCExporter(ctx context.Context, config *types.OTelGRPC) (sdkmetric.Exporter, error) { func newGRPCExporter(ctx context.Context, config *otypes.OTelGRPC) (sdkmetric.Exporter, error) {
host, port, err := net.SplitHostPort(config.Endpoint) host, port, err := net.SplitHostPort(config.Endpoint)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err) return nil, fmt.Errorf("invalid collector endpoint %q: %w", config.Endpoint, err)

View File

@ -15,7 +15,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/version" "github.com/traefik/traefik/v3/pkg/version"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
@ -323,10 +323,10 @@ func TestOpenTelemetry(t *testing.T) {
ts.Close() ts.Close()
}) })
var cfg types.OTLP var cfg otypes.OTLP
(&cfg).SetDefaults() (&cfg).SetDefaults()
cfg.AddRoutersLabels = true cfg.AddRoutersLabels = true
cfg.HTTP = &types.OTelHTTP{ cfg.HTTP = &otypes.OTelHTTP{
Endpoint: ts.URL, Endpoint: ts.URL,
} }
cfg.PushInterval = ptypes.Duration(10 * time.Millisecond) cfg.PushInterval = ptypes.Duration(10 * time.Millisecond)

View File

@ -13,7 +13,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
) )
const ( const (
@ -80,7 +80,7 @@ func PrometheusHandler() http.Handler {
// RegisterPrometheus registers all Prometheus metrics. // RegisterPrometheus registers all Prometheus metrics.
// It must be called only once and failing to register the metrics will lead to a panic. // It must be called only once and failing to register the metrics will lead to a panic.
func RegisterPrometheus(ctx context.Context, config *types.Prometheus) Registry { func RegisterPrometheus(ctx context.Context, config *otypes.Prometheus) Registry {
standardRegistry := initStandardRegistry(config) standardRegistry := initStandardRegistry(config)
if err := promRegistry.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})); err != nil { if err := promRegistry.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})); err != nil {
@ -104,7 +104,7 @@ func RegisterPrometheus(ctx context.Context, config *types.Prometheus) Registry
return standardRegistry return standardRegistry
} }
func initStandardRegistry(config *types.Prometheus) Registry { func initStandardRegistry(config *otypes.Prometheus) Registry {
buckets := []float64{0.1, 0.3, 1.2, 5.0} buckets := []float64{0.1, 0.3, 1.2, 5.0}
if config.Buckets != nil { if config.Buckets != nil {
buckets = config.Buckets buckets = config.Buckets

View File

@ -11,8 +11,8 @@ import (
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
th "github.com/traefik/traefik/v3/pkg/testhelpers" th "github.com/traefik/traefik/v3/pkg/testhelpers"
"github.com/traefik/traefik/v3/pkg/types"
) )
func TestRegisterPromState(t *testing.T) { func TestRegisterPromState(t *testing.T) {
@ -20,42 +20,42 @@ func TestRegisterPromState(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
prometheusSlice []*types.Prometheus prometheusSlice []*otypes.Prometheus
initPromState bool initPromState bool
unregisterPromState bool unregisterPromState bool
expectedNbRegistries int expectedNbRegistries int
}{ }{
{ {
desc: "Register once", desc: "Register once",
prometheusSlice: []*types.Prometheus{{}}, prometheusSlice: []*otypes.Prometheus{{}},
initPromState: true, initPromState: true,
unregisterPromState: false, unregisterPromState: false,
expectedNbRegistries: 1, expectedNbRegistries: 1,
}, },
{ {
desc: "Register once with no promState init", desc: "Register once with no promState init",
prometheusSlice: []*types.Prometheus{{}}, prometheusSlice: []*otypes.Prometheus{{}},
initPromState: false, initPromState: false,
unregisterPromState: false, unregisterPromState: false,
expectedNbRegistries: 1, expectedNbRegistries: 1,
}, },
{ {
desc: "Register twice", desc: "Register twice",
prometheusSlice: []*types.Prometheus{{}, {}}, prometheusSlice: []*otypes.Prometheus{{}, {}},
initPromState: true, initPromState: true,
unregisterPromState: false, unregisterPromState: false,
expectedNbRegistries: 2, expectedNbRegistries: 2,
}, },
{ {
desc: "Register twice with no promstate init", desc: "Register twice with no promstate init",
prometheusSlice: []*types.Prometheus{{}, {}}, prometheusSlice: []*otypes.Prometheus{{}, {}},
initPromState: false, initPromState: false,
unregisterPromState: false, unregisterPromState: false,
expectedNbRegistries: 2, expectedNbRegistries: 2,
}, },
{ {
desc: "Register twice with unregister", desc: "Register twice with unregister",
prometheusSlice: []*types.Prometheus{{}, {}}, prometheusSlice: []*otypes.Prometheus{{}, {}},
initPromState: true, initPromState: true,
unregisterPromState: true, unregisterPromState: true,
expectedNbRegistries: 2, expectedNbRegistries: 2,
@ -90,7 +90,7 @@ func TestPrometheus(t *testing.T) {
promRegistry = prometheus.NewRegistry() promRegistry = prometheus.NewRegistry()
t.Cleanup(promState.reset) t.Cleanup(promState.reset)
prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{ prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{
AddEntryPointsLabels: true, AddEntryPointsLabels: true,
AddRoutersLabels: true, AddRoutersLabels: true,
AddServicesLabels: true, AddServicesLabels: true,
@ -404,7 +404,7 @@ func TestPrometheusMetricRemoval(t *testing.T) {
promRegistry = prometheus.NewRegistry() promRegistry = prometheus.NewRegistry()
t.Cleanup(promState.reset) t.Cleanup(promState.reset)
prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true, AddRoutersLabels: true}) prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true, AddRoutersLabels: true})
defer promRegistry.Unregister(promState) defer promRegistry.Unregister(promState)
conf1 := dynamic.Configuration{ conf1 := dynamic.Configuration{
@ -495,7 +495,7 @@ func TestPrometheusMetricRemoveEndpointForRecoveredService(t *testing.T) {
promRegistry = prometheus.NewRegistry() promRegistry = prometheus.NewRegistry()
t.Cleanup(promState.reset) t.Cleanup(promState.reset)
prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddServicesLabels: true}) prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddServicesLabels: true})
defer promRegistry.Unregister(promState) defer promRegistry.Unregister(promState)
conf1 := dynamic.Configuration{ conf1 := dynamic.Configuration{
@ -534,7 +534,7 @@ func TestPrometheusMetricRemoveEndpointForRecoveredService(t *testing.T) {
func TestPrometheusRemovedMetricsReset(t *testing.T) { func TestPrometheusRemovedMetricsReset(t *testing.T) {
t.Cleanup(promState.reset) t.Cleanup(promState.reset)
prometheusRegistry := RegisterPrometheus(t.Context(), &types.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true}) prometheusRegistry := RegisterPrometheus(t.Context(), &otypes.Prometheus{AddEntryPointsLabels: true, AddServicesLabels: true})
defer promRegistry.Unregister(promState) defer promRegistry.Unregister(promState)
conf1 := dynamic.Configuration{ conf1 := dynamic.Configuration{

View File

@ -6,9 +6,9 @@ import (
"github.com/go-kit/kit/metrics/statsd" "github.com/go-kit/kit/metrics/statsd"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/traefik/v3/pkg/types"
) )
var ( var (
@ -45,7 +45,7 @@ const (
) )
// RegisterStatsd registers the metrics pusher if this didn't happen yet and creates a statsd Registry instance. // RegisterStatsd registers the metrics pusher if this didn't happen yet and creates a statsd Registry instance.
func RegisterStatsd(ctx context.Context, config *types.Statsd) Registry { func RegisterStatsd(ctx context.Context, config *otypes.Statsd) Registry {
// just to be sure there is a prefix defined // just to be sure there is a prefix defined
if config.Prefix == "" { if config.Prefix == "" {
config.Prefix = defaultMetricsPrefix config.Prefix = defaultMetricsPrefix
@ -97,7 +97,7 @@ func RegisterStatsd(ctx context.Context, config *types.Statsd) Registry {
} }
// initStatsdTicker initializes metrics pusher and creates a statsdClient if not created already. // initStatsdTicker initializes metrics pusher and creates a statsdClient if not created already.
func initStatsdTicker(ctx context.Context, config *types.Statsd) *time.Ticker { func initStatsdTicker(ctx context.Context, config *otypes.Statsd) *time.Ticker {
address := config.Address address := config.Address
if len(address) == 0 { if len(address) == 0 {
address = "localhost:8125" address = "localhost:8125"

View File

@ -8,7 +8,7 @@ import (
"github.com/stvp/go-udp-testing" "github.com/stvp/go-udp-testing"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
) )
func TestStatsD(t *testing.T) { func TestStatsD(t *testing.T) {
@ -20,7 +20,7 @@ func TestStatsD(t *testing.T) {
// This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond
udp.Timeout = 5 * time.Second udp.Timeout = 5 * time.Second
statsdRegistry := RegisterStatsd(t.Context(), &types.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true}) statsdRegistry := RegisterStatsd(t.Context(), &otypes.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true})
testRegistry(t, defaultMetricsPrefix, statsdRegistry) testRegistry(t, defaultMetricsPrefix, statsdRegistry)
} }
@ -34,7 +34,7 @@ func TestStatsDWithPrefix(t *testing.T) {
// This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond // This is needed to make sure that UDP Listener listens for data a bit longer, otherwise it will quit after a millisecond
udp.Timeout = 5 * time.Second udp.Timeout = 5 * time.Second
statsdRegistry := RegisterStatsd(t.Context(), &types.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true, Prefix: "testPrefix"}) statsdRegistry := RegisterStatsd(t.Context(), &otypes.Statsd{Address: ":18125", PushInterval: ptypes.Duration(time.Second), AddEntryPointsLabels: true, AddRoutersLabels: true, AddServicesLabels: true, Prefix: "testPrefix"})
testRegistry(t, "testPrefix", statsdRegistry) testRegistry(t, "testPrefix", statsdRegistry)
} }

View File

@ -0,0 +1,15 @@
package observability
import (
"fmt"
"os"
)
func EnsureUserEnvVar() error {
if os.Getenv("USER") == "" {
if err := os.Setenv("USER", "traefik"); err != nil {
return fmt.Errorf("could not set USER environment variable: %w", err)
}
}
return nil
}

View File

@ -13,7 +13,8 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/observability"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"go.opentelemetry.io/contrib/propagators/autoprop" "go.opentelemetry.io/contrib/propagators/autoprop"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
@ -38,10 +39,14 @@ func NewTracing(ctx context.Context, conf *static.Tracing) (*Tracer, io.Closer,
if backend == nil { if backend == nil {
log.Debug().Msg("Could not initialize tracing, using OpenTelemetry by default") log.Debug().Msg("Could not initialize tracing, using OpenTelemetry by default")
defaultBackend := &types.OTelTracing{} defaultBackend := &otypes.OTelTracing{}
backend = defaultBackend backend = defaultBackend
} }
if err := observability.EnsureUserEnvVar(); err != nil {
return nil, nil, err
}
otel.SetTextMapPropagator(autoprop.NewTextMapPropagator()) otel.SetTextMapPropagator(autoprop.NewTextMapPropagator())
tr, closer, err := backend.Setup(ctx, conf.ServiceName, conf.SampleRate, conf.ResourceAttributes) tr, closer, err := backend.Setup(ctx, conf.ServiceName, conf.SampleRate, conf.ResourceAttributes)

View File

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/traefik/traefik/v3/pkg/config/static" "github.com/traefik/traefik/v3/pkg/config/static"
"github.com/traefik/traefik/v3/pkg/types" otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp" "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
@ -355,8 +355,8 @@ func TestTracing(t *testing.T) {
ServiceName: "traefik", ServiceName: "traefik",
SampleRate: 1.0, SampleRate: 1.0,
ResourceAttributes: test.resourceAttributes, ResourceAttributes: test.resourceAttributes,
OTLP: &types.OTelTracing{ OTLP: &otypes.OTelTracing{
HTTP: &types.OTelHTTP{ HTTP: &otypes.OTelHTTP{
Endpoint: collector.URL, Endpoint: collector.URL,
}, },
}, },
@ -410,7 +410,7 @@ func TestTracing(t *testing.T) {
func TestTracerProvider(t *testing.T) { func TestTracerProvider(t *testing.T) {
t.Parallel() t.Parallel()
otlpConfig := &types.OTelTracing{} otlpConfig := &otypes.OTelTracing{}
otlpConfig.SetDefaults() otlpConfig.SetDefaults()
config := &static.Tracing{OTLP: otlpConfig} config := &static.Tracing{OTLP: otlpConfig}

View File

@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"github.com/traefik/paerser/types" "github.com/traefik/paerser/types"
ttypes "github.com/traefik/traefik/v3/pkg/types"
"github.com/traefik/traefik/v3/pkg/version" "github.com/traefik/traefik/v3/pkg/version"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc" "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc"
@ -189,7 +190,7 @@ func (o *OTelLog) NewLoggerProvider(ctx context.Context) (*otelsdk.LoggerProvide
resource.WithOS(), resource.WithOS(),
resource.WithProcess(), resource.WithProcess(),
resource.WithTelemetrySDK(), resource.WithTelemetrySDK(),
resource.WithDetectors(K8sAttributesDetector{}), resource.WithDetectors(ttypes.K8sAttributesDetector{}),
// The following order allows the user to override the service name and version, // The following order allows the user to override the service name and version,
// as well as any other attributes set by the above detectors. // as well as any other attributes set by the above detectors.
resource.WithAttributes( resource.WithAttributes(

View File

@ -1,10 +1,12 @@
package types package types
import "github.com/traefik/traefik/v3/pkg/types"
// OTelGRPC provides configuration settings for the gRPC open-telemetry. // OTelGRPC provides configuration settings for the gRPC open-telemetry.
type OTelGRPC struct { type OTelGRPC struct {
Endpoint string `description:"Sets the gRPC endpoint (host:port) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint string `description:"Sets the gRPC endpoint (host:port) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"`
Insecure bool `description:"Disables client transport security for the exporter." json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty" export:"true"` Insecure bool `description:"Disables client transport security for the exporter." json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty" export:"true"`
TLS *ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` TLS *types.ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"`
Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"` Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"`
} }
@ -16,7 +18,7 @@ func (o *OTelGRPC) SetDefaults() {
// OTelHTTP provides configuration settings for the HTTP open-telemetry. // OTelHTTP provides configuration settings for the HTTP open-telemetry.
type OTelHTTP struct { type OTelHTTP struct {
Endpoint string `description:"Sets the HTTP endpoint (scheme://host:port/path) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"` Endpoint string `description:"Sets the HTTP endpoint (scheme://host:port/path) of the collector." json:"endpoint,omitempty" toml:"endpoint,omitempty" yaml:"endpoint,omitempty"`
TLS *ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"` TLS *types.ClientTLS `description:"Defines client transport security parameters." json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" export:"true"`
Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"` Headers map[string]string `description:"Headers sent with payload." json:"headers,omitempty" toml:"headers,omitempty" yaml:"headers,omitempty"`
} }

View File

@ -9,6 +9,7 @@ import (
"time" "time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
ttypes "github.com/traefik/traefik/v3/pkg/types"
"github.com/traefik/traefik/v3/pkg/version" "github.com/traefik/traefik/v3/pkg/version"
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
@ -77,7 +78,7 @@ func (c *OTelTracing) Setup(ctx context.Context, serviceName string, sampleRate
resource.WithOS(), resource.WithOS(),
resource.WithProcess(), resource.WithProcess(),
resource.WithTelemetrySDK(), resource.WithTelemetrySDK(),
resource.WithDetectors(K8sAttributesDetector{}), resource.WithDetectors(ttypes.K8sAttributesDetector{}),
// The following order allows the user to override the service name and version, // The following order allows the user to override the service name and version,
// as well as any other attributes set by the above detectors. // as well as any other attributes set by the above detectors.
resource.WithAttributes( resource.WithAttributes(

View File

@ -14,8 +14,8 @@ import (
"github.com/http-wasm/http-wasm-host-go/handler" "github.com/http-wasm/http-wasm-host-go/handler"
wasm "github.com/http-wasm/http-wasm-host-go/handler/nethttp" wasm "github.com/http-wasm/http-wasm-host-go/handler/nethttp"
"github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero"
"github.com/traefik/traefik/v3/pkg/logs"
"github.com/traefik/traefik/v3/pkg/middlewares" "github.com/traefik/traefik/v3/pkg/middlewares"
"github.com/traefik/traefik/v3/pkg/observability/logs"
) )
type wasmMiddlewareBuilder struct { type wasmMiddlewareBuilder struct {

View File

@ -13,7 +13,7 @@ import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/yaegi/interp" "github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib" "github.com/traefik/yaegi/stdlib"
"github.com/traefik/yaegi/stdlib/unsafe" "github.com/traefik/yaegi/stdlib/unsafe"

View File

@ -11,7 +11,7 @@ import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/yaegi/interp" "github.com/traefik/yaegi/interp"

View File

@ -10,7 +10,7 @@ import (
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// Account is used to store lets encrypt registration info. // Account is used to store lets encrypt registration info.

View File

@ -13,7 +13,7 @@ import (
"github.com/go-acme/lego/v4/challenge/http01" "github.com/go-acme/lego/v4/challenge/http01"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
) )
// ChallengeHTTP HTTP challenge provider implements challenge.Provider. // ChallengeHTTP HTTP challenge provider implements challenge.Provider.

View File

@ -9,7 +9,7 @@ import (
"github.com/go-acme/lego/v4/challenge/tlsalpn01" "github.com/go-acme/lego/v4/challenge/tlsalpn01"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"

View File

@ -8,7 +8,7 @@ import (
"sync" "sync"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
) )

View File

@ -27,9 +27,9 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs"
httpmuxer "github.com/traefik/traefik/v3/pkg/muxer/http" httpmuxer "github.com/traefik/traefik/v3/pkg/muxer/http"
tcpmuxer "github.com/traefik/traefik/v3/pkg/muxer/tcp" tcpmuxer "github.com/traefik/traefik/v3/pkg/muxer/tcp"
"github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
traefiktls "github.com/traefik/traefik/v3/pkg/tls" traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"

View File

@ -13,7 +13,7 @@ import (
"github.com/Masterminds/sprig/v3" "github.com/Masterminds/sprig/v3"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/tls"
) )

View File

@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/config/label" "github.com/traefik/traefik/v3/pkg/config/label"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/constraints" "github.com/traefik/traefik/v3/pkg/provider/constraints"
) )

View File

@ -17,7 +17,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/constraints" "github.com/traefik/traefik/v3/pkg/provider/constraints"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"

View File

@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/config/label" "github.com/traefik/traefik/v3/pkg/config/label"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/constraints" "github.com/traefik/traefik/v3/pkg/provider/constraints"
) )

View File

@ -16,7 +16,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
) )

View File

@ -17,7 +17,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
) )

View File

@ -24,7 +24,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
) )

View File

@ -18,7 +18,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/paerser/file" "github.com/traefik/paerser/file"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/tls"

View File

@ -16,7 +16,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
"github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/tls"

View File

@ -24,7 +24,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/gateway" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/gateway"

View File

@ -11,7 +11,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"

View File

@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/tls"

View File

@ -19,7 +19,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"

View File

@ -20,7 +20,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"

View File

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/types" "github.com/traefik/traefik/v3/pkg/types"
) )
@ -61,7 +62,7 @@ func Test_parseRouterConfig(t *testing.T) {
AccessLogs: pointer(true), AccessLogs: pointer(true),
Tracing: pointer(true), Tracing: pointer(true),
Metrics: pointer(true), Metrics: pointer(true),
TraceVerbosity: types.MinimalVerbosity, TraceVerbosity: otypes.MinimalVerbosity,
}, },
}, },
}, },

View File

@ -21,7 +21,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"

View File

@ -17,6 +17,7 @@ import (
ptypes "github.com/traefik/paerser/types" ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
traefikhttp "github.com/traefik/traefik/v3/pkg/muxer/http" traefikhttp "github.com/traefik/traefik/v3/pkg/muxer/http"
otypes "github.com/traefik/traefik/v3/pkg/observability/types"
"github.com/traefik/traefik/v3/pkg/provider" "github.com/traefik/traefik/v3/pkg/provider"
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"
"github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/tls"
@ -127,7 +128,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
AccessLogs: pointer(true), AccessLogs: pointer(true),
Tracing: pointer(true), Tracing: pointer(true),
Metrics: pointer(true), Metrics: pointer(true),
TraceVerbosity: types.MinimalVerbosity, TraceVerbosity: otypes.MinimalVerbosity,
}, },
}, },
}, },

View File

@ -14,7 +14,7 @@ import (
"github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/config/kv" "github.com/traefik/traefik/v3/pkg/config/kv"
"github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/job"
"github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/observability/logs"
"github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/safe"
) )

Some files were not shown because too many files have changed in this diff Show More