From a826c31941b0fb2939e8d681a71e267b5921a74d Mon Sep 17 00:00:00 2001 From: Pedro Lambert Date: Wed, 30 Aug 2017 15:26:54 -0400 Subject: [PATCH 1/2] Add context setter to `DefaultContextProvider` --- lib/ddtrace/provider.rb | 5 +++++ test/provider_test.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/ddtrace/provider.rb b/lib/ddtrace/provider.rb index eec539012ec..4187deca1be 100644 --- a/lib/ddtrace/provider.rb +++ b/lib/ddtrace/provider.rb @@ -8,6 +8,11 @@ def initialize @context = Datadog::ThreadLocalContext.new end + # Sets the current context. + def context=(ctx) + @context.local = ctx + end + # Return the current context. def context @context.local diff --git a/test/provider_test.rb b/test/provider_test.rb index ea1c19b6bb2..11de538c0c1 100644 --- a/test/provider_test.rb +++ b/test/provider_test.rb @@ -19,4 +19,12 @@ def test_default_provider assert_equal(ctx, ctx2) end + + def test_setting_a_context + provider = Datadog::DefaultContextProvider.new + custom_context = Datadog::Context.new + provider.context = custom_context + + assert_same(provider.context, custom_context) + end end From a2b838004e6dba1025fcf02769cad998c5b0fc2a Mon Sep 17 00:00:00 2001 From: Pedro Lambert Date: Thu, 31 Aug 2017 13:31:04 -0400 Subject: [PATCH 2/2] Enable access to provider --- lib/ddtrace/tracer.rb | 2 +- test/helper.rb | 1 - test/tracer_test.rb | 6 ++++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ddtrace/tracer.rb b/lib/ddtrace/tracer.rb index fd2f6df623e..5908e0020ba 100644 --- a/lib/ddtrace/tracer.rb +++ b/lib/ddtrace/tracer.rb @@ -18,7 +18,7 @@ module Datadog # of these function calls and sub-requests would be encapsulated within a single trace. # rubocop:disable Metrics/ClassLength class Tracer - attr_reader :writer, :sampler, :services, :tags + attr_reader :writer, :sampler, :services, :tags, :provider attr_accessor :enabled attr_writer :default_service diff --git a/test/helper.rb b/test/helper.rb index b57bc190036..46f12a455e7 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -14,7 +14,6 @@ class Writer class Tracer remove_method :writer attr_accessor :writer - attr_reader :provider end module Workers class AsyncTransport diff --git a/test/tracer_test.rb b/test/tracer_test.rb index f412ccb143e..a67c758f60b 100644 --- a/test/tracer_test.rb +++ b/test/tracer_test.rb @@ -356,4 +356,10 @@ def test_child_span_has_no_pid_metadata child = tracer.trace('something_else') assert_nil(child.get_tag('system.pid')) end + + def test_provider + provider = Datadog::DefaultContextProvider.new + tracer = Datadog::Tracer.new(context_provider: provider) + assert_same(provider, tracer.provider) + end end