-
Notifications
You must be signed in to change notification settings - Fork 76
any plan to support in multi thread? #165
Comments
I was also wondering this, as in our case we use TBB (actually ConCRT) spawning parallel_for and std::thread, but then tried to pass just the context - e.g. span.context() and it worked. Because after all the context is simply three "integer" values (of different sizes): thrace id, span id and options |
I ended up with hacky, but workable (for my case) way: a thread_local s_activeSpanContext; that gets saved (in RAII object), then restored back. I also ave another special one s_rootSpanContext - created at the begining, which gets used if the !s_activeSpanContext.IsValid() (just to handle edge cases). It's not perfect, and I know I should be handing off actual context, but at the same time this means changing a lot of the code - basically adding an additional argument to a lot of places (still the proper thing to do, but need to evaluate a bit more and then do it). |
I do the same work |
Hi all, @g-easy will start working on adding a Context support soon. I will keep this issue updated. |
Hava any progress report? @bogdandrutu |
Hi billowqiu, @g-easy has a prototype we are trying to polish the public API for the moment. This week the PR should land. |
@bogdandrutu if i have multiple threads to handle incoming requests |
@g-easy please follow on this |
@billowqiu Best practices:
e.g. {
WithSpan ws(span);
executor.add(Context::Current()::Wrap(callback_fn));
} Does this help? |
thanks
发自我的 iPhone
… 在 2018年10月12日,上午11:47,easy ***@***.***> 写道:
@billowqiu Best practices:
Always have the correct Context installed.
To set a current Span, use a WithSpan object.
Treat WithSpan as RAII - always stack-allocate it.
For callbacks, as you said, Wrap the callback while the correct context is installed.
e.g.
{
WithSpan ws(span);
executor.add(Context::Current()::Wrap(callback_fn));
}
Does this help?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'm trying to document this in #224 |
I have a scene,like the diagram: Undoubtedly, there are other ways of accomplishing the same thing (and maybe some of them are even easier). |
To do this in an async way, I would suggest the server component does something like this: void Server1(RequestFromClient req) {
// Server receives trace context and tagging context from client.
SpanContext parent_ctx = req.GetContext();
TagMap tags = reg.GetTags();
// Create the server-side span.
Span span = Span::StartSpanWithRemoteParent("ServerSpan", parent_ctx);
// Create a Context for this operation.
WithSpan ws(span);
WithTagMap wt(tags);
// Send request to s1 with the current Context installed.
// When that request completes, it will run a callback.
DownstreamRequest req1(...);
req1.Run(/* callback = */ Context::Current()::Wrap(Server2));
}
void Server2(ReplyFromDownstream reply1) {
// The current Context is correct.
Process(reply1);
// Send request to s2 with the current Context installed.
// When that request completes, it will run a callback.
DownstreamRequest req2(...);
req2.Run(/* callback = */ Context::Current()::Wrap(Server3));
}
void Server3(ReplyFromDownstream reply2) {
// The current Context is correct.
Process(reply2);
ReplyToClient();
// Operation is complete, remember to end the span.
GetCurrentSpan().End();
} Where Does this make sense? Does it look okay to you? Do you think there is a better and/or simpler approach? |
My plan for the gRPC integration is that the gRPC plugin will take care of:
|
This is helpful. |
look forward to see this integration 👍 |
like this link Passing Segment Context between Threads in a Multithreaded Application
The text was updated successfully, but these errors were encountered: