SigNoz/signoz · error

invalid scope item type: %s

Error message

invalid scope item type: %s

What it means

buildSpanScopeQuery handles special span search scope keys (parent/entrypoint). If the filter item's key type is something other than the recognized scope types, the key name falls through to the error branch. Effectively an unrecognized span-scope filter key/type combination.

Source

Thrown at pkg/query-service/app/traces/v4/query_builder.go:253

	var query string
	if fs == nil || len(fs.Items) == 0 {
		return "", nil
	}
	for _, item := range fs.Items {
		// skip anything other than Span Search scope attribute
		if item.Key.Type != v3.AttributeKeyTypeSpanSearchScope {
			continue
		}
		keyName := strings.ToLower(item.Key.Key)

		if keyName == constants.SpanSearchScopeRoot {
			query = "parent_span_id = '' "
			return query, nil
		} else if keyName == constants.SpanSearchScopeEntryPoint {
			query = "((name, `resource_string_service$$name`) GLOBAL IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) AND parent_span_id != '' "
			return query, nil
		} else {
			return "", fmt.Errorf("invalid scope item type: %s", item.Key.Type)
		}
	}
	return "", nil
}

func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3.PanelType, options v3.QBOptions) (string, error) {
	tracesStart := utils.GetEpochNanoSecs(start)
	tracesEnd := utils.GetEpochNanoSecs(end)

	// -1800 this is added so that the bucket start considers all the fingerprints.
	bucketStart := tracesStart/NANOSECOND - 1800
	bucketEnd := tracesEnd / NANOSECOND

	timeFilter := fmt.Sprintf("(timestamp >= '%d' AND timestamp <= '%d') AND (ts_bucket_start >= %d AND ts_bucket_start <= %d)", tracesStart, tracesEnd, bucketStart, bucketEnd)

	filterSubQuery, err := BuildTracesFilterQuery(mq.Filters, true)
	if err != nil {
		return "", err

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Use the exact constants (constants.SpanSearchScopeEntryPoint etc.) defined in the siglens/signoz constants package for scope keys
  2. Upgrade query-service so its scope constants match the client
  3. Remove the invalid scope filter

Example fix

// before
{"key":{"key":"entry_point","type":"scope"}}

// after
{"key":{"key":"entrypoint","type":"scope"}} // matches constants.SpanSearchScopeEntryPoint
Defensive patterns

Strategy: validation

Validate before calling

const validScopes = map[string]bool{constants.SpanSearchScopeEntryPoint: true /* , parent */}
if item.Key.Type == v3.AttributeKeyTypeScope && !validScopes[item.Key.Key] {
    return fmt.Errorf("unknown scope key %s", item.Key.Key)
}

Type guard

func isValidScopeKey(name string) bool {
    return name == constants.SpanSearchScopeEntryPoint || name == constants.SpanSearchScopeParent
}

Prevention

When it happens

Trigger: Sending a filter where item.Key.Type designates a scope search but keyName is not the recognized parent or entrypoint scope constant (e.g. a misspelled scope name or a new scope type).

Common situations: Custom clients constructing span-scope filters by hand; frontend changes introducing new scope names before query-service supports them; version skew between UI and backend constants.

Related errors


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