Skip to content

Commit

Permalink
[sinatra] change the name with service_name instead of default_service (
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Palazzetti authored Nov 30, 2017
1 parent ccf3332 commit 043a193
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/sinatra/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions test/contrib/sinatra/tracer_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'contrib/sinatra/tracer_test_base'

# rubocop:disable Metrics/ClassLength
class TracerTest < TracerTestBase
class TracerTestApp < Sinatra::Application
get '/request' do
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 043a193

Please sign in to comment.