Skip to content

Commit

Permalink
Merge pull request #183 from DataDog/pedro/update-provider
Browse files Browse the repository at this point in the history
Enable access to context provider
  • Loading branch information
p-lambert authored Aug 31, 2017
2 parents 165af46 + a2b8380 commit 5a85f94
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/ddtrace/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Writer
class Tracer
remove_method :writer
attr_accessor :writer
attr_reader :provider
end
module Workers
class AsyncTransport
Expand Down
8 changes: 8 additions & 0 deletions test/provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions test/tracer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5a85f94

Please sign in to comment.