-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide better resource names for
rack
- Loading branch information
Showing
5 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require_relative 'helpers' | ||
|
||
class ResourceNameTest < Minitest::Test | ||
include Rack::Test::Methods | ||
attr_reader :app | ||
|
||
def setup | ||
@previous_configuration = Datadog.configuration[:rack].to_h | ||
@tracer = get_test_tracer | ||
@app = Rack::Builder.new do | ||
use Datadog::Contrib::Rack::TraceMiddleware | ||
use AuthMiddleware | ||
run BottomMiddleware.new | ||
end.to_app | ||
|
||
remove_patch!(:rack) | ||
Datadog.configuration.use( | ||
:rack, | ||
middleware_names: true, | ||
tracer: @tracer, | ||
application: @app | ||
) | ||
end | ||
|
||
def teardown | ||
Datadog.configuration.use(:rack, @previous_configuration) | ||
end | ||
|
||
def test_resource_name_full_chain | ||
get '/', {}, 'HTTP_AUTH_TOKEN' => '1234' | ||
|
||
spans = @tracer.writer.spans | ||
assert(last_response.ok?) | ||
assert_equal(1, spans.length) | ||
assert_match(/BottomMiddleware#GET/, spans[0].resource) | ||
end | ||
|
||
def test_resource_name_short_circuited_request | ||
get '/', {}, 'HTTP_AUTH_TOKEN' => 'Wrong' | ||
|
||
spans = @tracer.writer.spans | ||
refute(last_response.ok?) | ||
assert_equal(1, spans.length) | ||
assert_match(/AuthMiddleware#GET/, spans[0].resource) | ||
end | ||
|
||
class AuthMiddleware | ||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
return [401, {}, []] if env['HTTP_AUTH_TOKEN'] != '1234' | ||
|
||
@app.call(env) | ||
end | ||
end | ||
|
||
class BottomMiddleware | ||
def call(_) | ||
[200, {}, []] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters