如何在错误记录中始终跟踪 Span?

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

How to always trace Spans on Error recording

问题

我有一个使用opentelemetry进行追踪的Go服务。
目前,我们按比例进行追踪。

现在,为了进行错误分析,我们希望在调用RecordError时始终强制进行追踪。

最初的想法是实现一个sampler,它将查看Span的收集事件。从接口上看,似乎我们无法访问这些事件。

那么我应该如何实现这个功能呢?

英文:

I have a Go Service which gets traced by opentelemetry.
For now, we trace by ratio.

Now for error analysis we would like to change tracing to be always enforced once we call RecordError.

Initial idea was to implement a Sampler, which would look at the collected Events of a Span. From the interfaces it seems like we have no access to this.

So how could I do this instead?

答案1

得分: 4

SDK中的Sampler是基于头部的,即在跨度的开始时做出采样决策,并且OTEL SDK的接口是围绕这个要求构建的。你可以通过始终在开始时进行采样并编写自定义跨度处理器来解决这个问题,该处理器决定是否对跨度进行采样。但是这可能会很复杂,因为它会中断跟踪,并且某些跨度的parentId可能设置为被丢弃的跨度。

或者,你可以通过添加新组件来实现你的目标。进行尾部采样,即根据特定条件丢弃/保留整个跟踪,并且在opentelemetry collector contrib中有一个处理器可以实现这一点https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor。请注意,执行尾部采样的代理/网关部署必须能够访问整个跟踪。

英文:

The Samplers from the SDK are head based i.e sampling decision is made at the beginning of span and interfaces in OTEL SDKs are built around this requirement. One way you could work around this is to always sample in the beginning and write your own custom span processor which makes the decision to whether or not sample the span. This can get hairy quickly since it breaks the trace and some span might have parentId set to span which is dropped.

Or Another way you could achieve your goal but with the addition of new component. Do tail sampling i.e drop/keep the entire trace if it matches certain criteria and there is processor for that in opentelemetry collector contrib https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor. Please note the agent/gateway deployment of collector which is doing tail sampling has to have the access to entire trace.

huangapple
  • 本文由 发表于 2022年5月30日 21:58:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/72435570.html
匿名

发表评论

匿名网友

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

确定