My API-gateway starts a tracer and a span for validate email. Then its passed to user-service
for validation.
I want to pass this span
details to user-service
as a json object and start another span
as a
tracer.start_span('Validate Email', child_of=API_gateway_span)
To do it, I have used following struct:
type checkEmail struct {
GatewayTracerSpan opentracing.SpanContext `json: gatewayTracerSpan`
Email string `json: email`
Uuid string `json: uuid`
}
In function()
validateEmailSpan := apitracer.tracer.StartSpan("Validate Email")
emailJson := checkEmail{
GatewayTracerSpan: validateEmailSpan.Context(),
Email: email,
Uuid: uuid,
}
But always GatewayTracerSpan
is empty value.
I have just started distributed-tracing. Here I selected to use json over native http-headers
as its easy for upgrade any protocol change.
Is this possible? If so, am I doing it right? Or what mistakes did I make?
One way to link spans from different services is to use
uber-trace-id
from the parent span. If you haveLogSpans
set totrue
in yourReporterConfig
,uber-trace-id
is what gets printed out ("Reporting span xxx-xxx-xxx"
).Here is how it might look like in the code:
You can now pass
uberTraceID
instead ofvalidateEmailSpan.Context()
to your other services.You can use this function in your other services:
This works for me if I need to see spans between services linked together in a parent-child manner. If other information needs to be passed as well, I would suggest passing it as regular data in the JSON object, then either create my own
Carrier
or use tags if needed to do a search with that passed data.EDIT:
Here you can find a great tutorial on using opentracing. It uses
HTTPHeadersCarrier
, it has a step by step walkthrough, but it's basically the same process as above.