From 2d4b4839cd03a1a241258a8e46e33c7c7be28710 Mon Sep 17 00:00:00 2001 From: Anurag Mittal Date: Wed, 8 Jan 2025 12:32:42 +0100 Subject: [PATCH] Disable trace export if endpoint not specified - Default functionality is to not export traces - Updated e2e tests for help to verify the same --- .github/scripts/setup_cosi_resources.sh | 4 ---- cmd/scality-cosi-driver/cmd.go | 13 +++++++++---- helm/scality-cosi-driver/values.yaml | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/scripts/setup_cosi_resources.sh b/.github/scripts/setup_cosi_resources.sh index 3639f64e..90c7e8a5 100755 --- a/.github/scripts/setup_cosi_resources.sh +++ b/.github/scripts/setup_cosi_resources.sh @@ -45,10 +45,6 @@ log_and_run docker build -t ghcr.io/scality/cosi-driver:latest . log_and_run echo "Loading COSI driver image into KIND cluster..." log_and_run kind load docker-image ghcr.io/scality/cosi-driver:latest --name object-storage-cluster -# Log trace output to std out for e2e tests -sed -i 's/# - "--driver-otel-stdout=false"/- "--driver-otel-stdout=true"/' kustomize/base/deployment.yaml -cat kustomize/base/deployment.yaml - # Step 5: Run COSI driver log_and_run echo "Applying COSI driver manifests..." if ! kubectl apply -k .; then diff --git a/cmd/scality-cosi-driver/cmd.go b/cmd/scality-cosi-driver/cmd.go index d2c69dd0..b71aa929 100644 --- a/cmd/scality-cosi-driver/cmd.go +++ b/cmd/scality-cosi-driver/cmd.go @@ -45,7 +45,7 @@ const ( defaultMetricsPrefix = "scality_cosi_driver" defaultMetricsAddress = ":8080" defaultOtelStdout = false - defaultOtelEndpoint = "localhost:4318" + defaultOtelEndpoint = "" defaultOtelServiceName = "cosi.scality.com" ) @@ -55,7 +55,7 @@ var ( driverMetricsAddress = flag.String("driver-metrics-address", defaultMetricsAddress, "The address (hostname:port) to expose Prometheus metrics, default: 0.0.0.0:8080") driverMetricsPath = flag.String("driver-metrics-path", defaultMetricsPath, "path for the metrics endpoint, default: /metrics") driverMetricsPrefix = flag.String("driver-custom-metrics-prefix", defaultMetricsPrefix, "prefix for the metrics, default: scality_cosi_driver") - driverOtelEndpoint = flag.String("driver-otel-endpoint", defaultOtelEndpoint, "OpenTelemetry endpoint to export traces, default: localhost:4318") + driverOtelEndpoint = flag.String("driver-otel-endpoint", defaultOtelEndpoint, "OpenTelemetry endpoint to export traces, default: \"\"") driverOtelStdout = flag.Bool("driver-otel-stdout", defaultOtelStdout, "Enable OpenTelemetry trace export to stdout, disables endpoint if enabled, default: false") driverOtelServiceName = flag.String("driver-otel-service-name", defaultOtelServiceName, "Service name for OpenTelemetry traces, default: cosi.scality.com") ) @@ -83,6 +83,7 @@ func init() { "driverMetricsAddress", *driverMetricsAddress, "driverOtelEndpoint", *driverOtelEndpoint, "driverOtelStdout", *driverOtelStdout, + "driverOtelServiceName", *driverOtelServiceName, ) } @@ -98,13 +99,17 @@ func initOpenTelemetry(ctx context.Context) (*sdktrace.TracerProvider, error) { return nil, fmt.Errorf("failed to initialize stdout exporter: %w", err) } klog.Info("OpenTelemetry tracing enabled with stdout exporter") - } else { - // Configure OTLP exporter + } else if *driverOtelEndpoint != "" { + // Configure OTLP exporter only if the endpoint is set exporter, err = otlptracehttp.New(ctx, otlptracehttp.WithEndpoint(*driverOtelEndpoint), otlptracehttp.WithInsecure()) if err != nil { return nil, fmt.Errorf("failed to initialize OTLP exporter: %w", err) } klog.InfoS("OpenTelemetry tracing enabled with OTLP exporter", "endpoint", *driverOtelEndpoint) + } else { + // If neither stdout nor endpoint is set, disable tracing + klog.Info("OpenTelemetry tracing is disabled (no exporter configured)") + return nil, nil } // Set up the tracer provider with the selected exporter tp := sdktrace.NewTracerProvider( diff --git a/helm/scality-cosi-driver/values.yaml b/helm/scality-cosi-driver/values.yaml index aa900149..77003c32 100644 --- a/helm/scality-cosi-driver/values.yaml +++ b/helm/scality-cosi-driver/values.yaml @@ -34,11 +34,22 @@ metrics: path: "/metrics" traces: - # endpoint for trace collector to send traces to - otel_endpoint: "http://localhost:4318" - # prints traces to stdout if true and does not send to collector + # Configure tracing for the application. + + # If both `otel_stdout` and `otel_endpoint` are set, `otel_stdout` takes precedence. + # Set `otel_stdout: false` and `otel_endpoint: ""` to disable tracing entirely. + + # The endpoint of the trace collector to which traces will be sent. + # Use an empty string ("") to disable endpoint-based trace collection. + # Use the format "http://:/v1/trace" to specify the collector endpoint. + otel_endpoint: "" + + # Enable stdout tracing by setting this to true. When enabled, traces will be printed + # to the console instead of being sent to the collector endpoint. otel_stdout: false - # Trace span service name + + # The name of the service to appear in trace spans, used for identification + # in observability tools. otel_service_name: "cosi.scality.com" resources: