Sha256: 71ca22aeef5d245447a99bcb77ef5cbb1addc46b6ffac209a6e3b297995fef86

Contents?: true

Size: 1022 Bytes

Versions: 2

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

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

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

module OpenTelemetry
  module Adapters
    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

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-adapters-concurrent_ruby-0.4.0 lib/opentelemetry/adapters/concurrent_ruby/context_composite_executor_service.rb
opentelemetry-adapters-concurrent_ruby-0.3.0 lib/opentelemetry/adapters/concurrent_ruby/context_composite_executor_service.rb