我可以通过Datadog跟踪器将错误日志记录到Datadog吗?

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

Can I log errors into datadog via datadog tracer?

问题

我有很多使用zerolog的golang应用程序,它们将日志错误/信息等写入本地服务器上的文件。

我在一家国际合作公司工作,决定使用Datadog进行日志记录。合作决策是使用tracer而不是dogstatsd。

我已经提供了以下示例代码:

import (
...
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main(){
    ...
	tracer.Start(
		tracer.WithService("CVR-service"), // 指定服务名称
		tracer.WithEnv("Stage"),           // 指定环境
		tracer.WithServiceVersion("2.0"),
	)
	defer tracer.Stop()	
	 
    mux := httptrace.NewServeMux()
    
    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("CVR-Service-Started!"))
    })
    http.ListenAndServe(":8080", mux)
}

根据我阅读的datadog文档,tracer用于测量性能或请求,示例主要是关于http请求的,我没有找到关于记录错误的示例。我的许多应用程序也没有使用http。我进行了无数次的搜索,没有找到可用的内容。中央合作支持也无法解决我的问题。

是否有办法将zerolog注入tracer或反向注入?例如:

f := some_kind_of_iowriter_from_tracer()
logger := zerolog.New(f).With().Timestamp().Logger()
r, err := Myfunc()
if err != nil {
    logger.Panic().Err(err).Msg("HELP")
}

如果不行,我该如何使用tracer记录错误(和信息)?

或者说,使用datadog tracer实现这个目的是不可能的吗?

英文:

I have a lots of golang application using zerolog, which are writing logs errors/info etc. into a file on the local server.

I work in a international cooperation, which has decided to use Datadog for logging. The cooperate decision is to use tracer and NOT dogstatsd.

I have been supplied with the following example code:

    import (
    ...
    "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
    )
    
    func main(){
        ...
    	tracer.Start(
    		tracer.WithService("CVR-service"), // Specify the service name
    		tracer.WithEnv("Stage"),           // Specify the env
    		tracer.WithServiceVersion("2.0"),
    	)
    	defer tracer.Stop()	
    	 
        mux := httptrace.NewServeMux()
        
        mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
            w.Write([]byte("CVR-Service-Started!"))
        })
        http.ListenAndServe(":8080", mux)
    }

As i read the datadog documentation tracer is used for measuring performance or requests, and the examples are primarily on http
requests and I have not found examples of logging errors. Many of my application doesn't use http either. I have made endless googling and haven't found anything usable. The central cooperate support can't give a solution to my problem.

Is there any kind of way to inject zerolog into tracer or reverse? e.g:

    f := some_kind_of_iowriter_from_tracer()
    logger := zerolog.New(f).With().Timestamp().Logger()
    r, err := Myfunc()
    if err != nil {
        logger.Panic().Err(err).Msg("HELP")
    }

If not how do i use tracer to log errors (and info) ?

Or is it mission impossible to use datadog tracer for this purpose?

答案1

得分: 1

追踪是 APM 的一部分,用于对代码进行仪器化,以测量特定方法和依赖项的性能,并了解代码的运行情况。导入日志是日志管理的一部分。您需要使用 Datadog 代理程序或创建某种转发来跟踪日志文件并通过 HTTP API 发送它们。

英文:

Tracing is part of APM which is for instrumenting code to measure the performance of specific methods and dependencies and getting insight into how code runs. Ingesting logs is part of Log Management. You need to use the Datadog agent or create some kind of forward to tail your log files and send them via the HTTP API.

huangapple
  • 本文由 发表于 2023年3月16日 17:20:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75754164.html
匿名

发表评论

匿名网友

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

确定