From 745b0a8c09ad9d0866da67403ffa99d11ba70ec3 Mon Sep 17 00:00:00 2001 From: vickkkkkyy Date: Tue, 24 Mar 2026 01:14:28 +0800 Subject: [PATCH] cmd/utils: guard SampleRatio flag with IsSet check (#34062) In `setOpenTelemetry`, all other fields (Enabled, Endpoint, AuthUser, AuthPassword, InstanceID, Tags) are guarded by `ctx.IsSet()` checks, so they only override the config file when explicitly set via CLI flags. `SampleRatio` was the only field missing this guard, causing the flag default (`1.0`) to always overwrite whatever was loaded from the config file. - Fix OpenTelemetry `SampleRatio` being unconditionally overwritten by the CLI flag default value (`1.0`), even when the user did not pass `--rpc.telemetry.sample-ratio` - This caused config file values for `SampleRatio` to be silently ignored --- cmd/utils/flags.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3a0bcc6b05..c1284044eb 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1584,7 +1584,9 @@ func setOpenTelemetry(ctx *cli.Context, cfg *node.Config) { if ctx.IsSet(RPCTelemetryTagsFlag.Name) { tcfg.Tags = ctx.String(RPCTelemetryTagsFlag.Name) } - tcfg.SampleRatio = ctx.Float64(RPCTelemetrySampleRatioFlag.Name) + if ctx.IsSet(RPCTelemetrySampleRatioFlag.Name) { + tcfg.SampleRatio = ctx.Float64(RPCTelemetrySampleRatioFlag.Name) + } if tcfg.Endpoint != "" && !tcfg.Enabled { log.Warn(fmt.Sprintf("OpenTelemetry endpoint configured but telemetry is not enabled, use --%s to enable.", RPCTelemetryFlag.Name))