Skip to content

Commit

Permalink
Deprecate StreamingListener middleware
Browse files Browse the repository at this point in the history
Deprecate the StreamingListener now that it is almost identical to the
AbstractMiddleware. Those couple differences are actually ones we don't
want people to rely on, so deprecate it.
  • Loading branch information
tombruijn committed Jul 8, 2024
1 parent e26902a commit 57d6fa3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
type: deprecate
---

Deprecate the `Appsignal::Rack::StreamingListener` middleware. Use the `Appsignal::Rack::InstrumentationMiddleware` middleware instead.

5 changes: 5 additions & 0 deletions lib/appsignal/rack/streaming_listener.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# frozen_string_literal: true

Appsignal::Utils::StdoutAndLoggerMessage.warning \
"The constant Appsignal::Rack::StreamingListener has been deprecated. " \
"Please update the constant name to " \
"Appsignal::Rack::InstrumentationMiddleware."

module Appsignal
module Rack
# Instrumentation middleware that tracks exceptions in streaming Rack
Expand Down
78 changes: 57 additions & 21 deletions spec/lib/appsignal/rack/streaming_listener_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
require "appsignal/rack/streaming_listener"
describe "Appsignal::Rack::StreamingListener" do
def load_middleware
load "lib/appsignal/rack/streaming_listener.rb"
end

describe Appsignal::Rack::StreamingListener do
let(:env) { {} }
let(:app) { DummyApp.new }
let(:middleware) { described_class.new(app, {}) }
before { start_agent }
around { |example| keep_transactions { example.run } }
describe "loading the streaming_listener integrations file" do
let(:err_stream) { std_stream }
let(:stderr) { err_stream.read }
after { Appsignal::Rack.send(:remove_const, :StreamingListener) }

def make_request
middleware.call(env)
end
it "prints a deprecation warning to STDERR" do
capture_std_streams(std_stream, err_stream) do
load_middleware
end

it "instruments the call" do
make_request
expect(stderr).to include(
"appsignal WARNING: The constant Appsignal::Rack::StreamingListener " \
"has been deprecated."
)
end

expect(last_transaction).to include_event("name" => "process_streaming_request.rack")
it "logs a warning" do
logs =
capture_logs do
silence do
load_middleware
end
end

expect(logs).to contains_log(
:warn,
"The constant Appsignal::Rack::StreamingListener has been deprecated."
)
end
end

it "set no action by default" do
make_request
describe "middleware" do
let(:env) { {} }
let(:app) { DummyApp.new }
let(:middleware) { Appsignal::Rack::StreamingListener.new(app, {}) }
around { |example| keep_transactions { example.run } }
before(:context) { load_middleware }
before { start_agent }

expect(last_transaction).to_not have_action
end
def make_request
middleware.call(env)
end

it "instruments the call" do
make_request

expect(last_transaction).to include_event("name" => "process_streaming_request.rack")
end

it "set no action by default" do
make_request

expect(last_transaction).to_not have_action
end

it "set `appsignal.action` to the action name" do
env["appsignal.action"] = "Action"
it "set `appsignal.action` to the action name" do
env["appsignal.action"] = "Action"

make_request
make_request

expect(last_transaction).to have_action("Action")
expect(last_transaction).to have_action("Action")
end
end
end

0 comments on commit 57d6fa3

Please sign in to comment.