Skip to content

Commit

Permalink
Update version and changelog for 'abstract route to span name' (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykitamura-mdsol authored and jcarres-mdsol committed Sep 11, 2018
1 parent 50640d9 commit 7c50494
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.29.0
* Add abstract route to span name
* Fix not to raise "NoMethodError" for Rails:Module

# 0.28.0
* Add the `:trace_id_128bit` configuration option.

Expand Down
10 changes: 5 additions & 5 deletions lib/zipkin-tracer/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ def self.routable_request?(path_info, http_method)
false
end

def self.get_route(path_info, http_method)
def self.get_route(env)
return nil unless defined?(Rails)
req = Rack::Request.new("PATH_INFO" => path_info, "REQUEST_METHOD" => http_method)
req = Rack::Request.new(env)
# Returns a string like /some/path/:id
Rails.application.routes.router.recognize(req) { |route|
Rails.application.routes.router.recognize(req) do |route|
return route.path.spec.to_s
}
end
rescue
nil
end

def self.logger
if defined?(Rails) # If we happen to be inside a Rails app, use its logger
if defined?(Rails.logger) # If we happen to be inside a Rails app, use its logger
Rails.logger
else
Logger.new(STDOUT)
Expand Down
8 changes: 6 additions & 2 deletions lib/zipkin-tracer/rack/zipkin-tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def call(env)
if !trace_id.sampled? || !routable_request?(env)
@app.call(env)
else
@tracer.with_new_span(trace_id, "#{env[REQUEST_METHOD].to_s.downcase} #{route(env)}".strip) do |span|
@tracer.with_new_span(trace_id, span_name(env)) do |span|
trace!(span, zipkin_env) { @app.call(env) }
end
end
Expand All @@ -44,7 +44,11 @@ def routable_request?(env)
end

def route(env)
Application.get_route(env[PATH_INFO], env[REQUEST_METHOD])
Application.get_route(env)
end

def span_name(env)
"#{env[REQUEST_METHOD].to_s.downcase} #{route(env)}".strip
end

def annotate_plugin(span, env, status, response_headers, response_body)
Expand Down
2 changes: 1 addition & 1 deletion lib/zipkin-tracer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ZipkinTracer
VERSION = '0.28.0'.freeze
VERSION = '0.29.0'.freeze
end
3 changes: 2 additions & 1 deletion spec/lib/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module ZipkinTracer
end

describe '.get_route' do
subject { Application.get_route("path", "METHOD") }
let(:env) { { "PATH_INFO" => "path", "REQUEST_METHOD" => "METHOD" } }
subject { Application.get_route(env) }

context 'Rails available' do
before do
Expand Down

0 comments on commit 7c50494

Please sign in to comment.