Class: Datadog::Contrib::ConcurrentRuby::ContextCompositeExecutorService

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Concurrent::ExecutorService
Defined in:
lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb

Overview

wraps existing executor to carry over trace context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(composited_executor) ⇒ ContextCompositeExecutorService

Returns a new instance of ContextCompositeExecutorService.



14
15
16
# File 'lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb', line 14

def initialize(composited_executor)
  @composited_executor = composited_executor
end

Instance Attribute Details

#composited_executorObject

Returns the value of attribute composited_executor.



12
13
14
# File 'lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb', line 12

def composited_executor
  @composited_executor
end

Instance Method Details

#datadog_configurationObject



34
35
36
# File 'lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb', line 34

def datadog_configuration
  Datadog.configuration[:concurrent_ruby]
end

#post(*args, &task) ⇒ Object

post method runs the task within composited executor - in a different thread



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb', line 19

def post(*args, &task)
  parent_context = datadog_configuration.tracer.provider.context

  @composited_executor.post(*args) do
    begin
      original_context = datadog_configuration.tracer.provider.context
      datadog_configuration.tracer.provider.context = parent_context
      yield
    ensure
      # Restore context in case the current thread gets reused
      datadog_configuration.tracer.provider.context = original_context
    end
  end
end