From 5594367a5d46a3b539696c0a096d013f6c4d8867 Mon Sep 17 00:00:00 2001 From: Emanuele Palazzetti Date: Thu, 30 Mar 2017 12:44:44 +0200 Subject: [PATCH] [core] Tracer#set_tags accepts a hash instead of a single key --- lib/ddtrace/contrib/rails/framework.rb | 2 +- lib/ddtrace/tracer.rb | 8 +++----- test/tracer_test.rb | 8 +++++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ddtrace/contrib/rails/framework.rb b/lib/ddtrace/contrib/rails/framework.rb index 52bdc154624..1e510d577e3 100644 --- a/lib/ddtrace/contrib/rails/framework.rb +++ b/lib/ddtrace/contrib/rails/framework.rb @@ -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 diff --git a/lib/ddtrace/tracer.rb b/lib/ddtrace/tracer.rb index a52114bf5d7..2767fee70f6 100644 --- a/lib/ddtrace/tracer.rb +++ b/lib/ddtrace/tracer.rb @@ -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 diff --git a/test/tracer_test.rb b/test/tracer_test.rb index 3827e072244..b8f8753a67a 100644 --- a/test/tracer_test.rb +++ b/test/tracer_test.rb @@ -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