Skip to content

Conversation

@jfeltesse-mdsol
Copy link
Contributor

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

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?
Copy link
Member

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.

Copy link
Collaborator

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?

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Apr 21, 2017 via email

@jfeltesse-mdsol
Copy link
Contributor Author

@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.
Note that right now it's only that one which is "duplicated", the client doesn't send http.uri for instance.
I'll amend this PR and comment back.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Apr 24, 2017 via email

@jfeltesse-mdsol jfeltesse-mdsol changed the title Add the :always_record_path configuration option Add the :record_on_server_receive configuration option Apr 24, 2017
@jfeltesse-mdsol
Copy link
Contributor Author

changed the option to :record_on_server_receive which accepts CSV style tag names, whitelisting them though. It only supports http.path for now, not sure what would make sense to add...

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
Copy link
Collaborator

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

Copy link
Contributor Author

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_receive is falsy
    => tags var is nil
    => trace_request_information doesn'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.

Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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)

sampled_as_boolean: true
}

def parse_record_on_server_receive(tag_names)
Copy link
Member

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..

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit spelling receive

Copy link
Contributor Author

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"

Copy link
Member

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

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Apr 25, 2017 via email

# 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?
Copy link
Collaborator

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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?
Copy link
Collaborator

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?
Copy link
Collaborator

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
  {}
end

Copy link
Contributor Author

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.

@jcarres-mdsol jcarres-mdsol merged commit 5aa6afd into openzipkin:master Apr 26, 2017
@jfeltesse-mdsol jfeltesse-mdsol deleted the feature/always_record_path_option branch April 26, 2017 09:13
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

Successfully merging this pull request may close these issues.

3 participants