Sha256: cdf019f148ae80abc4adc67ae16c518d08f73f3370fac6b380d2f270cd0f3273

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# typed: ignore

require_relative 'engine'

module Datadog
  module AppSec
    module Reactive
      # Reactive Engine nested operation tracking
      class Operation
        attr_reader :reactive,
          :parent,
          :name

        def initialize(name, parent = nil, reactive_engine = nil)
          Datadog.logger.debug { "operation: #{name} initialize" }
          @name = name
          @parent = parent
          @reactive = reactive_engine || (parent.reactive unless parent.nil?) || Reactive::Engine.new

          # TODO: concurrent store
          # TODO: constant
          Thread.current[:datadog_security_active_operation] = self

          yield self if block_given?
        ensure
          finalize
        end

        # TODO: use structs instead of an arg splat
        def subscribe(*addresses, &block)
          reactive.subscribe(*addresses, &block)
        end

        def publish(address, data)
          reactive.publish(address, data)
        end

        def finalize
          Datadog.logger.debug { "operation: #{name} finalize" }
          Thread.current[:datadog_security_active_operation] = parent
        end

        class << self
          def active
            Thread.current[:datadog_security_active_operation]
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/datadog/appsec/reactive/operation.rb