Sha256: 43d608f849b653fcce6788a91046bbe9d76046bcdf1ccd3fb496a1adb6bfceb3
Contents?: true
Size: 1.46 KB
Versions: 37
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module Datadog module AppSec # Instrumentation for AppSec module Instrumentation # Instrumentation gateway implementation class Gateway # Instrumentation gateway middleware class Middleware attr_reader :key, :block def initialize(key, &block) @key = key @block = block end def call(stack, env) @block.call(stack, env) end end private_constant :Middleware def initialize @middlewares = Hash.new { |h, k| h[k] = [] } end def push(name, env, &block) block ||= -> {} middlewares_for_name = middlewares[name] return [block.call, nil] if middlewares_for_name.empty? wrapped = lambda do |_env| [block.call, nil] end # TODO: handle exceptions, except for wrapped stack = middlewares_for_name.reverse.reduce(wrapped) do |next_, middleware| lambda do |env_| middleware.call(next_, env_) end end stack.call(env) end def watch(name, key, &block) @middlewares[name] << Middleware.new(key, &block) unless middlewares[name].any? { |m| m.key == key } end private attr_reader :middlewares end def self.gateway @gateway ||= Gateway.new # TODO: not thread safe end end end end
Version data entries
37 entries across 37 versions & 2 rubygems