OpenTelemetry在Erlang/Elixir中的传播 – 一个示例

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

OpenTelemetry Propagation in Erlang/Elixir - an example

问题

I have a gRPC API and want to add Otel based tracing to it. Every request to this API contains trace/span ID, but I am struggling to properly emit child span.

Here is an example from iex:

require OpenTelemetry.Tracer
alias OpenTelemetry.Tracer

:otel_propagator_text_map.extract([{"traceparent", "00-00000000000000001f28325aa9c79b59-37ab46991f7a64e1-00"}])
_parent = :otel_tracer.current_span_ctx()

span_ctx = Tracer.start_span("otel-test")
Tracer.set_current_span(span_ctx)
# start doing some work
:timer.sleep(100)
# work done

Tracer.end_span(span_ctx)

Not sure what is wrong here but I don't see span emitted in the iex console.
As I understand when traceparent is extracted it becomes parent span automatically, hence the need to change the span via set_current_span/1.

Can someone tell me what is wrong here?

英文:

I have a gRPC API and want to add Otel based tracing to it. Every request to this API contains trace/span ID, but I am struggling to properly emit child span.

Here is an example from iex:

require OpenTelemetry.Tracer
alias OpenTelemetry.Tracer

:otel_propagator_text_map.extract([{"traceparent", "00-00000000000000001f28325aa9c79b59-37ab46991f7a64e1-00"}])
_parent = :otel_tracer.current_span_ctx()

span_ctx = Tracer.start_span("otel-test")
Tracer.set_current_span(span_ctx)
# start doing some work
:timer.sleep(100)
# work done

Tracer.end_span(span_ctx)

Not sure what is wrong here but I don't see span emitted in the iex console.
As I understand when traceparent is extracted it becomes parent span automatically, hence the need to change the span via set_current_span/1.

Can someone tell me what is wrong here?

答案1

得分: 1

已解决。

traceparent头部中,trace-flags指向不进行采样,因此输出中没有任何内容。

应该是:00-00000000000000001f28325aa9c79b59-37ab46991f7a64e1-01

来源:https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers

英文:

Ok, solved.

trace-flags in traceparent header point to no sampling hence nothing in the output.

Should be: 00-00000000000000001f28325aa9c79b59-37ab46991f7a64e1-01

Source: https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers

huangapple
  • 本文由 发表于 2023年7月6日 22:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629837.html
匿名

发表评论

匿名网友

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

确定