Skip to content

Commit

Permalink
[core] Tracer#set_tags accepts a hash instead of a single key
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Palazzetti committed Mar 30, 2017
1 parent 5baa4db commit 5594367
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.configure(config)
Datadog::Ext::AppTypes::CACHE
)

datadog_config[:tracer].set_tag('env', datadog_config[:env])
datadog_config[:tracer].set_tags('env' => datadog_config[:env])

if defined?(::ActiveRecord)
begin
Expand Down
8 changes: 3 additions & 5 deletions lib/ddtrace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def set_service_info(service, app, app_type)
# appended to each span created by the tracer. Keys and values must be strings.
# A valid example is:
#
# tracer.set_tag('env', 'prod')
def set_tag(key, value)
@tags[key] = value.to_s
rescue StandardError => e
Datadog::Tracer.log.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
# tracer.set_tags('env' => 'prod', 'component' => 'core')
def set_tags(tags)
@tags.update(tags)
end

# Return a +span+ that will trace an operation called +name+. You could trace your code
Expand Down
8 changes: 5 additions & 3 deletions test/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ def test_set_service_info
assert_equal(tracer.services['rest-api'], 'app' => 'rails', 'app_type' => 'web')
end

def test_set_tag
def test_set_tags
tracer = get_test_tracer
tracer.set_tag('env', 'test')
tracer.set_tags('env' => 'test', 'component' => 'core')
assert_equal(tracer.tags['env'], 'test')
assert_equal(tracer.tags['component'], 'core')
end

def test_trace_global_tags
tracer = get_test_tracer
tracer.set_tag('env', 'test')
tracer.set_tags('env' => 'test', 'component' => 'core')
span = tracer.trace('something')
assert_equal(span.get_tag('env'), 'test')
assert_equal(span.get_tag('component'), 'core')
end

def test_disabled_tracer
Expand Down

0 comments on commit 5594367

Please sign in to comment.