diff --git a/adapters/rack/lib/opentelemetry/adapters/rack/adapter.rb b/adapters/rack/lib/opentelemetry/adapters/rack/adapter.rb index e4dfde888..ba1f33768 100644 --- a/adapters/rack/lib/opentelemetry/adapters/rack/adapter.rb +++ b/adapters/rack/lib/opentelemetry/adapters/rack/adapter.rb @@ -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 @@ -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) @@ -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 diff --git a/adapters/rack/test/opentelemetry/adapters/rack/middlewares/tracer_middleware_test.rb b/adapters/rack/test/opentelemetry/adapters/rack/middlewares/tracer_middleware_test.rb index d63666fe2..de092cb09 100644 --- a/adapters/rack/test/opentelemetry/adapters/rack/middlewares/tracer_middleware_test.rb +++ b/adapters/rack/test/opentelemetry/adapters/rack/middlewares/tracer_middleware_test.rb @@ -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 @@ -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 @@ -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