Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sinatra] change the name with service_name instead of default_service #260

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


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