Steeltoe里的分布式追踪功能与Spring Cloud Sleuth一样,支持在日志中记录追踪数据,或者上传到远端的服务,比如Zipkin。

Logging

在Steeltoe中使用日志时需要引入其特有的日志包Steeltoe.Extensions.Logging.DynamicLogger

之后还需在应用程序启动时加入日志提供器。

WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().ConfigureLogging((builderContext, loggingBuilder) =>
{
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection("Logging")); // Add Steeltoe Dynamic Logging provider
loggingBuilder.AddDynamicConsole();
});

接下来,引入追踪包Steeltoe.Management.TracingCore

然后在Startup类中加入追踪服务。

public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedTracing(Configuration); services.AddMvc();
}

最后在Action方法里添加日志锚点。

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly ILogger _logger;
public ValuesController(ILogger<ValuesController> logger)
{
_logger = logger;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
_logger.LogWarning("Hello log");
return new string[] { "value1", "value2" };
}
}

并在appsettings.json文件确认如下配置:

"Logging": {
"LogLevel": {
"Default": "Warning"
}
}

这样启动程序后,可以在输出窗口内看到两条日志,这是因为Steeltoe的日志提供器是对ASP.NET Core自身日志器的进一步封装,其在原始数据基础上增加了如Spring Cloud Sleuth中一样的额外信息。

Exporting

如果想要把追踪数据发送到Zipkin服务中,还需额外引入新的包Steeltoe.Management.ExporterCore

并在Startup类中增加新的服务。

public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedTracing(Configuration);
services.AddZipkinExporter(Configuration); services.AddMvc();
} public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(); app.UseTracingExporter();
}

appsettings.json文件里加上上文中Zipkin的服务地址。

"management": {
"tracing": {
"alwaysSample": true,
"egressIgnorePattern": "/api/v2/spans|/v2/apps/.*/permissions|/eureka/.*|/oauth/.*",
"exporter": {
"zipkin": {
"endpoint": "http://localhost:10000/api/v2/spans",
"validateCertificates": false
}
}
}
}

再次启动程序,首先可以看到exportable字段的值已从false变为了true。

然后,再到Zipkin服务中查看,追踪数据确实已经传入到其中。

Steeltoe之Distributed Tracing篇的更多相关文章

  1. Sentry 监控 - Distributed Tracing 分布式跟踪

    系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...

  2. Knowing how all your components work together: distributed tracing with Zipkin

    转自: http://aredko.blogspot.com/2014/02/knowing-how-all-your-components-work.html In today's post we ...

  3. Steeltoe之Circuit Breaker篇

    在分布式系统中,服务发生异常是很正常的现象.为了处理这类"例外",可以采取不同的应对策略,断路器模式即是其中一种方法.这个模式的主要特点是其可以阻断失败的级联影响,不会因为一个服务 ...

  4. Steeltoe之Service Discovery篇

    在前文一窥Spring Cloud Eureka中,已经构建了基于Eureka的服务端与客户端,可用于实现服务注册与发现功能.而借助Steeltoe的类库,可以在.NET生态系统中使用Spring C ...

  5. Steeltoe之Config客户端篇

    Steeltoe是一款开源项目,其目标是选取源自Netflix及其它公司的工具,使它们能够运用于.NET社区.它不仅可以在.NET Core上,也可以在.NET Framework 4.X以上使用.此 ...

  6. .NET Core微服务之基于Steeltoe使用Zipkin实现分布式追踪

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 =>  Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...

  7. OneAPM大讲堂 | Metrics, Tracing 和 Logging 的关系

    [编者按]这是在 OpenTracing 和分布式追踪领域内广受欢迎的一片博客文章.在构建监控系统时,大家往往在这几个名词和方式之间纠结. 通过这篇文章,作者很好的阐述了分布式追踪.统计指标与日志之间 ...

  8. Scalable, Distributed Systems Using Akka, Spring Boot, DDD, and Java--转

    原文地址:https://dzone.com/articles/scalable-distributed-systems-using-akka-spring-boot-ddd-and-java Whe ...

  9. Build Telemetry for Distributed Services之OpenCensus:C#

    OpenCensus Easily collect telemetry like metrics and distributed traces from your services OpenCensu ...

随机推荐

  1. webstorm调试

    webstorm调试nodejs    https://www.cnblogs.com/dogharry/p/4335157.html webstorm调试js   https://www.cnblo ...

  2. sql查询重复值

    SELECT COUNT(字段name) AS con,字段name,重复字段pc FROM 表名 GROUP BY 重复字段pc HAVING con>=

  3. Bicoloring 二分图+染色

    https://vjudge.net/contest/281085?tdsourcetag=s_pcqq_aiomsg#problem/B #include<stdio.h> #inclu ...

  4. bzoj1124_枪战_基环树

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1124 https://www.luogu.org/problemnew/show/P34 ...

  5. [AGC017D]Game on Tree

    [AGC017D]Game on Tree 题目大意: 一棵\(n(n\le10^5)\)个结点的树.A和B轮流进行游戏,A先手.每次删掉一棵子树,根结点不能删.最先不能操作的人输,问最后谁赢. 思路 ...

  6. 解决Idea无法提示代码、不检查语法的方法

    今天打开Idea做项目的时候,java代码图标出现异常(不是以前的C图标),所有java文件都只有两种颜色,百度查了一下,Idea有一个叫power save mode,在file -> Pow ...

  7. Layui下拉框改变时触发事件

    layui.use(['form', 'layer'], function () { var form = layui.form(); var layer = layui.layer; form.on ...

  8. Inmon和Kimball数仓建模思想

    Inmon和Kimball是数据仓库领域伟大的开拓者,他们均多年从事数据仓库的研究,Inmon还被称为“数据仓库之父”.Inmon的<数据仓库>和Kimball的<数据仓库工具箱&g ...

  9. 实现webservice过滤器,请求日志和权限等

    过滤webservice的请求日志,做权限验证功能等. 1. namespace WebApplication1 { public class SimpleWSInvokeMonitorExtensi ...

  10. vue的风格指南(必要的)

    1.v-if与v-for不要放在同一个元素上 当 v-if 与 v-for 一起使用时,v-for 具有比 v-if 更高的优先级.永远不要把 v-if 和 v-for 同时用在同一个元素上. 一般我 ...