Skip to content

Commit

Permalink
Merge pull request #89 from scality/improvement/COSI-61-disable-trace…
Browse files Browse the repository at this point in the history
…-export-if-endpoint-not-specified

COSI-61 disable trace export if endpoint not specified(default) and test new default behaviour in e2e feature tests (stdout export remains same)
  • Loading branch information
anurag4DSB authored Jan 9, 2025
2 parents 3cad181 + 2d4b483 commit f028105
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .github/scripts/setup_cosi_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions cmd/scality-cosi-driver/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
defaultMetricsPrefix = "scality_cosi_driver"
defaultMetricsAddress = ":8080"
defaultOtelStdout = false
defaultOtelEndpoint = "localhost:4318"
defaultOtelEndpoint = ""
defaultOtelServiceName = "cosi.scality.com"
)

Expand All @@ -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")
)
Expand Down Expand Up @@ -83,6 +83,7 @@ func init() {
"driverMetricsAddress", *driverMetricsAddress,
"driverOtelEndpoint", *driverOtelEndpoint,
"driverOtelStdout", *driverOtelStdout,
"driverOtelServiceName", *driverOtelServiceName,
)
}

Expand All @@ -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(
Expand Down
19 changes: 15 additions & 4 deletions helm/scality-cosi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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://<host>:<port>/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:
Expand Down

0 comments on commit f028105

Please sign in to comment.