英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论