Dapr牵手.NET学习笔记:可观测性-分布式跟踪

Posted dotNET跨平台

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dapr牵手.NET学习笔记:可观测性-分布式跟踪相关的知识,希望对你有一定的参考价值。

分布式跟踪在dapr里是开箱即用的,不需要对应用作任何一丁点的侵入式编程。之前的开发,如果想实现分式跟踪,就得在应用中埋点,这是一个与业务无关系的动作。dpar通过sidecar可以轻松做到这点,从而让程序员更多精力投入到业务中,又让运维得到可观测性能数据,对服务运维保驾护航。从此以后,开发和运维再没有爱恨情愁,可以友好的做朋友。

接上一篇的docker-compose部署,在docker-compose.yam中只需要增加zipkin在的节点,并且每个服务的sidecar启动时指定zipkin配置即可。

version: '3.4'
services:
  #┌────────────────────────────────┐
  #│ ordersystem app + Dapr sidecar │
  #└────────────────────────────────┘
  ordersystem:
    image: ${DOCKER_REGISTRY-}ordersystem
    depends_on:
      - redis
      - placement 
      - rabbitmq         
      - zipkin       
    build:
      context: ../
      dockerfile: OrderSystem/Dockerfile
    ports:
      - "3500:3500"    
    volumes:   
      - ../OrderSystem:/OrderSystem  
    networks:
      - b2c-dapr
  ordersystem-dapr:
     image: "daprio/daprd:latest"
     command: [ "./daprd", "-app-id", "order", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]
     depends_on:
       - ordersystem
     network_mode: "service:ordersystem"
     volumes:   
      - ../components:/components 
      - ../:/home/nonroot/.dapr        
  
  #┌───────────────────────────────────┐
  #│ paymentsystem1 app + Dapr sidecar │
  #└───────────────────────────────────┘  
  paymentsystem1:
    image: ${DOCKER_REGISTRY-}paymentsystem
    depends_on:
      - redis
      - placement 
      - rabbitmq   
      - zipkin      
    build:
      context: ../
      dockerfile: PaymentSystem/Dockerfile
    ports:
      - "3601:3500"
    volumes:   
      - ../PaymentSystem:/PaymentSystem      
    networks:
      - b2c-dapr      
  paymentsystem1-dapr:
     image: "daprio/daprd:latest"
     command: [ "./daprd", "-app-id", "pay", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]
     depends_on:
       - paymentsystem1
     network_mode: "service:paymentsystem1"
     volumes:   
      - ../components:/components 
      - ../:/home/nonroot/.dapr     
      
  #┌───────────────────────────────────┐
  #│ paymentsystem2 app + Dapr sidecar │
  #└───────────────────────────────────┘   
  paymentsystem2:
    image: ${DOCKER_REGISTRY-}paymentsystem
    depends_on:
      - redis
      - placement   
      - rabbitmq   
      - zipkin        
    build:
      context: ../
      dockerfile: PaymentSystem/Dockerfile
    volumes:   
      - ../PaymentSystem:/PaymentSystem            
    ports:
      - "3602:3500"
    networks:
      - b2c-dapr      
  paymentsystem2-dapr:
     image: "daprio/daprd:latest"
     command: [ "./daprd", "-app-id", "pay", "-app-port", "80" ,"-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml"]
     depends_on:
       - paymentsystem2
     network_mode: "service:paymentsystem2"
     volumes:   
      - ../components:/components       
      - ../:/home/nonroot/.dapr     


  #┌───────────────────────────────────┐
  #│ noticesystem1 app + Dapr sidecar  │
  #└───────────────────────────────────┘  
  noticesystem1:
    image: ${DOCKER_REGISTRY-}noticesystem
    depends_on:
      - redis
      - placement  
      - rabbitmq  
      - zipkin         
    build:
      context: ../
      dockerfile: NoticeSystem/Dockerfile
    ports:
      - "3701:3500"
    volumes:   
      - ../NoticeSystem:/NoticeSystem      
    networks:
      - b2c-dapr      
  noticesystem1-dapr:
     image: "daprio/daprd:latest"
     command: [ "./daprd", "-app-id", "notice", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components","-config","/home/nonroot/.dapr/config.yaml" ]
     depends_on:
       - noticesystem1
     network_mode: "service:noticesystem1"
     volumes:   
      - ../components:/components 
      - ../:/home/nonroot/.dapr     


  #┌───────────────────────────────────┐
  #│ noticesystem2 app + Dapr sidecar  │
  #└───────────────────────────────────┘  
  noticesystem2:
    image: ${DOCKER_REGISTRY-}noticesystem
    depends_on:
      - redis
      - placement    
      - rabbitmq  
      - zipkin         
    build:
      context: ../
      dockerfile: NoticeSystem/Dockerfile
    ports:
      - "3702:3500"
    volumes:   
      - ../NoticeSystem:/NoticeSystem      
    networks:
      - b2c-dapr      
  noticesystem2-dapr:
     image: "daprio/daprd:latest"
     command: [ "./daprd", "-app-id", "notice", "-app-port", "80","-placement-host-address", "placement:50006","-components-path","/components" ,"-config","/home/nonroot/.dapr/config.yaml"]
     depends_on:
       - noticesystem2
     network_mode: "service:noticesystem2"
     volumes:   
      - ../components:/components 
      - ../:/home/nonroot/.dapr     
 
  #┌────────────────────────┐
  #│ Dapr placement service │
  #└────────────────────────┘  
  placement:
    image: "daprio/dapr"
    command: ["./placement", "-port", "50006"]
    ports:
      - "50006:50006"
    networks:
      - b2c-dapr
  #┌──────────────────────────┐
  #│ Zipkin  service          │
  #└──────────────────────────┘ 
  zipkin:
    image: "openzipkin/zipkin"
    ports:
      - "9411:9411"
    networks:
      - b2c-dapr
  #┌───────────────────┐
  #│ Redis state store │
  #└───────────────────┘  
  redis:
    image: "redis:latest"
    ports:
      - "6379:6379"
    networks:
      - b2c-dapr


  #┌──────────────────────┐
  #│ RabbitMQ             │
  #└──────────────────────┘  
  rabbitmq:
    image: "rabbitmq:management"
    ports:
      - "15672:15672"
      - "5672:5672" 
    environment:
      - RABBITMQ_DEFAULT_USER=admin
      - RABBITMQ_DEFAULT_PASS=!2021que 
    networks:
      - b2c-dapr  


networks:
    b2c-dapr:

config.yaml,指定了tracing的配置,zipkin的地址是:http://zipkin:9411/api/v2/spans

apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
  name: daprConfig
spec:
  tracing:
    samplingRate: "1"
    zipkin:
      endpointAddress: http://zipkin:9411/api/v2/spans

这是一个调用的跟踪结果(一)

这是一个调用的跟踪结果(二)

这是一个调用的跟踪结果(三)

这是一个发布订阅的跟踪结果(一)

这是一个发布订阅的跟踪结果(一)

以上是关于Dapr牵手.NET学习笔记:可观测性-分布式跟踪的主要内容,如果未能解决你的问题,请参考以下文章

Dapr牵手.NET学习笔记:状态管理之docker-compose发布

手把手教你学Dapr - 9. 可观测性

Dapr牵手.NET学习笔记:状态管理进阶

Dapr牵手.NET学习笔记:状态管理进阶

Dapr牵手.NET学习笔记:想入非非的服务调用

Dapr牵手.NET学习笔记:绑定