SigNoz/signoz · error

timeShiftBy param should be a number

Error message

timeShiftBy param should be a number

What it means

timeShift's first argument must be a number (or a string parseable as a float). This error fires when Args[0] is neither float64 nor a string that strconv.ParseFloat can parse (the failed string type-assertion would panic otherwise; a parse error returns this message).

Source

Thrown at pkg/query-service/model/v3/v3.go:1123

	if b.Expression == "" {
		return fmt.Errorf("expression is required")
	}

	if len(b.Functions) > 0 {
		for _, function := range b.Functions {
			if err := function.Name.Validate(); err != nil {
				return fmt.Errorf("function name is invalid: %w", err)
			}
			if function.Name == FunctionNameTimeShift {
				if len(function.Args) == 0 {
					return fmt.Errorf("timeShiftBy param missing in query")
				}
				_, ok := function.Args[0].(float64)
				if !ok {
					// if string, attempt to convert to float
					timeShiftBy, err := strconv.ParseFloat(function.Args[0].(string), 64)
					if err != nil {
						return fmt.Errorf("timeShiftBy param should be a number")
					}
					function.Args[0] = timeShiftBy
				}
			} else if function.Name == FunctionNameEWMA3 ||
				function.Name == FunctionNameEWMA5 ||
				function.Name == FunctionNameEWMA7 {
				if len(function.Args) == 0 {
					return fmt.Errorf("alpha param missing in query")
				}
				alpha, ok := function.Args[0].(float64)
				if !ok {
					// if string, attempt to convert to float
					alpha, err := strconv.ParseFloat(function.Args[0].(string), 64)
					if err != nil {
						return fmt.Errorf("alpha param should be a float")
					}
					function.Args[0] = alpha
				}

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Pass the shift as a plain number of seconds (3600) or a numeric string ("3600")
  2. Convert duration strings to seconds client-side before building the query

Example fix

// before
{"name":"timeShift","args":["1h"]}
// after
{"name":"timeShift","args":[3600]}
Defensive patterns

Strategy: type-guard

Validate before calling

if _, err := strconv.ParseFloat(fmt.Sprint(args[0]), 64); err != nil { return fmt.Errorf("timeShift arg must be numeric") }

Type guard

func isNumericArg(a interface{}) bool {
  switch a.(type) { case float64, int: return true; case string: _, err := strconv.ParseFloat(a.(string), 64); return err == nil }
  return false
}

Prevention

When it happens

Trigger: "args":["1h"] or [null] or [true] for timeShift — the code only accepts float64 or numeric strings like "3600".

Common situations: Passing duration strings ("30m", "1h") instead of seconds; JSON where the value arrives as a map or null; language clients that serialize numbers as non-numeric strings.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/47dc567e51dd83a2. Report an issue: GitHub.