zipkin-ruby icon indicating copy to clipboard operation
zipkin-ruby copied to clipboard

How to set component_span with Rack middleware?

Open georgeu2000 opened this issue 9 years ago • 7 comments

We have the following config for a Sinatra App:

zipkin_config = { service_name:ENV[ '...' ],
                  service_port:settings.port,
                  sampled_as_boolean:false,
                  sample_rate: 1,
                  json_api_host: ENV[ '..' ]}
use ZipkinTracer::RackHandler, zipkin_config

The span is displayed as "post", which I guess comes from the request method. How can I set it to request method and request path?

georgeu2000 avatar Jan 06 '17 00:01 georgeu2000

the span name is currently hard-set. It could be possible to add a naming function instead, which could compose the value. A lot of instrumentation do things like this.

https://github.com/openzipkin/zipkin-ruby/blob/master/lib/zipkin-tracer/rack/zipkin-tracer.rb#L24

codefromthecrypt avatar Jan 06 '17 03:01 codefromthecrypt

What if we change it to

@tracer.with_new_span(trace_id,"#{env['REQUEST_METHOD']} #{env['PATH_INFO']}".downcase) do ...

Since this is a default, it might be better to more explicit...? (Although I have zero context so this is just for my use case.)

I would be happy to do a PR.

georgeu2000 avatar Jan 06 '17 17:01 georgeu2000

PATH_INFO is likely to be variable, right? If so, it would explode the cardinality of span names which would cause usability (and also UI performance problems). The span name is a label in the UI.

I think the default should be left alone, but allow a function of env to be passed to customize. For example, that could clean up or otherwise format PATH_INFO such that it doesn't repeat endlessly (such as something with an identifier in it would). For those who happen to have low cardinality paths, they could choose to put the function you mention.

sg?

codefromthecrypt avatar Jan 07 '17 02:01 codefromthecrypt

seems there's a long discussion of how to get what's currently referred to as "http.route" from the rails env https://stackoverflow.com/questions/42691729/how-to-find-current-abstract-route-in-rails-middware

see https://github.com/openzipkin/zipkin-api/pull/42 for http.route

codefromthecrypt avatar Feb 23 '18 04:02 codefromthecrypt

I'm not exactly clear how to use the change in https://github.com/openzipkin/zipkin-api/pull/42/files to now get the route in the span name. How do I use HTTP_ROUTE in zipkin-ruby? Do I still want to do something like what @georgeu2000 suggested above, but instead do

@tracer.with_new_span(trace_id,"#{env['REQUEST_METHOD']} #{env['PATH_ROUTE']}".downcase)

and pass the route into env['PATH_ROUTE'] using what's described in your stackoverflow link?

jmhon08 avatar Jun 14 '18 18:06 jmhon08

here's the route-based span name logic we use in java if that helps? https://github.com/openzipkin/brave/blob/master/instrumentation/http/src/main/java/brave/http/HttpParser.java#L94

codefromthecrypt avatar Jun 16 '18 00:06 codefromthecrypt

OK I think I figured it out https://github.com/openzipkin/zipkin-ruby/pull/122/files. This looks good for our Rails app. Can you please review?

screen shot 2018-06-19 at 6 17 06 pm

jmhon08 avatar Jun 20 '18 01:06 jmhon08