diff --git a/lib/middleware/request_tracker.rb b/lib/middleware/request_tracker.rb index fda5fc46f28..4decb0983c8 100644 --- a/lib/middleware/request_tracker.rb +++ b/lib/middleware/request_tracker.rb @@ -125,13 +125,26 @@ class Middleware::RequestTracker is_api: is_api, is_user_api: is_user_api, is_background: is_message_bus || is_topic_timings, - background_type: is_message_bus ? "message-bus" : "topic-timings", is_mobile: helper.is_mobile?, track_view: track_view, timing: timing, queue_seconds: env['REQUEST_QUEUE_SECONDS'] } + if h[:is_background] + h[:background_type] = if is_message_bus + if request.query_string.include?("dlp=t") + "message-bus-dlp" + elsif env["HTTP_DONT_CHUNK"] + "message-bus-dontchunk" + else + "message-bus" + end + else + "topic-timings" + end + end + if h[:is_crawler] user_agent = env['HTTP_USER_AGENT'] if user_agent && (user_agent.encoding != Encoding::UTF_8) diff --git a/spec/lib/middleware/request_tracker_spec.rb b/spec/lib/middleware/request_tracker_spec.rb index b3953a53913..d00fc3f7592 100644 --- a/spec/lib/middleware/request_tracker_spec.rb +++ b/spec/lib/middleware/request_tracker_spec.rb @@ -2,10 +2,10 @@ RSpec.describe Middleware::RequestTracker do def env(opts = {}) - create_request_env.merge( + path = opts.delete(:path) || "/path?bla=1" + create_request_env(path: path).merge( "HTTP_HOST" => "http://test.com", "HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", - "REQUEST_URI" => "/path?bla=1", "REQUEST_METHOD" => "GET", "HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "rack.input" => StringIO.new @@ -666,5 +666,21 @@ RSpec.describe Middleware::RequestTracker do expect(headers["X-Runtime"].to_f).to be > 0 end + + it "can correctly log messagebus request types" do + tracker = Middleware::RequestTracker.new(app([200, {}, []])) + + tracker.call(env(path: "/message-bus/abcde/poll")) + expect(@data[:is_background]).to eq(true) + expect(@data[:background_type]).to eq("message-bus") + + tracker.call(env(path: "/message-bus/abcde/poll?dlp=t")) + expect(@data[:is_background]).to eq(true) + expect(@data[:background_type]).to eq("message-bus-dlp") + + tracker.call(env("HTTP_DONT_CHUNK" => "True", path: "/message-bus/abcde/poll")) + expect(@data[:is_background]).to eq(true) + expect(@data[:background_type]).to eq("message-bus-dontchunk") + end end end