openzipkin / zipkin-ruby

zipkin-tracer ruby gem
Apache License 2.0
100 stars 38 forks source link

Build a backend trace ruby library #157

Open littlegrasscao opened 5 years ago

littlegrasscao commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

let's please not introduce methods for sole purpose of posting data to zipkin. zipkin v2 json format is extremely simple with very little depth or complexity in the model. https://zipkin.io/zipkin-api/#/default/post_spans

What is the concern with a: just using a json serializer or b: having a feature here like other libraries which simply takes objects and writes them as json?

can we elaborate before changing the api to add hooks that are better handled offline?

On Wed, Jul 24, 2019 at 4:53 AM Jordi Polo Carres notifications@github.com wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openzipkin/zipkin-ruby/issues/157?email_source=notifications&email_token=AAAPVV3A4DWPYLTI5GFCNXLQA5OUDA5CNFSM4IEJK552YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2UH6AA#issuecomment-514359040, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAPVV22F7N57GIBLZMKA4TQA5OUDANCNFSM4IEJK55Q .

littlegrasscao commented 5 years ago

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 commented 5 years ago

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