|
4 | 4 | require 'datadog/tracing/contrib/action_pack/action_dispatch/instrumentation'
|
5 | 5 |
|
6 | 6 | RSpec.describe Datadog::Tracing::Contrib::ActionPack::ActionDispatch::Instrumentation do
|
7 |
| - describe '::set_http_route_tags' do |
8 |
| - let(:tracing_enabled) { true } |
9 |
| - |
10 |
| - before do |
11 |
| - expect(Datadog::Tracing).to receive(:enabled?).and_return(tracing_enabled) |
12 |
| - end |
13 |
| - |
| 7 | + describe '.set_http_route_tags' do |
14 | 8 | context 'when tracing is disabled' do
|
15 |
| - let(:tracing_enabled) { false } |
| 9 | + before { expect(Datadog::Tracing).to receive(:enabled?).and_return(false) } |
16 | 10 |
|
17 | 11 | it 'sets no tags' do
|
18 | 12 | Datadog::Tracing.trace('rack.request') do |_span, trace|
|
|
24 | 18 | end
|
25 | 19 | end
|
26 | 20 |
|
27 |
| - it 'sets http.route and http.route.path tags on existing trace' do |
28 |
| - Datadog::Tracing.trace('rack.request') do |_span, trace| |
29 |
| - described_class.set_http_route_tags('/users/:id(.:format)', '/auth') |
| 21 | + context 'when tracing is enabled' do |
| 22 | + before { expect(Datadog::Tracing).to receive(:enabled?).and_return(true) } |
30 | 23 |
|
31 |
| - expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id') |
32 |
| - expect(trace.send(:meta).fetch('http.route.path')).to eq('/auth') |
| 24 | + it 'sets http.route and http.route.path tags on existing trace' do |
| 25 | + Datadog::Tracing.trace('rack.request') do |_span, trace| |
| 26 | + described_class.set_http_route_tags('/users/:id', '/auth') |
| 27 | + |
| 28 | + expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id') |
| 29 | + expect(trace.send(:meta).fetch('http.route.path')).to eq('/auth') |
| 30 | + end |
33 | 31 | end
|
34 |
| - end |
35 | 32 |
|
36 |
| - it 'sets no http.route.path when script name is nil' do |
37 |
| - Datadog::Tracing.trace('rack.request') do |_span, trace| |
38 |
| - described_class.set_http_route_tags('/users/:id(.:format)', nil) |
| 33 | + it 'sets no http.route.path when script name is nil' do |
| 34 | + Datadog::Tracing.trace('rack.request') do |_span, trace| |
| 35 | + described_class.set_http_route_tags('/users/:id', nil) |
39 | 36 |
|
40 |
| - expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id') |
41 |
| - expect(trace.send(:meta)).not_to have_key('http.route.path') |
| 37 | + expect(trace.send(:meta).fetch('http.route')).to eq('/users/:id') |
| 38 | + expect(trace.send(:meta)).not_to have_key('http.route.path') |
| 39 | + end |
42 | 40 | end
|
43 |
| - end |
44 | 41 |
|
45 |
| - it 'sets no tags when route spec is nil' do |
46 |
| - Datadog::Tracing.trace('rack.request') do |_span, trace| |
47 |
| - described_class.set_http_route_tags(nil, '/auth') |
| 42 | + it 'sets no tags when route spec is nil' do |
| 43 | + Datadog::Tracing.trace('rack.request') do |_span, trace| |
| 44 | + described_class.set_http_route_tags(nil, '/auth') |
48 | 45 |
|
49 |
| - expect(trace.send(:meta)).not_to have_key('http.route') |
50 |
| - expect(trace.send(:meta)).not_to have_key('http.route.path') |
| 46 | + expect(trace.send(:meta)).not_to have_key('http.route') |
| 47 | + expect(trace.send(:meta)).not_to have_key('http.route.path') |
| 48 | + end |
51 | 49 | end
|
52 |
| - end |
53 | 50 |
|
54 |
| - it 'does not create new traces when no active trace is present' do |
55 |
| - described_class.set_http_route_tags('/users/:id', '/auth') |
| 51 | + it 'does not create new traces when no active trace is present' do |
| 52 | + described_class.set_http_route_tags('/users/:id', '/auth') |
56 | 53 |
|
57 |
| - expect(traces).to be_empty |
| 54 | + expect(traces).to be_empty |
| 55 | + end |
58 | 56 | end
|
59 | 57 | end
|
60 | 58 | end
|
0 commit comments