only configure tracing in envoy if it is enabled in pomerium

This commit is contained in:
Joe Kralicky 2025-01-06 18:59:42 +00:00
parent 180c7e04af
commit de68673819
No known key found for this signature in database
GPG key ID: 75C4875F34A9FB79
3 changed files with 50 additions and 10 deletions

View file

@ -437,16 +437,6 @@ func grpcHealthChecks(name string) []*envoy_config_core_v3.HealthCheck {
ServiceName: name,
},
},
// EventLogger: []*envoy_config_core_v3.TypedExtensionConfig{
// {
// Name: "envoy.health_check.event_sink.file",
// TypedConfig: marshalAny(&envoy_extensions_eventsinks_file_v3.HealthCheckEventFileSink{
// EventLogPath: "/tmp/healthchecks",
// }),
// },
// },
// AlwaysLogHealthCheckFailures: true,
// AlwaysLogHealthCheckSuccess: true,
}}
}

View file

@ -15,13 +15,31 @@ import (
envoy_type_v3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
"github.com/pomerium/pomerium/config"
"github.com/pomerium/pomerium/config/envoyconfig/extensions"
"github.com/pomerium/pomerium/internal/telemetry/trace"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func isTracingEnabled(cfg *config.Options) bool {
if os.Getenv("OTEL_SDK_DISABLED") == "true" {
return false
}
switch cfg.TracingProvider {
case "none", "noop": // explicitly disabled from config
return false
case "": // unset
return trace.IsEnabledViaEnvironment()
default: // set to a non-empty value
return !trace.IsDisabledViaEnvironment()
}
}
func applyTracingConfig(
mgr *envoy_extensions_filters_network_http_connection_manager.HttpConnectionManager,
opts *config.Options,
) {
if !isTracingEnabled(opts) {
return
}
mgr.HttpFilters = append([]*envoy_extensions_filters_network_http_connection_manager.HttpFilter{
tracingMetadataFilter(),
}, mgr.HttpFilters...)

View file

@ -225,3 +225,35 @@ func (n NoopClient) Stop(context.Context) error {
func (n NoopClient) UploadTraces(context.Context, []*v1.ResourceSpans) error {
return nil
}
func IsDisabledViaEnvironment() bool {
if os.Getenv("OTEL_SDK_DISABLED") == "true" {
return true
}
exporter, ok := os.LookupEnv("OTEL_TRACES_EXPORTER")
if !ok {
return false
}
switch strings.ToLower(strings.TrimSpace(exporter)) {
case "none, noop":
return true
default:
return false
}
}
func IsEnabledViaEnvironment() bool {
if os.Getenv("OTEL_SDK_DISABLED") == "true" {
return false
}
exporter, ok := os.LookupEnv("OTEL_TRACES_EXPORTER")
if !ok {
return false
}
switch strings.ToLower(strings.TrimSpace(exporter)) {
case "none, noop", "":
return false
default:
return true
}
}