-
Notifications
You must be signed in to change notification settings - Fork 37
Add the :record_on_server_receive configuration option
#103
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
Add the :record_on_server_receive configuration option
#103
Conversation
lib/zipkin-tracer/config.rb
Outdated
| if @sampled_as_boolean | ||
| @logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false") | ||
| end | ||
| # Record the path info on server receive, even if the zipkin headers were present in the incoming request? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought about this a little elsewhere and kindof like the keys approach, where you specify the keys you would like to have added to the span. I'm not sure if this config is shared between client and server or not. If it isn't you could imagine a set that includes "http.uri" etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the configuration file would have a list of keys to be added on each span for both the client and the server?
|
You mean the configuration file would have a list of keys to be added on
each span for both the client and the server?
yep. this is particularly neat with http.url vs http.uri, but also when
people add new keys like "requestId" as then you can declaratively decide
whether to add it even if the code is always there
|
|
@adriancole talking with @jcarres-mdsol offline we came to the conclusion that I'm going to change that configuration option to something more generic that would allow you to specify keys that are recognized by the client/server, such as http.path, in CSV style. |
|
sounds great. I'm excited to see where this goes. we might use similar
approach in other tracers.
|
:always_record_path configuration option:record_on_server_receive configuration option
|
changed the option to |
lib/zipkin-tracer/config.rb
Outdated
| end | ||
| # Record the given tags on server receive, even if the zipkin headers were present in the incoming request? | ||
| tags = config[:record_on_server_receive] | ||
| @record_on_server_receive = present?(tags) ? parse_record_on_server_receive(tags) : nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do {} instead of nil and later you do not need to check for nil just do .each on the hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason I went this way is that the standard case is the user doesn't have this option set and the service is called by another zipkin-enabled one. In this 99% of the time case, we don't need to do anything at all, e.g.
zipkin_env.called_with_zipkin_headers?is true@config.record_on_server_receiveis falsy
=>tagsvar is nil
=>trace_request_informationdoesn't do anything
If I go the default empty hash route here I'll either have to check for nil and empty or I'll have to create a new hash object every time just so that .each doesn't blow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty hash would be made only here in config and then stay empty, then you do not need to check for it, maybe you'll need to call merge on it and each.
On the other hand nil brings no meaning, given that something blows up and it is a nil, it is difficult to know the intention of that data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this? c41332a
| # This middleware reads Zipkin headers from the request and sets/creates a Trace.id usable by the rest of the app | ||
| # It will also send the trace to the Zipkin service using one of the methods configured. | ||
| class RackHandler | ||
| # the following constants are defined only from rack 1.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we depend on rack > 1.6 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really if we want to keep a reasonable backwards-compatibility.
For instance actionpack 4.1.x depends on rack ~> 1.5.2 (https://rubygems.org/gems/actionpack/versions/4.1.16)
lib/zipkin-tracer/config.rb
Outdated
| sampled_as_boolean: true | ||
| } | ||
|
|
||
| def parse_record_on_server_receive(tag_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what's idiomatic, but seems like it would be easier to see this if this function were in the rack class (ex tag filter was passed to it vs moving the logic here). For example, it would make it easier to see if you change "parse_record_on_server_receive" to "parse_tags" and no meaning is loss. I was looking to see if any tags were added on server send and needed to scroll to the rack handler file to find that out..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I get it, here I'm parsing the value passed in the config once and for all, just like the other config options. I don't think that parsing whatever was passed at config time belongs in the rack class since it has nothing to do with middleware stuff.
| tags = DEFAULT_SERVER_RECV_TAGS unless zipkin_env.called_with_zipkin_headers? | ||
| # if the user specified tags to record on server recv, use these no matter what | ||
| tags = @config.record_on_server_receive if @config.record_on_server_receive | ||
| # if the user specified tags to record on server receive, use these no matter what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit spelling receive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? Am I missing something? Any spelling issue with the following?
"if the user specified tags to record on server receive, use these no matter what"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird.. I thought I saw "recieve" here! Ignore me .. I'm not helping I think :P
|
sorry I misunderstood. thanks for clearing!
|
| # if the user specified tags to record on server recv, use these no matter what | ||
| tags = @config.record_on_server_receive if @config.record_on_server_receive | ||
| # if the user specified tags to record on server receive, use these no matter what | ||
| tags = @config.record_on_server_receive unless @config.record_on_server_receive.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do this? just let the empty hash reach trace_request_information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, that was in line with the old tags can be nil code but it doesn't make sense anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, nope, can't do this because of the case where we'd been called by a non zipkin enabled service, tags would be using the DEFAULT_SERVER_RECV_TAGS. Getting rid of the check here would overwrite this and make it empty...
And I can't use that DEFAULT_SERVER_RECV_TAGS as the config's default altogether because we still need it to be empty in the 99% case where we're called with zipkin headers and we don't want the http.path to be recorded too.
In a nutshell, we need the empty default config while having an alternative default for the case of no zipkin headers in the request.
Makes sense?
| # if called by a service, the caller already added the information | ||
| trace_request_information(span, zipkin_env.env) unless zipkin_env.called_with_zipkin_headers? | ||
| # if the request comes from a non zipkin-enabled source record the default tags | ||
| tags = DEFAULT_SERVER_RECV_TAGS unless zipkin_env.called_with_zipkin_headers? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe do these things inside trace_request_information ?
| def trace_request_information(span, env, tags) | ||
| # tags is nil if we've been called by a zipkin-enabled service and the user hasn't | ||
| # specified tags to record on server receive. | ||
| return if tags.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe...
tags = if !@config.record_on_server_receive.empty?
@config.record_on_server_receive
else if !zipkin_env.called_with_zipkin_headers?
DEFAULT_SERVER_RECV_TAGS
else
{}
endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated following your recommendation but left the return if tags.nil? check so as not to needlessly create empty hash objects and call .each on them in what is going to be the 99% use case.
This adds a new configuration option to force the sending of path info on server receive.
Usually it is not needed because it's provided by the client but we have a use case here that requires that data to be sent (in a nutshell some service processing zipkin data to compute metrics).
@jcarres-mdsol @adriancole