Sha256: da570b83bdd0f4a42fbf8667e1677d8ea3d466cefc4bef79e39ffc068ca9f341

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

require 'concurrent/executor/executor_service'

module Datadog
  module Tracing
    module Contrib
      module ConcurrentRuby
        # wraps existing executor to carry over trace context
        class ContextCompositeExecutorService
          include Concurrent::ExecutorService

          attr_accessor :composited_executor

          def initialize(composited_executor)
            @composited_executor = composited_executor
          end

          # post method runs the task within composited executor - in a different thread
          def post(*args, &task)
            tracer = Tracing.send(:tracer)
            parent_context = tracer.provider.context

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

          # Respect the {Concurrent::ExecutorService} interface
          def can_overflow?
            @composited_executor.can_overflow?
          end

          # Respect the {Concurrent::ExecutorService} interface
          def serialized?
            @composited_executor.serialized?
          end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ddtrace-1.15.0 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.14.0 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.13.1 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.13.0 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.12.1 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.12.0 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.11.1 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.11.0 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb
ddtrace-1.11.0.beta1 lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb