Skip to content

Commit

Permalink
Added: Custom Rails controller resource test.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Jan 19, 2018
1 parent 9721c7d commit 0fe453a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test/contrib/rails/apps/controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def full
@value = Rails.cache.write('empty-key', 50)
render 'views/tracing/full.html.erb'
end

def custom_resource
tracer = Datadog.configuration[:rails][:tracer]
tracer.active_span.resource = 'custom-resource'
head :ok
end
end

routes = {
Expand All @@ -102,7 +108,8 @@ def full
'/error_template' => 'tracing#error_template',
'/error_partial' => 'tracing#error_partial',
'/missing_template' => 'tracing#missing_template',
'/missing_partial' => 'tracing#missing_partial'
'/missing_partial' => 'tracing#missing_partial',
'/custom_resource' => 'tracing#custom_resource'
}

if Rails.version >= '3.2.22.5'
Expand Down
11 changes: 11 additions & 0 deletions test/contrib/rails/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ class TracingControllerTest < ActionController::TestCase
assert_nil(span.get_tag('error.stack'), 'no error stack')
end

test 'custom resource names can be set' do
get :custom_resource
assert_response :success
spans = @tracer.writer.spans
assert_equal(spans.length, 1)

spans.first.tap do |span|
assert_equal('custom-resource', span.resource)
end
end

test 'combining rails and custom tracing is supported' do
@tracer.trace('a-parent') do
get :index
Expand Down

0 comments on commit 0fe453a

Please sign in to comment.