首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >uber zap登录到apm服务器

uber zap登录到apm服务器
EN

Stack Overflow用户
提问于 2022-02-03 07:20:29
回答 1查看 365关注 0票数 2

我试图使用uber zap日志库将日志发送到APM服务器。

我已经尝试过他们的仪表模块(https://www.elastic.co/guide/en/apm/agent/go/1.x/builtin-modules.html#builtin-modules-apmzap)这样做,但它对我没有用:

事务不会发送到APM服务器。

环境司:

代码语言:javascript
运行
复制
ELASTIC_APM_LOG_FILE=stderr=stderr
ELASTIC_APM_LOG_LEVEL=debug
ELASTIC_APM_SERVICE_NAME=service-name
ELASTIC_APM_SERVER_URL=http://localhost:8200
代码语言:javascript
运行
复制
import (
    "go.uber.org/zap"

    "go.elastic.co/apm/module/apmzap"
)

// apmzap.Core.WrapCore will wrap the core created by zap.NewExample
// such that logs are also sent to the apmzap.Core.
//
// apmzap.Core will send "error", "panic", and "fatal" level log
// messages to Elastic APM.
var logger = zap.NewExample(zap.WrapCore((&apmzap.Core{}).WrapCore))

func handleRequest(w http.ResponseWriter, req *http.Request) {
    // apmzap.TraceContext extracts the transaction and span (if any)
    // from the given context, and returns zap.Fields containing the
    // trace, transaction, and span IDs.
    traceContextFields := apmzap.TraceContext(req.Context())
    logger.With(traceContextFields...).Debug("handling request")
    logger.With(traceContextFields...).Error("handling error")
}
EN

回答 1

Stack Overflow用户

发布于 2022-02-03 14:07:36

将APM堆栈更新为7.15。工作得很完美。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70967222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档