将Uber Zap日志记录到APM服务器。

huangapple go评论116阅读模式
英文:

uber zap logging to apm server

问题

我正在尝试使用Uber Zap日志记录库将日志发送到APM服务器。

我尝试使用它们的仪表板模块(https://www.elastic.co/guide/en/apm/agent/go/1.x/builtin-modules.html#builtin-modules-apmzap)来实现,但对我来说不起作用:

事务未发送到APM服务器。

环境变量:

  1. ELASTIC_APM_LOG_FILE=stderr=stderr
  2. ELASTIC_APM_LOG_LEVEL=debug
  3. ELASTIC_APM_SERVICE_NAME=service-name
  4. ELASTIC_APM_SERVER_URL=http://localhost:8200
  1. import (
  2. "go.uber.org/zap"
  3. "go.elastic.co/apm/module/apmzap"
  4. )
  5. // apmzap.Core.WrapCore将包装由zap.NewExample创建的核心,
  6. // 以便日志也发送到apmzap.Core。
  7. //
  8. // apmzap.Core将发送“error”、“panic”和“fatal”级别的日志消息到Elastic APM。
  9. var logger = zap.NewExample(zap.WrapCore((&apmzap.Core{}).WrapCore))
  10. func handleRequest(w http.ResponseWriter, req *http.Request) {
  11. // apmzap.TraceContext从给定的上下文中提取事务和跨度(如果有),
  12. // 并返回包含跟踪、事务和跨度ID的zap.Fields。
  13. traceContextFields := apmzap.TraceContext(req.Context())
  14. logger.With(traceContextFields...).Debug("handling request")
  15. logger.With(traceContextFields...).Error("handling error")
  16. }
英文:

I'm trying to send logs to the APM server using the uber zap logging library.

I've tried their instrumentation module (https://www.elastic.co/guide/en/apm/agent/go/1.x/builtin-modules.html#builtin-modules-apmzap) to do so but it's not working for me:

The transactions are not being sent to the APM server.

envs:

  1. ELASTIC_APM_LOG_FILE=stderr=stderr
  2. ELASTIC_APM_LOG_LEVEL=debug
  3. ELASTIC_APM_SERVICE_NAME=service-name
  4. ELASTIC_APM_SERVER_URL=http://localhost:8200
  1. import (
  2. "go.uber.org/zap"
  3. "go.elastic.co/apm/module/apmzap"
  4. )
  5. // apmzap.Core.WrapCore will wrap the core created by zap.NewExample
  6. // such that logs are also sent to the apmzap.Core.
  7. //
  8. // apmzap.Core will send "error", "panic", and "fatal" level log
  9. // messages to Elastic APM.
  10. var logger = zap.NewExample(zap.WrapCore((&apmzap.Core{}).WrapCore))
  11. func handleRequest(w http.ResponseWriter, req *http.Request) {
  12. // apmzap.TraceContext extracts the transaction and span (if any)
  13. // from the given context, and returns zap.Fields containing the
  14. // trace, transaction, and span IDs.
  15. traceContextFields := apmzap.TraceContext(req.Context())
  16. logger.With(traceContextFields...).Debug("handling request")
  17. logger.With(traceContextFields...).Error("handling error")
  18. }

答案1

得分: 1

已更新APM堆栈至7.15版本,运行完美。

英文:

Updated APM stack to 7.15. working perfectly.

huangapple
  • 本文由 发表于 2022年2月3日 15:20:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/70967222.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定