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

Inherits:
Object
  • Object
show all
Includes:
Concurrent::ExecutorService
Defined in:
lib/datadog/tracing/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.



15
16
17
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 15

def initialize(composited_executor)
  @composited_executor = composited_executor
end

Instance Attribute Details

#composited_executorObject

Returns the value of attribute composited_executor.



13
14
15
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 13

def composited_executor
  @composited_executor
end

Instance Method Details

#can_overflow?Boolean

Respect the Concurrent::ExecutorService interface

Returns:

  • (Boolean)


37
38
39
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 37

def can_overflow?
  @composited_executor.can_overflow?
end

#datadog_configurationObject



46
47
48
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 46

def datadog_configuration
  Datadog.configuration.tracing[:concurrent_ruby]
end

#post(*args, &task) ⇒ Object

post method runs the task within composited executor - in a different thread. The original arguments are captured to be propagated to the composited executor post method



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 21

def post(*args, &task)
  digest = Tracing.active_trace && Tracing.active_trace.to_digest
  executor = @composited_executor.is_a?(Symbol) ? Concurrent.executor(@composited_executor) : @composited_executor

  # Pass the original arguments to the composited executor, which
  # pushes them (possibly transformed) as block args
  executor.post(*args) do |*block_args|
    Tracing.continue_trace!(digest)

    # Pass the executor-provided block args as they should have been
    # originally passed without composition, see ChainPromise#on_resolvable
    yield(*block_args)
  end
end

#serialized?Boolean

Respect the Concurrent::ExecutorService interface

Returns:

  • (Boolean)


42
43
44
# File 'lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb', line 42

def serialized?
  @composited_executor.serialized?
end