-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add http.route tag setting to rack middleware as fallback
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
require 'datadog/tracing/contrib/support/spec_helper' | ||
|
||
require 'rack/test' | ||
|
||
require 'datadog' | ||
require 'datadog/tracing/contrib/rack/middlewares' | ||
|
||
RSpec.describe 'Rack testing for http.route' do | ||
include Rack::Test::Methods | ||
|
||
before do | ||
Datadog.configure do |c| | ||
c.tracing.instrument :rack | ||
end | ||
end | ||
|
||
after do | ||
Datadog.configuration.tracing[:rack].reset! | ||
end | ||
|
||
let(:app) do | ||
app = rack_app | ||
|
||
Rack::Builder.new do | ||
use Datadog::Tracing::Contrib::Rack::TraceMiddleware | ||
|
||
%w[/ /rack].each do |route| | ||
map route do | ||
run app | ||
end | ||
end | ||
end.to_app | ||
end | ||
|
||
let(:rack_app) do | ||
Rack::Builder.new do | ||
map '/hello/world' do | ||
run ->(_env) { [200, { 'content-type' => 'text/plain' }, 'hello world'] } | ||
end | ||
|
||
map '/hello/:id' do | ||
run ->(_env) { [200, { 'content-type' => 'text/plain' }, "hello #{params[:id]}"] } | ||
end | ||
end | ||
end | ||
|
||
it 'sets http.route tag on request to base route' do | ||
response = get('/hello/world') | ||
|
||
expect(response).to be_ok | ||
expect(request_span.get_tag('http.route')).to eq('/hello/world') | ||
end | ||
|
||
it 'sets http.route tag on requst to nested app route' do | ||
response = get('/rack/hello/world') | ||
|
||
expect(response).to be_ok | ||
expect(request_span.get_tag('http.route')).to eq('/rack/hello/world') | ||
end | ||
|
||
def request_span | ||
spans.detect do |span| | ||
span.name == Datadog::Tracing::Contrib::Rack::Ext::SPAN_REQUEST | ||
end | ||
end | ||
end |