-
Hello opentelemetry-ruby team, we use the gem a microservice platform. There intermediate http requests are made to different services, and therefore we don't have a common webserver instance from which we could create child spans. It seems that to achieve a common span / trace we need to propagate the traceId so we can represent our request structure. Therefore, first question: Is propagating the traceId a suitable way how to achieve what we need, or are you aware of a better way? Second, if this is the proper approach, how would this work technically? I've checked the repo, and there i've seen that using custom traceIds is not supported. Therefore i thaught of extending the OpenTelemetry::Trace::Tracer in_span method to accept a trace_id parameter and the add_span method to accept the parameter as well. In the OpenTelemetry::SDK::Trace::Tracer.add_span method the trace_id can then be directly used. Would you consider this as the optimal way how to reach this aim here, or would you suggest a better one? If this is the one we would be happy to contribute with a PR. Looking forward to your responses, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @c23omega - you have the right idea; in order to connect spans from disparate systems you need to propagate a custom trace ID. Luckily, this should be almost - if not completely - free! I would start by looking at the OpenTelemetry overview document. That page introduces a lot of terminology that's useful when working with the I would next take a look at our http example - that contains an example of a client and server, and shows you how to manually inject context into the headers of an outgoing request from the client, and how to extract the context from an inbound request on the server. It also shows on the server how you activate the context that was extracted - and that activation is what causes the server's spans to be logical children of the client's spans. That example is really good to understand what needs to happen - but what's even better is that you don't actually have to do this manually! If you're using something that has auto-instrumentation available, then it's almost zero-effort! For example, if your "client" application uses require 'opentelemetry/sdk'
require 'opentelemetry-instrumentation-faraday'
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::Faraday'
end ...and on the "server", if you're using Rails, you could initialize the OpenTelemetry SDK like so: require 'opentelemetry/sdk'
require 'opentelemetry-instrumentation-rails'
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::Rails'
end ...and when you do it like that, any outbound request from the client (via Faraday) will have the current context injected automatically into request headers, and any inbound request into the rails server will extract that context and make it the "current" context automatically from the request headers. In that specific example, you don't have to write any code at all other than just initializing the SDKs - the auto-instrumentation handles it all for you. And, if you're not using faraday and rails, there is a lot of other auto instrumentation available, and they all have examples. Let me know if that helps! |
Beta Was this translation helpful? Give feedback.
Hi @c23omega - you have the right idea; in order to connect spans from disparate systems you need to propagate a custom trace ID. Luckily, this should be almost - if not completely - free!
I would start by looking at the OpenTelemetry overview document. That page introduces a lot of terminology that's useful when working with the
opentelemetry-ruby
library. The parts that talk about your question are "Context propagation" - that's the mechanism that carries the trace ID between services on different systems. As long as context is injected into outbound requests and extracted from incoming requests, then spans from different systems should be assembled by your tracing vendor / system autom…