简体   繁体   English

我可以使用 OpenCensus 跟踪子调用函数吗?

[英]can I trace sub called function with OpenCensus?

I want to trace the whole project with Opencensus and Jaeger.我想用 Opencensus 和 Jaeger 追踪整个项目。 I added HTTP trace in entry services and add stratspan in middleware surrounded whol my services and this two-span called and show on Jaeger.我在入口服务中添加了 HTTP 跟踪,并在中间件中添加了stratspan ,包围了我的stratspan服务,这两个跨度在 Jaeger 上调用并显示。 My problem is each service contain a lot of function and I want see a trace of all my functions but in this way not show overall service not shown each function.我的问题是每个服务都包含很多功能,我想查看我所有功能的踪迹,但以这种方式不显示整体服务,未显示每个功能。 I don't like add per function add one stratspan .我不喜欢为每个函数添加一个stratspan I use ctx context.Context entry all my function but not different!我使用ctx context.Context条目我所有的功能但没有什么不同!

There's really not many options for other than starting a span in each function you'd like to instrument:除了在您想要检测的每个函数中启动一个跨度之外,实际上没有太多选择:

func something(ctx context.Context) {
  ctx, span := trace.StartSpan(ctx, "something")
  defer span.End()
}

If your functions have a common call signature, or you can coalesce your function into a common call signature, you can write a wrapper.如果您的函数有一个公共调用签名,或者您可以将您的函数合并为一个公共调用签名,则您可以编写一个包装器。 Examples of this can be seen in http "middleware" .这方面的例子可以在 http "middleware" 中看到。

Consider the http.Handler, you could write a decorator for your functions that handles the span lifecycle:考虑 http.Handler,您可以为处理 span 生命周期的函数编写一个装饰器

func WithTraced(handler http.Handler, opName string) http.Handler {
    return func(w http.ResponseWriter, r *http.Request) {
        ctx, span := trace.StartSpan(ctx, opName)
        defer span.End()
        handler.ServeHTTP(w, r.WithContext(ctx))

    }

}

A similar pattern could be applied by embedding structs.通过嵌入结构可以应用类似的模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以为每个要调用的函数获取函数ID并与之通信吗? - Can I have function ID for each function being called and communicate with it? 为什么当我超时函数时不调用延迟? - Why when I timeout a function a defer is not called? 我可以从恐慌中恢复,处理错误,然后再次恐慌并保持原始堆栈跟踪? - Can I recover from panic, handle the error, then panic again and keep the original stack trace? 自定义OpenCensus指标未显示在Stackdriver上 - Custom OpenCensus metrics not appearing on Stackdriver 如何查看`runtime / trace`生成的跟踪的详细信息? - How do I view the details of a trace produced by `runtime/trace`? 接受interface {}参数的函数如何更新通过引用调用的值? - How can a function that accepts an interface{} parameter update the value it is called with by reference? 如何使用 BPF (BCC) 跟踪 go 函数 - How to trace a go function with BPF (BCC) 如何测试main()函数中正在调用的特定方法 - How do I test that specific methods are being called in the main() function 来自Opencensus图书馆的Golang供应商问题 - Vendoring problem from Opencensus Libraries for Golang 如何使用 OpenCensus 检测 Prometheus Gauge? - How to instrument Prometheus Gauge using OpenCensus?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM