diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 6d0738d49a3..91f2d6ec615 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -142,7 +142,7 @@ either ``sinatra`` or ``sinatra/base``: require 'ddtrace/contrib/sinatra/tracer' Datadog.configure do |c| - c.use :sinatra, default_service: 'my-app' + c.use :sinatra, service_name: 'my-app' end get '/' do @@ -157,7 +157,7 @@ Available settings are: * ``enabled``: define if the ``tracer`` is enabled or not. If set to ``false``, the code is still instrumented but no spans are sent to the local trace agent. -* ``default_service``: set the service name used when tracing application requests. Defaults to ``sinatra`` +* ``service_name``: set the service name used when tracing application requests. Defaults to ``sinatra`` * ``tracer``: set the tracer to use. Usually you don't need to change that value unless you're already using a different initialized tracer somewhere else * ``debug``: set to ``true`` to enable debug logging. diff --git a/lib/ddtrace/contrib/sinatra/tracer.rb b/lib/ddtrace/contrib/sinatra/tracer.rb index 4c6175c3c26..c8c36c1250a 100644 --- a/lib/ddtrace/contrib/sinatra/tracer.rb +++ b/lib/ddtrace/contrib/sinatra/tracer.rb @@ -27,7 +27,7 @@ module Tracer get_option(:tracer).enabled = value end - option :default_service, default: 'sinatra', depends_on: [:tracer] do |value| + option :service_name, default: 'sinatra', depends_on: [:tracer] do |value| get_option(:tracer).set_service_info(value, 'sinatra', Ext::AppTypes::WEB) value end @@ -90,7 +90,7 @@ def render(engine, data, *) tracer = Datadog.configuration[:sinatra][:tracer] span = tracer.trace('sinatra.request', - service: Datadog.configuration[:sinatra][:default_service], + service: Datadog.configuration[:sinatra][:service_name], span_type: Datadog::Ext::HTTP::TYPE) span.set_tag(Datadog::Ext::HTTP::URL, request.path) span.set_tag(Datadog::Ext::HTTP::METHOD, request.request_method) diff --git a/test/contrib/sinatra/tracer_test.rb b/test/contrib/sinatra/tracer_test.rb index 4d81b665500..f6534477dac 100644 --- a/test/contrib/sinatra/tracer_test.rb +++ b/test/contrib/sinatra/tracer_test.rb @@ -1,5 +1,6 @@ require 'contrib/sinatra/tracer_test_base' +# rubocop:disable Metrics/ClassLength class TracerTest < TracerTestBase class TracerTestApp < Sinatra::Application get '/request' do @@ -45,6 +46,22 @@ def setup super end + def test_service_name + previous_name = Datadog.configuration[:sinatra][:service_name] + Datadog.configuration.use(:sinatra, service_name: 'my-sinatra-app') + + get '/request' + assert_equal(200, last_response.status) + + spans = @writer.spans() + assert_equal(1, spans.length) + + span = spans[0] + assert_equal('my-sinatra-app', span.service) + ensure + Datadog.configuration.use(:sinatra, service_name: previous_name) + end + def test_request get '/request#foo?a=1' assert_equal(200, last_response.status)