{"record":{"id":"bbfa2692ee91bc19","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-parse-long-type","errorCode":null,"errorMessage":"failed to parse Long type: {}","messagePattern":"failed to parse Long type: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/TracingRepositoryImpl.java","lineNumber":404,"sourceCode":"            .build();\n    }\n\n    // 辅助方法\n    private String getString(Map<String, Object> map, String key) {\n        Object value = map.get(key);\n        return value != null ? value.toString() : null;\n    }\n\n    private Long getLong(Map<String, Object> map, String key) {\n        Object value = map.get(key);\n        if (value instanceof Number) {\n            return ((Number) value).longValue();\n        }\n        if (value instanceof String) {\n            try {\n                return Long.parseLong((String) value);\n            } catch (NumberFormatException e) {\n                log.warn(\"failed to parse Long type: {}\", value, e);\n                return null;\n            }\n        }\n        log.warn(\"failed to parse Long type: {}\", value);\n        return null;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private List<SpanLinkDTO> convertSpanLinks(List<Map<String, Object>> links) {\n        if (links == null) return new ArrayList<>();\n        \n        return links.stream()\n            .map(link -> SpanLinkDTO.builder()\n                .traceId(getString(link, \"traceID\"))\n                .spanId(getString(link, \"spanID\"))\n                .attributes((Map<String, Object>) link.get(\"attribute\"))\n                .build())\n            .collect(Collectors.toList());","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/TracingRepositoryImpl.java#L386-L422","documentation":"TracingRepositoryImpl.getLong converts raw stored values (Number or String) into Long. When a String value cannot be parsed as a long, it logs 'failed to parse Long type' with the offending value and returns null so the caller (startTimeUs/endTimeUs/durationUs/convertSpanEvents) skips the field.","triggerScenarios":"A span attribute or field stored as a String that is not a numeric long (e.g. '12.5', 'abc', '1e9', empty string, or a value with units) is passed to Long.parseLong.","commonSituations":"Tracing backends storing duration as '12.5ms' or floats as strings; span events containing non-numeric attribute values that the converter assumes are timestamps/durations.","solutions":["Inspect the logged value in the warning to find the malformed span attribute","Fix or clean the data at the source so numeric fields are stored as numbers or integer strings","Extend getLong to handle Float/Double inputs (((Number)value).longValue()) and trim strings before parsing"],"exampleFix":"// before\nif (value instanceof String) {\n    try { return Long.parseLong((String) value); }\n    catch (NumberFormatException e) { log.warn(...); return null; }\n}\n// after\nif (value instanceof Number n) return n.longValue();\nif (value instanceof String s) {\n    try { return Long.parseLong(s.trim()); }\n    catch (NumberFormatException e) {\n        try { return (long) Double.parseDouble(s.trim()); }\n        catch (NumberFormatException ex) { log.warn(...); return null; }\n    }\n}","handlingStrategy":"type-guard","validationCode":"if (value instanceof Number || (value instanceof String s && s.matches(\"-?\\\\d+\"))) { /* safe to convert */ }","typeGuard":"Long asLong(Object v) {\n    if (v instanceof Number n) return n.longValue();\n    if (v instanceof String s) { try { return Long.parseLong(s.trim()); } catch (NumberFormatException e) { return null; } }\n    return null;\n}","tryCatchPattern":"Long ts = getLong(attr, \"start_time\");\nif (ts == null) { log.warn(\"skipping span with unparseable start_time: {}\", attr.get(\"start_time\")); return; }","preventionTips":["Store numeric tracing fields as numbers, not strings","Avoid float/unit-suffixed values (\"12.5ms\", \"1e9\") in timestamp/duration attributes","Scrub span attributes at export time"],"tags":["tracing","type-conversion","parsing","long"],"backgroundTag":"type-mismatch","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}