alibaba/spring-ai-alibaba · warning

解析属性过滤条件失败

Error message

解析属性过滤条件失败: {}

What it means

TracingQueryBuilder builds an Elasticsearch-style query from a trace search request. When the 'attributes' filter JSON supplied by the client cannot be parsed or turned into field/value term filters, the builder logs this warning and silently drops the attribute filters instead of failing the request.

Solutions

  1. Fix the client to send attributes as a valid JSON object, e.g. {"http.status_code":"500"}
  2. Log and inspect the actual attributesJson value in the warning to find the syntax problem
  3. Server-side: validate/normalize the JSON before parsing and return a 400 for invalid input instead of silently dropping filters

Example fix

// before
String attrs = "{'key':'value'}"; // single quotes
// after
String attrs = "{\"key\":\"value\"}"; // valid JSON object
Defensive patterns

Strategy: validation

Validate before calling

if (attributesJson == null || attributesJson.isBlank()) throw new IllegalArgumentException("attributes must be a JSON object");
Object o = new com.fasterxml.jackson.databind.ObjectMapper().readValue(attributesJson, Object.class);
if (!(o instanceof Map)) throw new IllegalArgumentException("attributes must be a JSON object, got: " + o.getClass());

Type guard

boolean isValidAttributesJson(String s) {
    try { return new ObjectMapper().readValue(s, Map.class) != null; }
    catch (Exception e) { return false; }
}

Try / catch

try { queryBuilder.buildTracesQuery(req); } catch (IllegalArgumentException e) { return ResponseEntity.badRequest().body("invalid attributes filter: " + e.getMessage()); }

Prevention

When it happens

Trigger: buildTracesQuery -> addAttributesFilter receives attributesJson that is malformed JSON, not a JSON object, or contains nested/complex values that cannot be converted to a simple term query; the catch(Exception) around JSON parsing/filter construction fires.

Common situations: Frontend sending attributes as single-quoted or non-object JSON; passing an array instead of a map; values that are nested objects; URL-decoding issues stripping quotes from the JSON.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/6c3366e8eb63dff3. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/TracingQueryBuilder.java:252

    /**
     * 添加属性过滤条件
     */
    private void addAttributesFilter(BoolQuery.Builder boolQuery, String attributesJson) {
        try {
            @SuppressWarnings("unchecked")
            Map<String, Object> attributesMap = objectMapper.readValue(attributesJson, Map.class);
            
            for (Map.Entry<String, Object> entry : attributesMap.entrySet()) {
                String field = "attributes." + entry.getKey();
                Query attrQuery = Query.of(q -> q.term(t -> t
                    .field(field)
                    .value(String.valueOf(entry.getValue()))
                ));
                boolQuery.filter(attrQuery);
            }
        } catch (Exception e) {
            log.warn("解析属性过滤条件失败: {}", attributesJson, e);
        }
    }



    /**
     * 将ISO8601时间字符串转换为微秒时间戳
     */
    private Long convertISO8601ToMicroseconds(String iso8601Time) {
        try {
            java.time.Instant instant = java.time.Instant.parse(iso8601Time);
            // 转换为微秒
            return instant.toEpochMilli() * 1000;
        } catch (Exception e) {
            log.error("时间转换失败: {}", iso8601Time, e);
            return null;
        }
    }

View on GitHub (pinned to f82da0b50f)