Sha256: f60784d54c8484471de48638b2f03c8d848ba75fd7691fb70c9d376287f581b8

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'concurrent/executor/executor_service'
require 'forwardable'

module OpenTelemetry
  module Instrumentation
    module ConcurrentRuby
      # Wraps existing executor to carry over trace context
      class ContextCompositeExecutorService
        extend Forwardable
        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)
          context = OpenTelemetry::Context.current

          @composited_executor.post(*args) do
            OpenTelemetry::Context.with_current(context) do
              yield
            end
          end
        end

        delegate %i[can_overflow? serialized?] => :composited_executor
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-concurrent_ruby-0.18.2 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.18.1 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.18.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.17.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.16.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.15.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.14.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.13.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.12.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-instrumentation-concurrent_ruby-0.11.0 lib/opentelemetry/instrumentation/concurrent_ruby/context_composite_executor_service.rb