Skip to content

Commit

Permalink
Integrate Util::Quantization
Browse files Browse the repository at this point in the history
  • Loading branch information
duonoid committed Feb 3, 2020
1 parent e9c021b commit 99f44e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions adapters/rack/lib/opentelemetry/adapters/rack/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter
require_dependencies

retain_middleware_names if config[:retain_middleware_names]
configure_default_quantization

if (app = config[:application])
app.use Middlewares::TracerMiddleware
Expand All @@ -32,6 +33,7 @@ class Adapter < OpenTelemetry::Instrumentation::Adapter

def require_dependencies
require_relative 'middlewares/tracer_middleware'
require_relative 'util/quantization'
end

MissingApplicationError = Class.new(StandardError)
Expand All @@ -57,6 +59,10 @@ def call(env)
next_middleware.instance_variable_get('@app')
end
end

def configure_default_quantization
config[:url_quantization] ||= ->(url) { Util::Quantization.url(url, config[:quantization_options]) }
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# require Adapter so .install method is found:
require_relative '../../../../../lib/opentelemetry/adapters/rack'
require_relative '../../../../../lib/opentelemetry/adapters/rack/adapter'
require_relative '../../../../../lib/opentelemetry/adapters/rack/util/quantization'
require_relative '../../../../../lib/opentelemetry/adapters/rack/middlewares/tracer_middleware'

describe OpenTelemetry::Adapters::Rack::Middlewares::TracerMiddleware do
Expand Down Expand Up @@ -146,7 +147,7 @@

describe 'config[:quantization]' do
before do
Rack::MockRequest.new(rack_builder).get('/really_long_url', env)
Rack::MockRequest.new(rack_builder).get('/really_long_url?category_id=1&sort_by=asc#featured', env)
end

describe 'without quantization' do
Expand All @@ -165,6 +166,19 @@
it 'mutates url according to url_quantization' do
_(first_span.name).must_equal '/reall'
end

describe 'with more complex quantization' do
let(:quantization_options) do
{ query: { exclude: :all } }
end
let(:quantization_example) do
->(url) { adapter_module::Util::Quantization.url(url, quantization_options) }
end

it 'mutates url' do
_(first_span.name).must_equal '/really_long_url'
end
end
end
end

Expand Down

0 comments on commit 99f44e8

Please sign in to comment.