Azure 日志流日志丢失 - Java

发布于 2025-01-09 01:22:22 字数 322 浏览 1 评论 0原文

在我的 Azure 函数中,我使用 SLF4J 进行日志记录(由 logback 支持)。 Application Insights 支持自动检测日志记录。自动收集日志的地方。详细信息此处。

但我发现随机丢失了很多日志。它们在运行期间存在,但在 LogStream 中查看时在其他时候会丢失。可能出了什么问题?

In my Azure Function, I am using SLF4J for logging (backed by logback). Application Insights supports auto-instrumented logging. Where the logs are automatically collected. Details here.

But I find that randomly a lot of logs get missed. They are present during a run and missing some other times when viewed in LogStream. What could be going wrong?

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

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

发布评论

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

评论(1

轻拂→两袖风尘 2025-01-16 01:22:22

这个答案并没有完全回答问题。我仍然发现这个问题存在。并且并不真正知道 LogStream 中丢失日志的原因。这令人沮丧。


您可能需要进一步注意的一件事是: 采样。从文档粘贴:

如果您需要降低成本,抽样很有帮助。进行抽样
作为操作 ID(也称为跟踪 ID)上的函数,以便
相同的操作 ID 将始终导致相同的采样
决定。这确保您不会获得分布式的部分
交易被采样,而其其他部分被采样。

例如,如果您将采样率设置为 10%,您将只能看到 10% 的数据
交易
,但这 10% 中的每一个都将拥有完整的端到端
交易详情。

为了避免由于采样而过滤,请添加功能配置:

APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE: 100

这不会遗漏任何内容。
有关更多详细信息,请访问:https: //learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling


就我而言,我想包含所有日志。但对其他指标执行采样(例如依赖关系,包括对 REST API、数据库或文件系统的调用)。

另一种方式也是如此。将 host.json 编辑为:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "excludedTypes": "Exception;Trace;Request"
      }
    }
  }
}

日志语句本身位于 Trace 下。所以我们排除了它的采样。对其余部分进行采样(依赖项、事件、PageView、请求)

要验证上述配置是否按预期工作,请运行以下 kusto 查询:对

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > ago(1d)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType

函数进行负载测试。在输出中,您应该在 Exception;Trace;Request 上看到 100

在此处输入图像描述

要查看全套配置:https://learn.microsoft。 com/en-us/azure/azure-functions/functions-host-json#sample-hostjson-file

有选择地覆盖(不同日志的不同行为):https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling-overrides-preview" microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling-overrides-preview


This answer does not fully answer the question. I still find the issue present. And don't really know the cause for missing logs in LogStream. And it is frustrating.


One thing that you may want to further take care is: Sampling. Pasting from the docs:

Sampling is helpful if you need to reduce cost. Sampling is performed
as a function on the operation ID (also known as trace ID), so that
the same operation ID will always result in the same sampling
decision. This ensures that you won't get parts of a distributed
transaction sampled in while other parts of it are sampled out.

For example, if you set sampling to 10%, you will only see 10% of your
transactions
, but each one of those 10% will have full end-to-end
transaction details.

To avoid filtering due to sampling, add the function configuration:

APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE: 100

This does not omit anything.
For more details, visit: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling


In my case, I wanted to include all the logs. But perform sampling for other metrics (like dependencies which includes calls to REST API, database or a file system).

An alternative way as well. Edit your host.json as:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "excludedTypes": "Exception;Trace;Request"
      }
    }
  }
}

The log statements as such go under Trace. So we exclude sampling for it. The rest are sampled (Dependency, Event, PageView, Request)

To validate if the above config is working as expected, run the below kusto query:

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > ago(1d)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType

Load test the function. In the output, you should see 100 across the Exception;Trace;Request

enter image description here

To view full set of config: https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json#sample-hostjson-file

To selectively override (different behavior for different logs): https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-config#sampling-overrides-preview


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