grpc-swift
grpc-swift copied to clipboard
how t0 add a trace for service call chain
What are you trying to achieve?
If I want to add a trace for our service call chain, do you have some suggestions for below example?
I have AProvider/AClient/BProvider/BClient, the call chain is AClient call AProvider methodA, In AProvider methodA I need to create a new BClient and call BProvider methodB. When I use AClient call AProvider I add callOptions like below
var options = greeter.defaultCallOptions
options.requestIDHeader = "x-trace-id"
options.requestIDProvider = .userDefined("mxy-trace-id")
And in AProvider methodA I also can get the x-trace-id
, And I also can create a options then pass to BClient for thist trace.
Even I can use this method to archive my goal, but I think it will generate so much same code. what suggestions do you have? thanks.
Tracing is in a slightly awkward space at the moment. There is a Swift package for distributed tracing (https://github.com/apple/swift-distributed-tracing) intended to make this easier. However, it does not have a stable API (so we can't adopt it) and it's likely to be impacted by new language features (see also https://github.com/apple/swift-distributed-tracing#important-note-on-adoption).
At the moment I think your best option is doing what you're doing now but with a set of helpers to reduce the toil of extracting and forwarding trace headers.
@glbrntt thanks your answer patiently, can I think as if the swift-distributed-tracing api is stable, will adapt it?
We would like to but it depends somewhat on the API and supported Swift versions. It may be something that happens more naturally as a v2.0 of grpc-swift.