skywalking5.0.0追蹤dubbo調(diào)用鏈常用配置

一、 安裝es-5.x

二、 安裝配置skywalking

  1. 在apache-skywalking-apm-incubating\config\application.yml文件配置接收器信息(es、grpc、agent上報(bào)等)
    naming:
      jetty:
        #OS real network IP(binding required), for agent to find collector cluster
        host: 0.0.0.0
        port: 10800
        contextPath: /
    
        ...
    
    storage:
      elasticsearch:
        clusterName: test                # es 集群名稱
        clusterTransportSniffer: true
        clusterNodes: 192.168.10.103:9300   # 注意是9300 es集群通信端口
        indexShardsNumber: 2
        indexReplicasNumber: 0
        highPerformanceMode: true
        # Batch process setting, refer to https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-docs-bulk-processor.html
        bulkActions: 2000 # Execute the bulk every 2000 requests
        bulkSize: 20 # flush the bulk every 20mb
        flushInterval: 10 # flush the bulk every 10 seconds whatever the number of requests
        concurrentRequests: 2 # the number of concurrent requests
        # Set a timeout on metric data. After the timeout has expired, the metric data will automatically be deleted.
        traceDataTTL: 90 # Unit is minute
        minuteMetricDataTTL: 90 # Unit is minute
        hourMetricDataTTL: 36 # Unit is hour
        dayMetricDataTTL: 45 # Unit is day
        monthMetricDataTTL: 18 # Unit is month
    
  2. 在apache-skywalking-apm-incubating\webapp\webapp.yml文件中配置sykwalking-web信息
     server:
       port: 8080
     
     collector:
       path: /graphql
       ribbon:
         ReadTimeout: 10000
         listOfServers: 127.0.0.1:10800  # 與application.yml文件中 naming一致
     
     security:
       user:
         admin:
           password: admin
    
  3. 執(zhí)行.\skywalking\apache-skywalking-apm-incubating\bin\startup.sh啟動(dòng),查看監(jiān)聽接口10800、8080等

三、 目標(biāo)項(xiàng)目配置使用

  1. 自動(dòng)探針配置
     java -jar -javaagent:$AGENT_PATH/skywalking-agent.jar -Dskywalking.agent.application_code=user_service  user_service.jar
    
    • 啟動(dòng)項(xiàng)目時(shí)配置 javaagent啟動(dòng),比如springboot項(xiàng)目打包為user_service.jar,
    • $AGENT_PATH是skywalking-agent的絕對(duì)路徑
    • application_code是動(dòng)態(tài)為服務(wù)配置的名稱,也可以在config文件夾下的agent.config文件中配置
  1. 手動(dòng)探針使用

    • 添加skywalking依賴
        <dependency>
            <groupId>org.apache.skywalking</groupId>
            <artifactId>apm-toolkit-trace</artifactId>
            <version>5.0.0-GA</version>
        </dependency>
        <dependency>
            <groupId>org.apache.skywalking</groupId>
            <artifactId>apm-toolkit-opentracing</artifactId>
            <version>5.0.0-GA</version>
        </dependency>
      
    • 通過 TraceContext.traceId() API,在應(yīng)用程序的任何地方獲取traceId.
    • 對(duì)任何需要追蹤的方法,使用 @Trace 標(biāo)注,則此方法會(huì)被加入到追蹤鏈中。
    • 在被追蹤的方法中自定義 tag.
      ActiveSpan.tag("my_tag", "my_value");
      

四、 日志組件集成(以log4j為例)

  1. 添加skywalking日志依賴
    <dependency>
        <groupId>org.apache.skywalking</groupId>
        <artifactId>apm-toolkit-log4j-1.x</artifactId>
        <version>5.0.0-GA</version>
    </dependency>
    
  2. 修改日志配置文件
    • 配置layout

      log4j.appender.stdout.layout===org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout==

    • 在layout.ConversionPattern中設(shè)置 %T來展示traceid

      log4j.appender.stdout.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} ==[%T]== %C{1}:%M - %m%n

    • 當(dāng)你使用-javaagent參數(shù)激活sky-walking的探針, 如果當(dāng)前上下文中存在traceid,log4j將在輸出traceId。如果探針沒有被激活,將輸出TID: N/A.

五、 查看效果

瀏覽器訪問 127.0.0.1:10800

注意

  • dubbo使用hessian協(xié)議鏈路會(huì)斷,skywalking暫不支持hessian協(xié)議,
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容