日志采样率

by Yan Cui

崔燕

为什么要在生产中采样调试日志 (Why you should sample debug logs in production)

It’s com­mon prac­tice to set your log lev­el to warning for pro­duc­tion due to traf­fic vol­ume. This is because you have to con­sid­er var­i­ous cost fac­tors:

通常的做法是将您的日志级别设置为警告 ,以防流量增加。 这是因为您必须考虑各种成本因素:

  • Cost of log­ging : Cloud­Watch Logs charges $0.50 per GB ingest­ed. In my expe­ri­ence, this is often much high­er than the Lamb­da invo­ca­tion costs

    记录的费用 :CloudWatch的日志费$ 0.50每GB摄入。 以我的经验,这通常比Lambda调用成本高得多

  • Cost of stor­age : Cloud­Watch Logs charges $0.03 per GB per month, and its default reten­tion pol­i­cy is Nev­er Expire! A com­mon prac­tice is to ship your logs to anoth­er log aggre­ga­tion ser­vice and to set the reten­tion pol­i­cy to X days. See this post for more details.

    存储成本的 :CloudWatch的日志每月收取每GB $ 0.03,它的默认保留策略永不过期 ! 一种常见的做法是将日志发送到另一个日志聚合服务,并将保留策略设置为X天。 有关更多详细信息,请参见此帖子 。

  • Cost of pro­cess­ing : if you’re pro­cess­ing the logs with Lamb­da, then you also have to fac­tor in the cost of Lamb­da invo­ca­tions.

    处理成本 :如果你和λ处理日志,那么你还必须因素LAMBDA调用的成本。

But, doing so leaves us with­out any debug logs in pro­duc­tion. When a prob­lem hap­pens in pro­duc­tion, you won’t have the debug logs to help iden­ti­fy the root cause.

但是,这样做会使我们在生产中没有任何调试日志。 当生产中出现问题时,您将没有调试日志来帮助确定根本原因。

Instead, you have to waste pre­cious time deploying a new ver­sion of your code to enable debug log­ging. Not to men­tion that you shouldn’t for­get to dis­able debug log­ging when you deploy the fix.

相反,您必须浪费宝贵的时间来部署新版本的代码以启用调试日志记录。 更不用说在部署修补程序时,您不应忘记禁用调试日志记录。

With microser­vices, you often have to do this for more than one ser­vice to get all the debug mes­sages you need.

对于微服务,您经常必须对多个服务执行此操作,才能获得所需的所有调试消息。

All these increas­e the mean time to recov­ery (MTTR) dur­ing an inci­dent. That’s not what we want.

所有这些增加了事故期间的平均恢复时间 (MTTR)。 那不是我们想要的。

It doesn’t have to be like that.

不一定要那样。

There is a hap­py mid­dle ground between hav­ing no debug logs and hav­ing all the debug logs. Instead, we should sam­ple debug logs from a small per­cent­age of invo­ca­tions.

在没有调试日志和拥有所有调试日志之间有一个中间的幸福基础。 相反,我们应该从一小部分调用中提取调试日志。

I demoed how to do this in the Log­ging chap­ter of my video course Pro­duc­tion-Ready Server­less. You need two basic things:

我演示了如何在我的视频课程的记录章节做生产准备无服务器 。 您需要两件事:

  • a log­ger that lets you to change the log­ging lev­el dynam­i­cal­ly, for example via envi­ron­ment vari­ables一个使您可以动态更改日志记录级别的记录器,例如通过环境变量
  • a mid­dle­ware engine such as mid­dy

    中间件引擎,例如Middy

With Lamb­da, I don’t need most of the fea­tures from a ful­ly-fledged log­ger such as pino. Instead, I pre­fer to use a sim­ple log­ger mod­ule like this one. It’s writ­ten in a hand­ful of lines and gives me the basics:

λ,我不需要从一个完全成熟的记录器的大部分功能,如皮诺 。 相反,我更喜欢使用像这样的简单记录器模块。 它用几行代码编写,并为我提供了基本知识:

  • struc­tured log­ging with JSON

    JSON的结构化日志记录

  • abil­i­ty to log at dif­fer­ent lev­els能够以不同级别登录
  • abil­i­ty to con­trol the log lev­el dynam­i­cal­ly via envi­ron­ment vari­ables通过环境变量动态控制日志级别的能力

Using mid­dy, I can cre­ate a mid­dle­ware to dynam­i­cal­ly update the log lev­el to debug. It does this for a con­fig­urable per­cent­age of invo­ca­tions. At the end of the invo­ca­tion, the mid­dle­ware would restore the pre­vi­ous log lev­el.

使用middy,我可以创造一个中间件动态更新的日志级别调试 。 这样做是为了实现可配置的调用百分比。 在调用结束时,中间件将恢复先前的日志级别。

You might notice that we also have some spe­cial han­dling for when the invo­ca­tion errs.

您可能会注意到,对于调用错误,我们还进行了一些特殊处理。

This is to ensure we cap­ture the error with as much con­text as pos­si­ble, includ­ing:

这是为了确保我们在尽可能多的上下文中捕获错误,包括:

  • the unique AWS Request ID唯一的AWS请求ID
  • the invo­ca­tion event, so we can replay the invo­ca­tion event local­ly and debug the prob­lem

    调用事件,因此我们可以在本地重播调用事件并调试问题

  • the error mes­sage and stack­trace错误消息和stacktrace

Hav­ing debug logs for a small per­cent­age of invo­ca­tions is great. But when you’re deal­ing with microser­vices, you need to make sure that your debug logs cov­er an entire call chain.

具有一小部分调用的调试日志非常棒。 但是,在处理微服务时,需要确保调试日志覆盖整个调用链。

That is the only way to put togeth­er a com­plete pic­ture of every­thing that hap­pened on that call chain. Oth­er­wise, you will end up with frag­ments of debug logs from many call chains but nev­er the com­plete pic­ture of one.

这是对呼叫链上发生的所有事情进行完整描述的唯一方法。 否则,您将获得来自许多调用链的调试日志的片段,但永远不会完整地看到一个。

You can do this by for­ward­ing the deci­sion to turn on debug log­ging as a cor­re­la­tion ID. The next func­tion in the chain would respect this deci­sion, and pass it on. See this post for more detail.

您可以通过转发决定打开调试日志记录作为相关ID来做到这一点。 链中的下一个职能将尊重这一决定,并将其继续下去。 有关更多详细信息 ,请参见这篇文章 。

So that’s it, anoth­er pro tip on how to build observ­abil­i­ty into your server­less appli­ca­tion. If you want to learn more about how to go all in with server­less, check out my 10-step guide here.

就是这样,这是有关如何在无服务器应用程序中建立可观察性的另一个提示。 如果您想了解更多有关如何使用无服务器的方法的更多信息,请在此处查看我的十步指南。

Until next time!

直到下一次!

翻译自: https://www.freecodecamp.org/news/why-you-should-sample-debug-logs-in-production-39d78ef3968d/

日志采样率

日志采样率_为什么要在生产中采样调试日志相关推荐

  1. vue中生产模式和调试模式_为什么在生产中进行调试是如此诱人?

    vue中生产模式和调试模式 生产调试 为什么在生产中进行调试是如此诱人? 在我的第一份工作中,我要做的任务之一是修复一个错误,该错误过去在非常复杂的生产系统中有时会发生. 那很简单! - 我想. 我将 ...

  2. 为什么在生产中进行调试是如此诱人?

    生产调试 为什么在生产中进行调试是如此诱人? 在我的第一份工作中,我要做的任务之一是修复一个错误,该错误过去在非常复杂的生产系统中有时会发生. 很简单! - 我想. 我将在开发环境中重现同样的情况,找 ...

  3. unity 日志级别_【Unity】通用的Debugger日志模块

    usingSystem;usingSystem.IO;namespaceUnityEngine {/// ///系统日志模块/// public classDebugger {public stati ...

  4. 用Java代码实现日志记录器_如何在此简单的Java日志记录实现中附加到日志文件? - java...

    我得到了以下用于创建和管理Logger的类.每当执行代码和程序时,都会使用对静态getLogger()捕获块的调用进行记录. public class Log { private static fin ...

  5. history linux 日志服务器_编译bash实现history的syslog日志记录

    一.编译BASH实现bash的syslog日志记录功能 1. 本文将通过bash软件实现history记录到syslog日志的功能,并通过该方式可以实现实时的传送到了远端的日志集中服务器上,可以实现操 ...

  6. elk 日志管理_具有ELK的APIGEE API网关日志管理(弹性搜索,Logstash和Kibana)

    elk 日志管理 在本文中,我们将看到如何使用 Elastic Search , Logstash 和 Kibana 管理APIGEE API网关生成的日志 . 下图突出显示了日志数据如何流经ELK堆 ...

  7. 12c集群日志位置_大数据系列教程006-开启日志聚合功能

    Container日志是hadoop各个container记录的日志,其中会包含错误或失败的重要信息.如果没有打开日志聚合,默认是分布在各个nodemanager节点上的.如果打开了日志聚合选项,则会 ...

  8. java 日志切面_自定义注解+面向切面整合的日志记录模块(一)

    java中的常见注解 jdk的自带注解 @Override:告诉编译器我重写了接口方法 @Deprecated:告诉编译器这个方法过时了,不建议使用,Ide会在方法上划横线 @SuppressWarn ...

  9. Nginx调试日志[emerg]: invalid log level “debug_http” in /path/conf/nginx.conf:XX

    配置日志的时候重启nginx报错:[emerg]: invalid log level "debug_http" in /path/conf/nginx.conf:XX,看到这篇文 ...

最新文章

  1. android回调函数
  2. LeetCode455 分发饼干(二分法)
  3. App Inventor2项目部署到本地
  4. 【图表】java 24年发展历史及长期支持jdk版本(up to 2020.04)
  5. 基础算法 —— 调度问题
  6. EXCHANGE 2013 一例证书故障
  7. Web 开发人员和设计师必读文章推荐【系列三十】
  8. 复制VIM编辑的文件和代码到别的地方
  9. mysql 加权_数据库 – MySQL中的加权平均计算?
  10. 用微信名片制作软件打造专属的电子名片
  11. Frank Pfenning
  12. 【Oracle】建立关联三个表的视图
  13. NANDFLASH与PSRAM
  14. APP在线制作平台,手机应用,手机App开发,手机客户端开发
  15. QAP-based Simulation-Extractable SNARK with a Single Verification及代码实现
  16. [Mac/Minikube] 使用K8s搭建ZooKeeper集群
  17. 嵌入式C语言实例(达内2013)
  18. 计算机开始菜单设置方法,开始菜单不见了,教您Win7开始菜单不见了如何解决
  19. SomeProbles:关于Mac不能格式化新的wd硬盘问题
  20. Java限流及常用解决方案总结

热门文章

  1. (前端)图片如何从模糊到清晰渐显
  2. 十大战略工具(1)——波士顿矩阵
  3. HCIP-H12-221单选题库(4)
  4. 《C++程序设计》在线平时作业2
  5. H3C 无线交换机的数据转发原理
  6. 【Apache POI】Excel操作(一):Excel本地写入基本操作的实现
  7. 2013的联想台式计算机,联想台式电脑选购常识_联想台式电脑使用常识 -真快乐商城...
  8. 人工智能调研报告汇总
  9. 语音论文阅读(Conformer:基于卷积增强的Transformer语音识别模型)
  10. python零基础入门教程视频下载-零基础学Python入门教程,视频资源下载