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
- Fix the client to send attributes as a valid JSON object, e.g. {"http.status_code":"500"}
- Log and inspect the actual attributesJson value in the warning to find the syntax problem
- 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
- Always send attributes as a JSON object with string/number values
- URL-encode JSON query params properly
- Validate filters client-side before submitting the trace search
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
- APP_COMPONENT_DETAIL_ERROR
- ChatClient successfully returned, but the returned json is…
- CreateMCPServerError
- 序列化 defaultParameters 失败
- Delete operation failed
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)