-
Hello, I am working on adding otel to an open source CLI tool written in golang. I trying to use otel since I want to get timing info using traces from multiple concurrent operations and plot it with jaeger. In short, I am finding the golang otel semantics to require passing lots of ctx objects around in sections of the code that ordinarily wouldn't need it. I am trying to find ways of reducing this verbosity. Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In Go, explicitly passing
I am not familiar with the otel implementation in Python, but I guess it uses thread-local storage to propagate the current span info (implicitly passing There is no such thing as thread-local storage in Go. Even if it has, I wouldn't prefer this style, as thread-local storage does not work well in an async manner because it would require hard work to carefully maintain the correct context attached to the thread when switching jobs between threads. From my experience in OTel Java, which also uses thread-local storage, the result would usually become bad if the instrumentation with async didn't deal carefully with the context propagation. And, if something went wrong, it would be difficult for developers to debug. |
Beta Was this translation helpful? Give feedback.
In Go, explicitly passing
ctx
objects is the convention that every method with context info should have. https://go.dev/blog/context#conclusionTracer.start
method uses context to retrieve the current span, so it can create a new span with the sametrace_id
.I am not familiar with the otel implementation in Python, but I guess it uses thread-local storage to propagate the current span info (implicitly passing
ctx
objects). So users don't need to specify the context.There is no such t…