Dev Mentor - Distributed tracing

OpenTrace take a tracer instance (e.g. Jaeger) to post the metrics via UDP to the remote Jaeger instance for display

OpenTrace then can be acquired in DI manner and get the hierrchical span id everywhere you want to leverage.

In this example

First processor - Product Service will acquire OpenTrace and get the span ids which seperated in semi colon 

"fa9af85bcbcc5f09:ceb22ff39dc75f9f:fa9af85bcbcc5f09:1"

then this will be pass to rabbit mq message as property value of message.

Second Processor - Order Sevice will acquire the property via JaegerMiddleWare and resolve it to get the span id hierarchy then use it to trace whatever the operation under the same parent span id

 

 

Configuration Phase : Freqence of sending these tracing data can be configured using sampler

 

using Jaeger;
using Jaeger.Reporters;
using Jaeger.Samplers;
using Jaeger.Senders;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenTracing;
using OpenTracing.Util;
using RawRabbit.Instantiation;namespace Common.Jaeger
{public static class Extensions{private static bool _initialized;public static IServiceCollection AddJaeger(this IServiceCollection services){if (_initialized){return services;}_initialized = true;var options = GetJaegerOptions(services);if (!options.Enabled){var defaultTracer = DefaultTracer.Create();services.AddSingleton(defaultTracer);return services;}services.AddSingleton<ITracer>(sp =>{var loggerFactory = sp.GetRequiredService<ILoggerFactory>();var reporter = new RemoteReporter.Builder().WithSender(new UdpSender(options.UdpHost, options.UdpPort, options.MaxPacketSize)).WithLoggerFactory(loggerFactory).Build();var sampler = GetSampler(options);var tracer = new Tracer.Builder(options.ServiceName).WithReporter(reporter).WithSampler(sampler).Build();GlobalTracer.Register(tracer);return tracer;});return services;}public static IClientBuilder UseJaeger(this IClientBuilder builder, ITracer tracer){builder.Register(pipe => pipe.Use<JaegerStagedMiddleware>(tracer));return builder;}private static JaegerOptions GetJaegerOptions(IServiceCollection services){using (var serviceProvider = services.BuildServiceProvider()){var configuration = serviceProvider.GetService<IConfiguration>();services.Configure<JaegerOptions>(configuration.GetSection("jaeger"));return configuration.GetOptions<JaegerOptions>("jaeger");}}private static ISampler GetSampler(JaegerOptions options){switch (options.Sampler){case "const": return new ConstSampler(true);case "rate": return new RateLimitingSampler(options.MaxTracesPerSecond);case "probabilistic": return new ProbabilisticSampler(options.SamplingRate);default: return new ConstSampler(true);}}}
}
Complete code for extension

For first processor - Product Service at controller level embed the span id to the context and pass over the RabbitMQ message

 For Second Processor, Order Sevice will acquire the property via JaegerMiddleWare and resolve it to get the span id hierarchy then use it to trace whatever the operation under the same parent span id

 

using Autofac;
using Common.Messages;
using Common.RabbitMQ;
using Jaeger;
using OpenTracing;
using OpenTracing.Tag;
using RawRabbit.Pipe;
using RawRabbit.Pipe.Middleware;
using System;
using System.Threading;
using System.Threading.Tasks;namespace Common.Jaeger
{public class JaegerStagedMiddleware : StagedMiddleware{private readonly ITracer _tracer;public JaegerStagedMiddleware(ITracer tracer)=> _tracer = tracer;public override string StageMarker => RawRabbit.Pipe.StageMarker.MessageDeserialized;public override Task InvokeAsync(IPipeContext context, CancellationToken token = new CancellationToken()){var correlationContext = (ICorrelationContext)context.GetMessageContext();var messageType = context.GetMessageType();using (var scope = BuildScope(messageType, correlationContext.SpanContext)){var span = scope.Span;span.Log($"Processing {messageType.Name}");try{return Next.InvokeAsync(context, token);}catch (Exception ex){span.SetTag(Tags.Error, true);span.Log(ex.Message);}}return Next.Next.InvokeAsync(context, token);}private IScope BuildScope(Type messageType, string serializedSpanContext){var spanBuilder = _tracer.BuildSpan($"processing-{messageType.Name}").WithTag("message-type", $@"{(messageType.IsAssignableTo<ICommand>() ? "command" : "event")}");if (string.IsNullOrEmpty(serializedSpanContext)){return spanBuilder.StartActive(true);}var spanContext = SpanContext.ContextFromString(serializedSpanContext);return spanBuilder.AddReference(References.FollowsFrom, spanContext).StartActive(true);}}
}
JaegerMiddleWare

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1174474.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于深度学习的火焰烟雾检测系统(YOLOv10+YOLO数据集+UI界面+Python项目+模型)

一、项目介绍 项目背景 火焰与烟雾的检测在很多领域中都至关重要&#xff0c;特别是在火灾监控、工业安全、环境保护等领域。准确、实时地识别火焰和烟雾的存在&#xff0c;不仅可以有效减少灾害发生的损失&#xff0c;还能够为相关部门提供及时的预警信息。因此&#xff0c;…

VIRTUALIZATION - Dev Mentor - Kubernates (Continue)

VIRTUALIZATION - Dev Mentor - Kubernates (Continue) kubectl apply -f /home/Asdf1234/pod.ymlkubectl get podskubectl port-forward nanoservice-pod 5000:5000kubectl describe pod nanoservice-pod kubectl de…

VIRTUALIZATION - Dev Mentor - Docker

VIRTUALIZATION - Dev Mentor - Docker Remove all inactive dockers : docker container prune -f Copy files in inactive docker to host server: docker container cp 5f9c2f1893c4:/app/migrator/ ./ VS.NET doc…

无需专业技能!AI小程序一句话高效改图出片

拍照总遇尴尬&#xff1f;自拍眼镜泛绿光、风景照路人乱入&#xff0c;修图又难又费钱&#xff1f;别慌&#xff01;安利小程序AI生图&#xff0c;小白也能一键精准修图&#xff0c;轻松拯救废片。实战演示&#xff1a;两大拍照痛点&#xff0c;一键解决▶场景一&#xff1a;人…

【性能测试】9_JMeter _JMeter录制脚本(了解)

文章目录一、录制脚本原理二、应用场景三、操作步骤四、jmeter问题不能联网五、过滤规则和Cookie管理器一、录制脚本原理 Jmeter在客户端和服务器之间做代理。收到所有的请求和响应数据后&#xff0c;Jmeter再进行逆向解析的动作&#xff0c;将数据报文转化为脚本。 二、应用…

【性能测试】8_JMeter _JMeter跨线程组关联

文章目录一、跨线程组关联1.1 说明1.2 实现原理二、Jmeter属性的配置方法三、场景四、操作方法一、跨线程组关联 当有依赖关系的两个请求&#xff08;一个请求的入参是另一个请求返回的数据&#xff09; &#xff0c; 放入到不同的线程组中时&#xff0c; 就不能使用提取器保存…

高低温交变湿热试验箱品牌都有哪些值得看?

在环境可靠性试验设备领域&#xff0c;高低温交变湿热试验箱是评估产品耐候性与稳定性的关键设备。面对市场上众多的品牌&#xff0c;如何选择一款性能卓越、质量可靠的设备成为许多企业的关注焦点。小编将为您梳理几个值得重点考察的实力品牌&#xff0c;助您做出明智决策。一…

2026中国GEO服务商权威测评:聚焦区域深耕,领跑AI搜索商业新纪元 - 野榜数据排行

报告摘要 2026年,生成式AI全面重构流量逻辑,传统SEO效能持续衰减,生成式引擎优化(GEO)已成为企业抢占AI生态认知卡位的核心战略。本报告基于技术创新、商业转化、服务交付、本土合规四大核心维度,对国内主流GEO服…

【AI应用开发工程师】-你有没有被 AI 的“幻觉输出”气到过?

&#x1f4da; 目录 #mermaid-svg-7hnpYjYDu1AjdrLw{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-7hnpYj…

实用指南:C++11(二)

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

强烈安利10个AI论文工具,专科生轻松搞定论文写作!

强烈安利10个AI论文工具&#xff0c;专科生轻松搞定论文写作&#xff01; AI工具如何让论文写作不再难 对于专科生来说&#xff0c;论文写作一直是一个令人头疼的难题。从选题到开题&#xff0c;从撰写到降重&#xff0c;每一个环节都可能成为阻碍。而如今&#xff0c;随着AI技…

GNSS位移监测在单北斗变形监测一体机中的应用与发展分析

GNSS位移监测技术在单北斗变形监测一体机中的应用日益广泛&#xff0c;涵盖了从基础设施维护到自然灾害预警的多个领域。单北斗系统通过高精度定位&#xff0c;实时获取重要的位移数据&#xff0c;帮助工程师及时判断结构安全情况。特别是在桥梁和地质灾害监测方面&#xff0c;…

AGC060C Large Heap 题解 / 计数 dp

题目传送门:AGC060C Large Heap。 首先这个东西完全就是一个满二叉树的堆,相当于权值顺序要为一个拓扑,且 \(U\) 在 \(V\) 前面。 而 \(U,V\) 在 \(A+1\) 与 \(B+1\) 层的最左和左右端点。 那么 \(U,V\) 分别是两条…

2026年AI艺术码二维码生成器推荐榜单:探寻最佳选择

在2026年&#xff0c;AI艺术码二维码生成器逐渐成为创意表达的重要工具。这些生成器帮助用户将各类内容转化为二维码&#xff0c;使艺术作品更加吸引人。以码上游、QRCodeMonkey和QR Code Generator PRO为代表&#xff0c;它们各有特色&#xff0c;能满足不同用户的需求。 个…

2026年1月二手宽体车公司评测报告:二手宽体车公司选择指南! - 品牌鉴赏师

一、开篇引言 近年来,我国二手宽体车市场尤其是矿用宽体车领域发展态势强劲,据太平洋汽车百科2025年行业分析报告显示,受益于矿山智能化建设推进及工程运输领域需求释放,二手宽体车市场规模年均增速保持在12%以上,…

2026年1月二手宽体车公司评测报告:二手宽体车公司选择指南! - 品牌鉴赏师

一、开篇引言 近年来,我国二手宽体车市场尤其是矿用宽体车领域发展态势强劲,据太平洋汽车百科2025年行业分析报告显示,受益于矿山智能化建设推进及工程运输领域需求释放,二手宽体车市场规模年均增速保持在12%以上,…

如何应对启动错误:一步步解决错误代码0xc0000001分享

当您尝试开启电脑时&#xff0c;面对的错误代码0xc0000001可能让您感到困惑和无助。这个错误通常涉及到系统文件的问题或硬件故障&#xff0c;但幸运的是&#xff0c;有多种方法可以尝试解决这个问题。本文将提供一个详尽的步骤指南&#xff0c;帮助您从错误中恢复出来&#xf…

CVE-2025-68645 Zimbra Collaboration Suite 本地文件包含漏洞分析

&#x1f525; CVE-2025-68645: Zimbra Collaboration Suite — 本地文件包含 (LFI) 漏洞分析 &#x1f4d6; 项目概述 本项目详细解析了编号为 CVE-2025-68645 的安全漏洞。该漏洞存在于 Zimbra Collaboration Suite (ZCS) 中&#xff0c;是一个无需身份验证即可远程利用的本地…

CVE-2025-68645 Zimbra Collaboration Suite 本地文件包含漏洞分析

&#x1f525; CVE-2025-68645: Zimbra Collaboration Suite — 本地文件包含 (LFI) 漏洞分析 &#x1f4d6; 项目概述 本项目详细解析了编号为 CVE-2025-68645 的安全漏洞。该漏洞存在于 Zimbra Collaboration Suite (ZCS) 中&#xff0c;是一个无需身份验证即可远程利用的本地…