微服务全链路跟踪:grpc集成zipkin
微服务全链路跟踪:jaeger集成istio,并兼容uber-trace-id与b3
本章节内容是基于springboot2集成net.devh.grpc的拓展
本章介绍grpc集成zipkin
zipkin部署
这里就不列举zipkin代码或者容器部署了,网上很多
grpc-client集成
pom.xml依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-bom</artifactId>
<version>4.19.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--核心grpc-spring-boot依赖-->
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>${net-devh-grpc.version}</version>
</dependency>
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>${net-devh-grpc.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>${grpc.version}</version>
</dependency>
<!--zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- Spring Boot 配置处理 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-instrumentation-grpc</artifactId>
</dependency>
</dependencies>
自动装配
import brave.Tracing;
import brave.grpc.GrpcTracing;
import io.grpc.ClientInterceptor;
import net.devh.boot.grpc.client.interceptor.GlobalClientInterceptorConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
/**
* @Auther: lipeng
* @Date: 2019/1/3 19:34
* @Description:
*/
@Order(Ordered.LOWEST_PRECEDENCE)
@Configuration
public class GrpcSleuthConfig {
private static final Logger logger = LoggerFactory.getLogger(GrpcSleuthConfig.class);
@Bean
public GrpcTracing grpcTracing(Tracing tracing) {
return GrpcTracing.create(tracing);
}
//We also create a client-side interceptor and put that in the context, this interceptor can then be injected into gRPC clients and
//then applied to the managed channel.
@Bean
ClientInterceptor grpcClientSleuthInterceptor(GrpcTracing grpcTracing) {
return grpcTracing.newClientInterceptor();
}
// Use this for debugging (or if there is no Zipkin server running on port 9411)
@Bean
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
public Reporter<Span> spanReporter() {
return new Reporter<Span>() {
@Override
public void report(Span span) {
logger.info("{}",span);
}
};
}
@Bean
public GlobalClientInterceptorConfigurer globalInterceptorConfigurerAdapter(ClientInterceptor grpcClientSleuthInterceptor) {
return registry -> registry.addClientInterceptors(grpcClientSleuthInterceptor);
}
}
application.xml配置
spring:
zipkin:
enable: true
base-url: http://zipkin.com
sleuth:
web:
client:
enabled: true
sampler:
probability: 1.0 #zipkin采集率 0.1表示 10%采集率
grpc-server
pom.xml依赖
<dependencies>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>${grpc.version}</version>
</dependency>
<!--zipkin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- Spring Boot 配置处理 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-instrumentation-grpc</artifactId>
</dependency>
</dependencies>
自动装配
import brave.Tracing;
import brave.grpc.GrpcTracing;
import io.grpc.ClientInterceptor;
import io.grpc.ServerInterceptor;
import net.devh.boot.grpc.server.interceptor.GlobalServerInterceptorConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
/**
* @Auther: lipeng
* @Date: 2019/1/3 19:34
* @Description:
*/
@Configuration
public class GrpcSleuthConfig {
private static final Logger logger = LoggerFactory.getLogger(GrpcSleuthConfig.class);
@Bean
public GrpcTracing grpcTracing(Tracing tracing) {
return GrpcTracing.create(tracing);
}
//grpc-spring-boot-starter provides @GrpcGlobalInterceptor to allow server-side interceptors to be registered with all
//server stubs, we are just taking advantage of that to install the server-side gRPC tracer.
@Bean
ServerInterceptor grpcServerSleuthInterceptor(GrpcTracing grpcTracing) {
return grpcTracing.newServerInterceptor();
}
//We also create a client-side interceptor and put that in the context, this interceptor can then be injected into gRPC clients and
//then applied to the managed channel.
@Bean
ClientInterceptor grpcClientSleuthInterceptor(GrpcTracing grpcTracing) {
return grpcTracing.newClientInterceptor();
}
// Use this for debugging (or if there is no Zipkin server running on port 9411)
@Bean
@ConditionalOnProperty(value = "sample.zipkin.enabled", havingValue = "false")
public Reporter<Span> spanReporter() {
return new Reporter<Span>() {
@Override
public void report(Span span) {
logger.info("{}",span);
}
};
}
@Bean
public GlobalServerInterceptorConfigurer globalInterceptorConfigurerAdapter(ServerInterceptor grpcServerSleuthInterceptor) {
return registry -> registry.addServerInterceptors(grpcServerSleuthInterceptor);
}
}
application.xml配置
spring:
zipkin:
enable: true
base-url: http://zipkin.com
sleuth:
web:
client:
enabled: true
sampler:
probability: 1.0 #zipkin采集率 0.1表示 10%采集率
微服务全链路跟踪:grpc集成zipkin的更多相关文章
- Go微服务全链路跟踪详解
在微服务架构中,调用链是漫长而复杂的,要了解其中的每个环节及其性能,你需要全链路跟踪. 它的原理很简单,你可以在每个请求开始时生成一个唯一的ID,并将其传递到整个调用链. 该ID称为Correlati ...
- Spring Cloud 微服务分布式链路跟踪 Sleuth 与 Zipkin
Zipkin 是一个开放源代码分布式的跟踪系统,由 Twitter 公司开源,它致力于收集服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集.存储.查找和展现.它的理论模型来自于Google ...
- 微服务, 架构, 服务治理, 链路跟踪, 服务发现, 流量控制, Service Mesh
微服务, 架构, 服务治理, 链路跟踪, 服务发现, 流量控制, Service Mesh 微服务架构 本文将介绍微服务架构和相关的组件,介绍他们是什么以及为什么要使用微服务架构和这些组件.本文侧 ...
- 微服务之分布式跟踪系统(springboot+zipkin+mysql)
通过上一节<微服务之分布式跟踪系统(springboot+zipkin)>我们简单熟悉了zipkin的使用,但是收集的数据都保存在内存中重启后数据丢失,不过zipkin的Storage除了 ...
- SpringCloud初体验:六、利用 Sleuth 和 Zipkin 给微服务加上链路监控追踪查看功能
首先:装上 Zipkin 服务,收集调用链跟踪数据,体验时装在了本机docker上, 方便快捷 docker run -d -p : openzipkin/zipkin 安装后访问地址也是 9411端 ...
- Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin【Finchley 版】
Spring Cloud(十二):分布式链路跟踪 Sleuth 与 Zipkin[Finchley 版] 发表于 2018-04-24 | 随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请 ...
- Springboot 2.0.x 引入链路跟踪Sleuth及Zipkin
Zipkin是一种分布式跟踪系统,它有助于收集解决微服务架构中得延迟问题所需的时序数据,它管理这些数据的收集和查找. 1. 架构概述 跟踪器存在于您的应用程序中,并记录有关发生的操作的时间和元数据.他 ...
- SpringBoot 整合 Elastic Stack 最新版本(7.14.1)分布式日志解决方案,开源微服务全栈项目【有来商城】的日志落地实践
一. 前言 日志对于一个程序的重要程度不用过多的言语修饰,本篇将以实战的方式讲述开源微服务全栈项目 有来商城 是如何整合当下主流日志解决方案 ELK +Filebeat . 话不多说,先看实现的效果图 ...
- SpringBoot之微服务日志链路追踪
SpringBoot之微服务日志链路追踪 简介 在微服务里,业务出现问题或者程序出的任何问题,都少不了查看日志,一般我们使用 ELK 相关的日志收集工具,服务多的情况下,业务问题也是有些难以排查,只能 ...
- (16)go-micro微服务jaeger链路追踪
目录 一 jaeger链路追踪介绍 什么是链路追踪: 链路追踪主要功能: 二 jaeger链路追踪作用 三 jaeger链路追踪主要特性 四 jaeger链路追踪原理图 1.链路调用原理 2. 一次调 ...
随机推荐
- python实现推送消息到微信公众号
使用到库: Requests 实现方式: 微信已开放了对应的接口,直接通过python的requests库,发起请求,实现推送消息到公众号 微信公众号准备: 1.没有注册微信公众号,可以使用微信提供的 ...
- 认真学习CSS3-问题收集-102号-关于定位
css中有关于定位的一个属性position. 在w3cschool中,position的介绍如下: 值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定 ...
- HDD成都站:HMS Core 6.0带来新可能,多元服务驱动产品价值提升
9月10日,由华为开发者联盟主办的HDD(Huawei Developer Day)于成都举行.活动中,华为HMS Core各领域专家重点解读了HMS Core 6.0为开发者带来的多项全新能力,及生 ...
- git 有用配置汇总
背景 git config的不同级别,每一个级别覆盖上一级别的配置,所以.git/config的配置变量会覆盖/etc/gitconfig中的配置变量 git config --system #为整个 ...
- 在WPF中使用WriteableBitmap对接工业相机及常用操作
写作背景 写这篇文章主要是因为工业相机(海康.大恒等)提供的.NET开发文档和示例程序都是用WinForm项目来说明举例的,而在WPF项目中对图像的使用和处理与在WinForm项目中有很大不同.在Wi ...
- map端join和reduce端join的区别
MapReduce Join MapJoin和ReduceJoin区别及优化 maptask处理后写到本地,如果再到reduce,又涉及到网络的拷贝. map端join最大优势,可以提前过滤不需要的数 ...
- python3 requests 请求https报错: urllib3.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:992)
正文 代码示例: #-*- coding:utf-8 -*- import requests url = "https://tst.com" res = requests.get( ...
- mysql 授权远程连接
解决方案 改表法 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 &quo ...
- git 更新某个目录或文件
不多说直接贴代码 更新文件 $ git fetch remote: Counting objects: 8, done. remote: Compressing objects: 100% (3/3) ...
- CRC 循环冗余效验
CRC循环冗余效验 利用多项式 x6 + x4 + x3,实际为使用模2除法来做的加密 常用crc多项式有 名称 生成多项式 数值式 简记式 标准引用 CRC-4 x4+x+1 0x1'3 0x3 I ...