Sha256: 3ccb65247e364c88f77ea494b6553bb898f5df92fc0a851361cd47727002a09f

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 KB

Contents

require "delegate"
require "flipper/instrumenters/noop"

module Flipper
  module Cloud
    class Instrumenter < SimpleDelegator
      def initialize(options = {})
        @brow = options.fetch(:brow)
        @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
        super @instrumenter
      end

      def instrument(name, payload = {}, &block)
        result = @instrumenter.instrument(name, payload, &block)
        push name, payload
        result
      end

      private

      def push(name, payload)
        return unless name == Flipper::Feature::InstrumentationName
        return unless :enabled? == payload[:operation]

        dimensions = {
          "feature" => payload[:feature_name].to_s,
          "result" => payload[:result].to_s,
        }
        if (thing = payload[:thing])
          dimensions["flipper_id"] = thing.value.to_s
        end

        event = {
          type: "enabled",
          dimensions: dimensions,
          measures: {},
          ts: Time.now.utc,
        }
        @brow.push event
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
flipper-cloud-0.27.1 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.27.0 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.26.2 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.26.1 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.26.0 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.26.0.rc2 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.26.0.rc1 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.25.4 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.25.3 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.25.2 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.25.1 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.25.0 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.24.1 lib/flipper/cloud/instrumenter.rb
flipper-cloud-0.24.0 lib/flipper/cloud/instrumenter.rb