Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build a backend trace ruby library #157

Open
littlegrasscao opened this issue Jul 17, 2019 · 5 comments
Open

Build a backend trace ruby library #157

littlegrasscao opened this issue Jul 17, 2019 · 5 comments

Comments

@littlegrasscao
Copy link

I plan to to build a backend trace library, not only tracing the HTTP requests, that collects the span information of every method in the path and POST to zipkin server. Is it possible to do it?

I think it needs a wrapper before each method to collect time cost and send spans to another backend server. The backend server can analyze the spans, generate a trace and send to Zipkin server.
The hard part is how to keep an identical traceID through the path and make each span include its parent ID in the path. With a backend server, I can create a stack that keeps tracking the methods being called. Add to stack before calling the method and pop out when finishing the method. However, if two traces happen at the same time(asynchronous), the stack would be a messy.

@littlegrasscao
Copy link
Author

I achieved the functionality of tracing a Non-web backend application. I added a wrapper at the beginning of the class and added one more parameter to everyone method call. The additional function parameter is a hash table that stores traceID and parentID. The wrapper records timestamps and generate an ID when calling a new method. When the method returns, the wrapper would generate a span and POST to the Zipkin server. The overall idea is similar to HTTP based tracing. One disadvantage is that It is kind of annoying to add one more parameter to every method call.

@jcarres-mdsol
Copy link
Collaborator

Yeah, I think that approach will be too hard to use for users.
Maybe you could have luck with ptrace or some kind of hook on each method

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Jul 24, 2019 via email

@littlegrasscao
Copy link
Author

You can try my test version. It is actually not that hard to use. I have done many tests, my wrapper works with all kinds of situations. This is the best way I can think of without modifying the Zipkin server interface. The overhead is also very small, which can be neglected.

To compile, enter: ruby test.rb. Make sure you have a local zipkin server that is running.
Backend_Trace_Test.zip

@codefromthecrypt
Copy link
Member

PS my above comment went on the wrong issue. it was meant for #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants