lib/ldclient-rb/events.rb in launchdarkly-server-sdk-7.3.3 vs lib/ldclient-rb/events.rb in launchdarkly-server-sdk-8.0.0
- old
+ new
@@ -38,11 +38,13 @@
value = nil,
reason = nil,
default = nil,
track_events = false,
debug_until = nil,
- prereq_of = nil
+ prereq_of = nil,
+ sampling_ratio = nil,
+ exclude_from_summaries = false
)
end
def record_identify_event(context)
end
@@ -53,10 +55,13 @@
data = nil,
metric_value = nil
)
end
+ def record_migration_op_event(event)
+ end
+
def flush
end
def stop
end
@@ -151,24 +156,30 @@
value = nil,
reason = nil,
default = nil,
track_events = false,
debug_until = nil,
- prereq_of = nil
+ prereq_of = nil,
+ sampling_ratio = nil,
+ exclude_from_summaries = false
)
post_to_inbox(LaunchDarkly::Impl::EvalEvent.new(timestamp, context, key, version, variation, value, reason,
- default, track_events, debug_until, prereq_of))
+ default, track_events, debug_until, prereq_of, sampling_ratio, exclude_from_summaries))
end
def record_identify_event(context)
post_to_inbox(LaunchDarkly::Impl::IdentifyEvent.new(timestamp, context))
end
def record_custom_event(context, key, data = nil, metric_value = nil)
post_to_inbox(LaunchDarkly::Impl::CustomEvent.new(timestamp, context, key, data, metric_value))
end
+ def record_migration_op_event(event)
+ post_to_inbox(event)
+ end
+
def flush
# flush is done asynchronously
post_to_inbox(FlushMessage.new)
end
@@ -218,10 +229,11 @@
def initialize(inbox, sdk_key, config, diagnostic_accumulator, event_sender)
@sdk_key = sdk_key
@config = config
@diagnostic_accumulator = config.diagnostic_opt_out? ? nil : diagnostic_accumulator
@event_sender = event_sender
+ @sampler = LaunchDarkly::Impl::Sampler.new(Random.new)
@context_keys = SimpleLRUCacheSet.new(config.context_keys_capacity)
@formatter = EventOutputFormatter.new(config)
@disabled = Concurrent::AtomicBoolean.new(false)
@last_known_past_time = Concurrent::AtomicReference.new(0)
@@ -290,11 +302,11 @@
def dispatch_event(event, outbox)
return if @disabled.value
# Always record the event in the summary.
- outbox.add_to_summary(event)
+ outbox.add_to_summary(event) unless event.exclude_from_summaries
# Decide whether to add the event to the payload. Feature events may be added twice, once for
# the event (if tracked) and once for debugging.
will_add_full_event = false
debug_event = nil
@@ -307,16 +319,16 @@
will_add_full_event = true
end
# For each context we haven't seen before, we add an index event - unless this is already
# an identify event for that context.
- if !event.context.nil? && !notice_context(event.context) && !event.is_a?(LaunchDarkly::Impl::IdentifyEvent)
+ if !event.context.nil? && !notice_context(event.context) && !event.is_a?(LaunchDarkly::Impl::IdentifyEvent) && !event.is_a?(LaunchDarkly::Impl::MigrationOpEvent)
outbox.add_event(LaunchDarkly::Impl::IndexEvent.new(event.timestamp, event.context))
end
- outbox.add_event(event) if will_add_full_event
- outbox.add_event(debug_event) unless debug_event.nil?
+ outbox.add_event(event) if will_add_full_event && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
+ outbox.add_event(debug_event) if !debug_event.nil? && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
end
#
# Add to the set of contexts we've noticed, and return true if the context
# was already known to us.
@@ -441,10 +453,11 @@
FEATURE_KIND = 'feature'
IDENTIFY_KIND = 'identify'
CUSTOM_KIND = 'custom'
INDEX_KIND = 'index'
DEBUG_KIND = 'debug'
+ MIGRATION_OP_KIND = 'migration_op'
SUMMARY_KIND = 'summary'
def initialize(config)
@context_filter = LaunchDarkly::Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
end
@@ -472,9 +485,67 @@
out[:variation] = event.variation unless event.variation.nil?
out[:version] = event.version unless event.version.nil?
out[:prereqOf] = event.prereq_of unless event.prereq_of.nil?
out[:contextKeys] = event.context.keys
out[:reason] = event.reason unless event.reason.nil?
+ out
+
+ when LaunchDarkly::Impl::MigrationOpEvent
+ out = {
+ kind: MIGRATION_OP_KIND,
+ creationDate: event.timestamp,
+ contextKeys: event.context.keys,
+ operation: event.operation.to_s,
+ evaluation: {
+ key: event.key,
+ value: event.evaluation.value,
+ },
+ }
+
+ out[:evaluation][:version] = event.version unless event.version.nil?
+ out[:evaluation][:default] = event.default unless event.default.nil?
+ out[:evaluation][:variation] = event.evaluation.variation_index unless event.evaluation.variation_index.nil?
+ out[:evaluation][:reason] = event.evaluation.reason unless event.evaluation.reason.nil?
+ out[:samplingRatio] = event.sampling_ratio unless event.sampling_ratio.nil? || event.sampling_ratio == 1
+
+ measurements = []
+
+ unless event.invoked.empty?
+ measurements << {
+ "key": "invoked",
+ "values": event.invoked.map { |origin| [origin, true] }.to_h,
+ }
+ end
+
+ unless event.consistency_check.nil?
+ measurement = {
+ "key": "consistent",
+ "value": event.consistency_check,
+ }
+
+ unless event.consistency_check_ratio.nil? || event.consistency_check_ratio == 1
+ measurement[:samplingRatio] = event.consistency_check_ratio
+ end
+
+ measurements << measurement
+ end
+
+
+ unless event.latencies.empty?
+ measurements << {
+ "key": "latency_ms",
+ "values": event.latencies,
+ }
+ end
+
+ unless event.errors.empty?
+ measurements << {
+ "key": "error",
+ "values": event.errors.map { |origin| [origin, true] }.to_h,
+ }
+ end
+ out[:measurements] = measurements unless measurements.empty?
+
out
when LaunchDarkly::Impl::IdentifyEvent
{
kind: IDENTIFY_KIND,