当前位置: 首页 > news >正文

Jaeger UI使用、采集应用API排除特定路径

Jaeger使用

注:
Jaeger服务端版本为:jaegertracing/all-in-one-1.6.0
OpenTracing版本为:0.33.0,最后一个版本,停留在May 06, 2019。最好升级到OpenTelemetry。
Jaeger客户端版本为:jaeger-client-1.3.2

Tags

Tag是一个非常常见的概念,时序数据库如InfluxDB,Prometheus里的基础概念。Jaeger也有这个概念,如下Jaeger UI里有一个Tags,主要用于筛选过滤部分可能会造成干扰的数据。
在这里插入图片描述
点击某个Trace进去,会发现如下信息:
在这里插入图片描述
因此,可输入如下内容实现过滤搜索:

  • 精确匹配:hostname=DESKTOP-L20EH42
  • 排除匹配:hostname=~DESKTOP-L20EH42

其他可用的Tag(常用的在前面):

  • hostname
  • ip
  • http.status_code
  • http.method
  • http.url
  • jaeger.version
  • component
  • span.kind
  • sampler.type
  • sampler.param

排除特定路径

在这里插入图片描述
如上图,Operation里列出该应用下的所有接口。

在k8s集群里,pod健康检查需要应用暴露一个/health接口。这个/health接口是写在框架Jar里的,而不是每个应用都写一个HealthController(虽然可以这样做,我在上家公司也这样干过)。

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;@Slf4j
@Component
@RequiredArgsConstructor
public class HealthyConfiguration implements ApplicationRunner {private final RequestMappingHandlerMapping requestMappingHandlerMapping;@Overridepublic void run(ApplicationArguments args) {RequestMappingInfo healthRequestMappingInfo = RequestMappingInfo.paths("/health").methods(RequestMethod.GET).produces(MediaType.APPLICATION_JSON_VALUE).options(requestMappingHandlerMapping.getBuilderConfiguration()).build();Method healthMethod = ReflectionUtils.findMethod(getClass(), "health", HttpServletRequest.class, HttpServletResponse.class);requestMappingHandlerMapping.registerMapping(healthRequestMappingInfo, this, healthMethod);}@ResponseBodypublic R<String> health(HttpServletRequest request, HttpServletResponse response) {return R.success("ok", "ok");}
}

需求:类似于这个GitHub Issue,Jaeger能不能不收集应用下的特定接口,即,排除特定路径。

方案

经过各种尝试,以及Google,DeepSeek,ChatGPT,最后还是GitHub Copilot给出的答复能解决问题。

新增一个Filter类,当然这个Filter类也是需要放在框架Jar里,然后所有应用都需要去引用它:

import com.johnny.security.util.CommonUtil;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import org.springframework.context.annotation.Configuration;import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;/*** @author johnny*/
@Configuration
public class TracingInterceptor implements Filter {private final Tracer tracer;public TracingInterceptor() {this.tracer = GlobalTracer.get();}@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse response, FilterChain chain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) servletRequest;String path = CommonUtil.getRequestPath(request);// 排除/health路径if ("/health".equals(path)) {// 停止当前请求的Tracingtracer.activeSpan().finish();chain.doFilter(servletRequest, response);return;}chain.doFilter(servletRequest, response);}
}

CommonUtil工具类如下:

public class CommonUtil {/*** 获取请求路径*/public static @NotNull String getRequestPath(HttpServletRequest request) {String path = "";String servletPath = request.getServletPath();if (StrUtil.isNotBlank(servletPath)) {path += servletPath;}String contextPath = request.getContextPath();if (StrUtil.isNotBlank(contextPath)) {path += contextPath;}String pathInfo = request.getPathInfo();if (StrUtil.isNotBlank(pathInfo)) {path += pathInfo;}return path;}
}

参考

  • GitHub Copilot
http://www.lryc.cn/news/519282.html

相关文章:

  • 设计一个利用事务特性可以阻塞线程的排他锁,并且通过注解和 AOP 来实现
  • 【2024年华为OD机试】 (A卷,100分)- 对称美学(Java JS PythonC/C++)
  • 【教程】数据可视化处理之2024年各省GDP排名预测!
  • Java 将RTF文档转换为Word、PDF、HTML、图片
  • 深度学习的原理和应用
  • CAPL语法基础
  • 安卓studio生成apk步骤
  • Azure主机windows2008就地升级十步
  • 解锁 C# 与 LiteDB 嵌入式 NoSQL 数据库
  • 7 分布式定时任务调度框架
  • 七星棋类游戏源码:两百玩法开源修复
  • 未来世界:科技引领的奇幻篇章
  • [python3]Uvicorn库
  • istio-proxy oom问题排查步骤
  • Flutter:使用FVM安装多个Flutter SDK 版本和使用教程
  • 关于物联网的基础知识(二)——物联网体系结构分层
  • [程序设计]—代理模式
  • 26、【OS】【Nuttx】用cmake构建工程
  • C#中序列化的选择:JSON、XML、二进制与Protobuf详解
  • 单片机实现模式转换
  • Shader -> SweepGradient扫描渐变着色器详解
  • 鼠标过滤驱动
  • 【深度学习】数据操作入门
  • WIFIAP项目 5G RX二次谐波超标案例分析
  • HarmonyOS(ArkUI框架介绍)
  • 在 Ubuntu 下通过 Docker 部署 MySQL 服务器
  • MCU 和 PSK
  • Linux:进程概念(二.查看进程、父进程与子进程、进程状态详解)
  • 苍穹外卖07——来单提醒和客户催单(涉及SpringTask、WebSocket协议、苍穹外卖跳过微信支付同时保证可以收到订单功能)
  • C语言二级考试