sleuth traceid格式错误的id异常

nwlls2ji  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(285)

我有一个服务a,它调用我的服务b,它在SpringBoot上。服务a传递一个带有键x-b3-traceid和值1f99a12d-066e-4aac-a71a-e7d42d7fa7a3的请求头,但sleuth给出了以下异常:

2020-12-08 20:18:21,821 [XNIO-2 task-5] ERROR [org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor] [ZipkinHttpSpanExtractor.java:50] [trace=,span=]  - Exception occurred while trying to extract span from carrier
java.lang.IllegalArgumentException: Malformed id: 1f99a12d-066e-4aac-a71a-e7d42d7fa7a3
    at org.springframework.cloud.sleuth.Span.hexToId(Span.java:585)
    at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.buildParentSpan(ZipkinHttpSpanExtractor.java:90)
    at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.joinTrace(ZipkinHttpSpanExtractor.java:48)
    at org.springframework.cloud.sleuth.instrument.web.ZipkinHttpSpanExtractor.joinTrace(ZipkinHttpSpanExtractor.java:19)
    at org.springframework.cloud.sleuth.instrument.web.TraceFilter.createSpan(TraceFilter.java:375)
    at org.springframework.cloud.sleuth.instrument.web.TraceFilter.doFilter(TraceFilter.java:165)

从span类中,我认为traceid只能包含0-9和a-f

public static long hexToId(String lowerHex, int index) {
        Assert.hasText(lowerHex, "Can't convert empty hex string to long");
        long result = 0L;

        for(int endIndex = Math.min(index + 16, lowerHex.length()); index < endIndex; ++index) {
            char c = lowerHex.charAt(index);
            result <<= 4;
            if (c >= '0' && c <= '9') {
                result |= (long)(c - 48);
            } else {
                if (c < 'a' || c > 'f') {
                    throw new IllegalArgumentException("Malformed id: " + lowerHex);
                }

                result |= (long)(c - 97 + 10);
            }
        }

        return result;
    }

有没有办法让跟踪id通用?
我正在使用springboot1.5.13.release和springcloudsleuth内核/1.3.4.release

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题