Skip to content

Commit 36d4c44

Browse files
committed
feat: Inline context for custom and migration op events
1 parent 39b1e0e commit 36d4c44

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

contract-tests/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'event-sampling',
4141
'context-comparison',
4242
'polling-gzip',
43-
'inline-context',
43+
'inline-context-all',
4444
'anonymous-redaction',
4545
'evaluation-hooks',
4646
'omit-anonymous-contexts',

lib/ldclient-rb/events.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def dispatch_event(event, outbox)
337337

338338
return if notice_context(context)
339339
return if event.is_a?(LaunchDarkly::Impl::IdentifyEvent)
340+
return if event.is_a?(LaunchDarkly::Impl::CustomEvent)
340341
return if event.is_a?(LaunchDarkly::Impl::MigrationOpEvent)
341342

342343
yield context unless block.nil?
@@ -508,7 +509,7 @@ def make_output_events(events, summary)
508509
out = {
509510
kind: MIGRATION_OP_KIND,
510511
creationDate: event.timestamp,
511-
contextKeys: event.context.keys,
512+
context: @context_filter.filter_redact_anonymous(event.context),
512513
operation: event.operation.to_s,
513514
evaluation: {
514515
key: event.key,
@@ -577,7 +578,7 @@ def make_output_events(events, summary)
577578
key: event.key,
578579
}
579580
out[:data] = event.data unless event.data.nil?
580-
out[:contextKeys] = event.context.keys
581+
out[:context] = @context_filter.filter_redact_anonymous(event.context)
581582
out[:metricValue] = event.metric_value unless event.metric_value.nil?
582583
out
583584

lib/ldclient-rb/impl/migrations/tracker.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class OpTracker
99
include LaunchDarkly::Interfaces::Migrations::OpTracker
1010

1111
#
12-
# @param logger [Logger] logger
13-
# @param key [string] key
14-
# @param flag [LaunchDarkly::Impl::Model::FeatureFlag] flag
15-
# @param context [LaunchDarkly::LDContext] context
16-
# @param detail [LaunchDarkly::EvaluationDetail] detail
17-
# @param default_stage [Symbol] default_stage
12+
# @param logger [Logger]
13+
# @param key [string]
14+
# @param flag [LaunchDarkly::Impl::Model::FeatureFlag]
15+
# @param context [LaunchDarkly::LDContext]
16+
# @param detail [LaunchDarkly::EvaluationDetail]
17+
# @param default_stage [Symbol]
1818
#
1919
def initialize(logger, key, flag, context, detail, default_stage)
2020
@logger = logger

spec/events_spec.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ module LaunchDarkly
390390

391391
output = flush_and_get_events(ep, sender)
392392
expect(output).to contain_exactly(
393-
eq(index_event(default_config, context)),
394-
eq(custom_event(context, 'eventkey', { thing: 'stuff' }, 1.5))
393+
eq(custom_event(default_config, context, 'eventkey', { thing: 'stuff' }, 1.5))
395394
)
396395
end
397396
end
@@ -403,8 +402,7 @@ module LaunchDarkly
403402

404403
output = flush_and_get_events(ep, sender)
405404
expect(output).to contain_exactly(
406-
eq(index_event(config, context)),
407-
eq(custom_event(context, 'eventkey', nil, nil))
405+
eq(custom_event(config, context, 'eventkey', nil, nil))
408406
)
409407
end
410408
end
@@ -476,7 +474,7 @@ module LaunchDarkly
476474

477475
output = flush_and_get_events(ep, sender)
478476
expect(output).to contain_exactly(
479-
eq(migration_op_event(flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
477+
eq(migration_op_event(default_config, flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
480478
)
481479
end
482480
end
@@ -786,6 +784,7 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
786784
end
787785

788786
#
787+
# @param config [Config]
789788
# @param flag [LaunchDarkly::Impl::Models::FeatureFlag]
790789
# @param context [LDContext]
791790
# @param variation [Integer]
@@ -795,12 +794,15 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
795794
# @param timestamp [Integer]
796795
# @return [Hash]
797796
#
798-
def migration_op_event(flag, context, variation, value, default, reason, timestamp = starting_timestamp)
797+
def migration_op_event(config, flag, context, variation, value, default, reason, timestamp = starting_timestamp)
798+
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
799+
redacted_context = context_filter.filter_redact_anonymous(context)
800+
799801
out = {
800802
kind: 'migration_op',
801803
operation: 'read',
802804
creationDate: timestamp,
803-
contextKeys: context.keys,
805+
context: redacted_context,
804806
evaluation: {
805807
default: default.to_s,
806808
key: flag.key,
@@ -836,17 +838,21 @@ def debug_event(config, flag, context, variation, value, timestamp = starting_ti
836838
end
837839

838840
#
841+
# @param config [Config]
839842
# @param context [LDContext]
840843
# @param key [String]
841844
# @param data [any]
842845
# @param metric_value [any]
843846
# @return [Hash]
844847
#
845-
def custom_event(context, key, data, metric_value)
848+
def custom_event(config, context, key, data, metric_value)
849+
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
850+
redacted_context = context_filter.filter_redact_anonymous(context)
851+
846852
out = {
847853
kind: "custom",
848854
creationDate: starting_timestamp,
849-
contextKeys: context.keys,
855+
context: redacted_context,
850856
key: key,
851857
}
852858
out[:data] = data unless data.nil?

0 commit comments

Comments
 (0)