Class: Datadog::OpenFeature::Exposures::Reporter
- Inherits:
-
Object
- Object
- Datadog::OpenFeature::Exposures::Reporter
- Defined in:
- lib/datadog/open_feature/exposures/reporter.rb
Overview
Owns the exposure cache and sends new or changed exposures to the Agent
Instance Method Summary collapse
-
#initialize(worker, logger:, datadog_logging_enabled: true) ⇒ Reporter
constructor
A new instance of Reporter.
-
#record(flag_key:, allocation_key:, variant:, serial_id:, context:, features:) ⇒ Boolean
Records the exposure in the cache and, when it is new or changed, sends it to Datadog.
Constructor Details
#initialize(worker, logger:, datadog_logging_enabled: true) ⇒ Reporter
Returns a new instance of Reporter.
11 12 13 14 15 16 |
# File 'lib/datadog/open_feature/exposures/reporter.rb', line 11 def initialize(worker, logger:, datadog_logging_enabled: true) @worker = worker @logger = logger @datadog_logging_enabled = datadog_logging_enabled @deduplicator = Deduplicator.new end |
Instance Method Details
#record(flag_key:, allocation_key:, variant:, serial_id:, context:, features:) ⇒ Boolean
Records the exposure in the cache and, when it is new or changed, sends it to Datadog. The cache records even when Datadog logging is off, so the verdict does not depend on it.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/datadog/open_feature/exposures/reporter.rb', line 22 def record(flag_key:, allocation_key:, variant:, serial_id:, context:, features:) key = Event.cache_key(flag_key: flag_key, targeting_key: context.targeting_key) value = Event.cache_value(allocation_key: allocation_key, variant: variant, serial_id: serial_id) if @deduplicator.duplicate?(key, value) skip(flag_key, "duplicate of the last exposure for this subject") return true end unless @datadog_logging_enabled skip(flag_key, "Datadog exposure logging is disabled") return false end enqueue( Event.build( flag_key: flag_key, allocation_key: allocation_key, variant: variant, serial_id: serial_id, context: context, features: features, ), ) false end |