Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report spans to SkyWalking #449

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Conversation

chenzhao11
Copy link

Motivation:

支持上报span数据到Skywalking中

Modification:

异步上报

使用http上报Json格式的segment数据到后端,上报时以message为单位,多个segment组合成一个message。流程如下图,span结束后将转换好的segment加入到segment缓冲数组中,另一个线程不断到数组中刷新数据到message,当message的大小达到最大值或等待发送的时间达到设定值就发送一次数据。

设置的message最大为2MB,计算每个segment的字节大小方法是把segment转换成Json String计算其长度,长度作为这个segment的字节大小。

image

关于拓扑图的展示问题的讨论

#443

这次提交的结果,设置skipAnalysistrue,不显示拓扑图和其他的一个指标只能查询trace信息

设置error

使用的是其他插件中使用的判断方法,这样当404的时候也会显示为错误

    private boolean isHttpOrMvcSuccess(String resultCode) {
        return resultCode.charAt(0) == '1' || resultCode.charAt(0) == '2'
               || "302".equals(resultCode.trim()) || ("301".equals(resultCode.trim()));
    }

    private boolean isWebHttpClientSuccess(String resultCode) {
        return StringUtils.isNotBlank(resultCode)
               && (isHttpOrMvcSuccess(resultCode) || SofaTracerConstant.RESULT_CODE_SUCCESS
                   .equals(resultCode));
    }

SegmentId

每一个segment中只有一个span,在segment中的spanId是从0开始的递增整数。在转换过程中

segmentId = traceId + SpanId + server/client ,其中server和client分别用0和1代替。最后需要加上client和server的原因是在Dubbo和SOFARpc中存在 server -> server 的情况,其中RPC调用的client、server span的spanIdparentId都一样,需要以此来区分它们。

Dubbo 与 SOFARpc中的特殊处理

存在server -> server的情况,client spanserver spanparentIdspanId都一样,

  • parentSegmentId

    主要是找出parentSegmentId,在非SOFARpc和Dubbo情况下,遵循 server -> clientclient -> server也就是client的父spa只能是server类型的,server类型的父span只能为空或client类型。最后结果是

    • server span:parentSegmentId = traceId + parentId + client
    • client span:parentSegmentId = traceId + parentId + server

    在SOFARpc和Dubbo中,根据使用Skywalking Java Agent后两者的链路展示,按照

    • server span: parentSegmentId = traceId + spanId + client
    • client span :parentSegmentId = traceId + parentId + server
  • Peer字段和networkAddressUsedAtPeer字段

    • peer字段

      在Dubbo中peer字段可以通过remote.hostremote.port两个tag组成

      SofaRPC中在remote.ip中包含了ip和port,只使用IP

    • networkAddressUsedAtPeer

      Dubbo可以通过span中的tag信息组成地址,其中port是通过修改Dubbo插件添加的Tag

      SofaPRC中不能直接从Span中国获取到本机的ip,使用的是获取本机的第一个有效IPV4地址,但是没有端口号,所以在上面的peer字段中也只用了IP

增加的配置项

com.alipay.sofa.tracer.skywalking.enabled
com.alipay.sofa.tracer.skywalking.baseUrl 
com.alipay.sofa.tracer.skywalking.maxBufferSize

Result:

Fixes #443.

@nobodyiam
Copy link
Member

@xzchaoo would you please help to review this pr?

@chenzhao11 chenzhao11 marked this pull request as draft October 2, 2021 01:58
@nobodyiam
Copy link
Member

@glmapper would you please help to review this pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SOFATracer support report trace data to jaeger and skywalking
2 participants