zipkin4net
zipkin4net copied to clipboard
How to add B3-headers to an inbound request and response?
Hello, I'm trying zipkin4net 1.2.1 in a .Net Core 2.1 WebAPI app.
I expected that UseTracingMiddleware
would add tracing headers to HttpContext.Request
and HttpContext.Response
for an inbound request. However, it seems the middleware just make calls to a Zipkin instance.
Should I add the tracing headers to the request/response manually? How to get a correct TraceId
in that case?
Hi @ilya-chumakov,
Did you see https://github.com/openzipkin/zipkin4net/blob/master/Examples/aspnetcore/frontend/Startup.cs#L19 ? Basically, you need to pass a TracingHandler to HTTP clients in order for them to forward traces.
also note that adding headers to the response is unusual as B3 headers were not initially designed for the backtrace. some notes here https://github.com/openzipkin/b3-propagation/issues/4
@fedj yes, I did. TracingHandler is for outbound requests, isn't it? I want to modify an inbound one. Let's say that there is only a WebAPI app which doesn't make any external HTTP calls. This app is called by someone, but it is not possible to force every caller to fill these headers.
@adriancole I would like to give the users (i.e. who calls our APIs) a kind of "request id". They could return it back to us in case of a problem happened. How else could I achieve that without response headers propagation?
@adriancole https://github.com/adriancole I would like to give the users (i.e. who calls our APIs) a kind of "request id". They could return it back to us in case of a problem happened. How else could I achieve that without response headers propagation?
request ids can be determined up front, which then mean you don't need the response to know them. Just know B3 isn't meant for backwards propagation so you can't rely on other frameworks to automatically do this. If your shop has homogeneous deployments you can certainly make it work. https://gitter.im/openzipkin/zipkin for more on this topic if you like as response propagation is a kindof open ended discussion. cheers!
@adriancole thanks, I unsuccessfully have tried that gitter channel before posting here :)
If I'm going to create a middleware filling the headers with a tracing context manually and put it before UseTracingMiddleware
, could you show me an example or class helper to start from?
I don't know dotnet so would want maybe @fedj or someone else to help with the example request
The middleware is located in https://github.com/openzipkin/zipkin4net/blob/8e73b3c93ef0e9b661ca3aae89d70c423abf9775/Src/zipkin4net.middleware.aspnetcore/Src/TracingMiddleware.cs
You would need to Inject B3 headers using the Propagations.B3String.Injector