如何与Serilog添加Elasticsearch服务相关

发布于 2025-01-18 19:12:09 字数 1089 浏览 5 评论 0原文

我正在使用 Elasticsearch 的 APM 监控我的应用程序。该应用程序包括多个节点,每个节点都有自己的 Elasticsearch 服务。

目前,Elasticsearch 能够将日志与应用程序内创建的事务和跨度关联起来,但它们不与创建它们的服务或节点关联。

每当我进入服务 > 日志时,都会显示此内容。

我注意到事务中的“服务名称”字段为空日志。

以下是我配置应用程序 Serilog 的方法:

    private static readonly Serilog.Core.Logger Serilogger = new LoggerConfiguration()
        .Enrich.WithProperty("ApplicationName", "myApp")
        .Enrich.FromLogContext()
        .WriteTo.Console()
        .Enrich.WithElasticApmCorrelationInfo()
        .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri($"http://{StaticAddresses.ElasticIp}:{StaticAddresses.ElasticHttpPort}"))
        {
            CustomFormatter = new EcsTextFormatter(),
            AutoRegisterTemplate = true,
            IndexFormat = "myApp",
            ModifyConnectionSettings = x => x.BasicAuthentication(ApmConfiguration.ElasticUser, ApmConfiguration.ElasticPswd)
        })
        .CreateLogger();

有什么方法可以在此处添加包含服务名称的字段吗?我错过了什么吗?

I am monitoring my application using Elasticsearch's APM. This application includes several nodes, each with their own Elasticsearch service.

For now, Elasticsearch is able to correlate logs with transactions and spans created inside our application, but they do not correlate with the service or node that created them.

Whenever I go to Service > Logs, this shows up.

I noticed that the field "Service Name" is empty in the transaction logs.

Here's how I'm configuring my application's Serilog:

    private static readonly Serilog.Core.Logger Serilogger = new LoggerConfiguration()
        .Enrich.WithProperty("ApplicationName", "myApp")
        .Enrich.FromLogContext()
        .WriteTo.Console()
        .Enrich.WithElasticApmCorrelationInfo()
        .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(
quot;http://{StaticAddresses.ElasticIp}:{StaticAddresses.ElasticHttpPort}"))
        {
            CustomFormatter = new EcsTextFormatter(),
            AutoRegisterTemplate = true,
            IndexFormat = "myApp",
            ModifyConnectionSettings = x => x.BasicAuthentication(ApmConfiguration.ElasticUser, ApmConfiguration.ElasticPswd)
        })
        .CreateLogger();

Is there any way I can add a field including the Service Name here? Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-25 19:12:09

我发现问题是什么。 ecstextFormatter()不包括Service.name,Container.ID或Host.name。您需要手动添加它。

https:> https: //discuss.elastic.co/t/logs-do-not-appear-in-apm--loge-correlation-info-ispresent/289720

I've found what the problem is. The EcsTextFormatter() does not automatically include the service.name, container.id or host.name of your application. You need to add it manually.

https://discuss.elastic.co/t/logs-do-not-appear-in-apm-although-correlation-info-is-present/289720

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文