SigNoz/signoz · error

invalid data type, expected int, got %v

Error message

invalid data type, expected int, got %v

What it means

Thrown by ValidateAndCastValue in SigNoz query-service when an attribute filter value declared as an int-typed attribute (e.g. []int64 via a string array) contains an element that is neither a numeric-parsable string nor int/int64, e.g. a bool, float, or nil inside the array.

Source

Thrown at pkg/query-service/utils/format.go:86

		case bool:
			return x, nil
		case string:
			boolean, err := strconv.ParseBool(x)
			if err != nil {
				return nil, fmt.Errorf("invalid data type, expected bool, got %v", reflect.TypeOf(v))
			}
			return boolean, nil
		default:
			return nil, fmt.Errorf("invalid data type, expected bool, got %v", reflect.TypeOf(v))
		}
	case v3.AttributeKeyDataTypeInt64:
		switch x := v.(type) {
		case []interface{}:
			for i, val := range x {
				if _, ok := val.(string); ok {
					int64val, err := strconv.ParseInt(val.(string), 10, 64)
					if err != nil {
						return nil, fmt.Errorf("invalid data type, expected int, got %v", reflect.TypeOf(val))
					}
					x[i] = int64val
				} else if _, ok := val.(int); ok {
					x[i] = int64(val.(int))
				} else if _, ok := val.(int64); !ok {
					return nil, fmt.Errorf("invalid data type, expected int, got %v", reflect.TypeOf(val))
				} else {
					x[i] = val.(int64)
				}
			}
			return x, nil
		case int, int64:
			return x, nil
		case float32:
			return int64(x), nil
		case float64:
			return int64(x), nil
		case string:

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Ensure all elements of the value array are int64 or strings parsable by strconv.ParseInt (base 10, 64-bit)
  2. Pre-normalize JSON-decoded numbers (encoding/json yields float64) to int64 before calling the query builder
  3. If float values are legitimate, change the filter key's dataType to Float64 instead of Int64
  4. Send values as int64-typed JSON numbers without decimal points or scientific notation

Example fix

// before
filter.Value = []interface{}{1.5, "2"}
// after
filter.Value = []interface{}{int64(1), int64(2)}
Defensive patterns

Strategy: validation

Validate before calling

func validIntArr(v interface{}) bool {
	arr, ok := v.([]interface{})
	if !ok { return false }
	for _, e := range arr {
		switch e.(type) {
		case int, int64, string:
			if s, isS := e.(string); isS {
				if _, err := strconv.ParseInt(s, 10, 64); err != nil { return false }
			}
		default:
			return false
		}
	}
	return true
}

Type guard

func isIntFilterValue(v interface{}) bool {
	switch v.(type) {
	case int, int64, string: return true
	case []interface{}: return validIntArr(v)
	}
	return false
}

Try / catch

if _, err := utils.ValidateAndCastValue(v, v3.AttributeKeyDataTypeInt64); err != nil { return httperr.BadRequest(fmt.Sprintf("invalid int filter value: %v", err)) }

Prevention

When it happens

Trigger: Calling buildTracesFilterQuery / BuildTracesFilterQuery or buildResourceFiltersFromFilterItems with a filter item whose key dataType is v3.AttributeKeyDataTypeInt64 and whose value is []interface{} containing a non-int element (bool, float64, null, nested object).

Common situations: Frontend or API client sends {"value": [1.5, "abc", true]} for an int64 attribute key; JSON numbers decoded as float64 by encoding/json; schema drift where an attribute was logged once as float/string and now filtered as int.

Related errors


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