Skip to content

Commit ab5b14f

Browse files
authored
feat: Inline context for custom and migration op events (#315)
1 parent b6590ed commit ab5b14f

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

contract-tests/service.rb

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def make_output_events(events, summary)
508508
out = {
509509
kind: MIGRATION_OP_KIND,
510510
creationDate: event.timestamp,
511-
contextKeys: event.context.keys,
511+
context: @context_filter.filter_redact_anonymous(event.context),
512512
operation: event.operation.to_s,
513513
evaluation: {
514514
key: event.key,
@@ -577,7 +577,7 @@ def make_output_events(events, summary)
577577
key: event.key,
578578
}
579579
out[:data] = event.data unless event.data.nil?
580-
out[:contextKeys] = event.context.keys
580+
out[:context] = @context_filter.filter_redact_anonymous(event.context)
581581
out[:metricValue] = event.metric_value unless event.metric_value.nil?
582582
out
583583

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

+6-6
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

+15-7
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ module LaunchDarkly
391391
output = flush_and_get_events(ep, sender)
392392
expect(output).to contain_exactly(
393393
eq(index_event(default_config, context)),
394-
eq(custom_event(context, 'eventkey', { thing: 'stuff' }, 1.5))
394+
eq(custom_event(default_config, context, 'eventkey', { thing: 'stuff' }, 1.5))
395395
)
396396
end
397397
end
@@ -404,7 +404,7 @@ module LaunchDarkly
404404
output = flush_and_get_events(ep, sender)
405405
expect(output).to contain_exactly(
406406
eq(index_event(config, context)),
407-
eq(custom_event(context, 'eventkey', nil, nil))
407+
eq(custom_event(config, context, 'eventkey', nil, nil))
408408
)
409409
end
410410
end
@@ -476,7 +476,7 @@ module LaunchDarkly
476476

477477
output = flush_and_get_events(ep, sender)
478478
expect(output).to contain_exactly(
479-
eq(migration_op_event(flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
479+
eq(migration_op_event(default_config, flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
480480
)
481481
end
482482
end
@@ -786,6 +786,7 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
786786
end
787787

788788
#
789+
# @param config [Config]
789790
# @param flag [LaunchDarkly::Impl::Models::FeatureFlag]
790791
# @param context [LDContext]
791792
# @param variation [Integer]
@@ -795,12 +796,15 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
795796
# @param timestamp [Integer]
796797
# @return [Hash]
797798
#
798-
def migration_op_event(flag, context, variation, value, default, reason, timestamp = starting_timestamp)
799+
def migration_op_event(config, flag, context, variation, value, default, reason, timestamp = starting_timestamp)
800+
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
801+
redacted_context = context_filter.filter_redact_anonymous(context)
802+
799803
out = {
800804
kind: 'migration_op',
801805
operation: 'read',
802806
creationDate: timestamp,
803-
contextKeys: context.keys,
807+
context: redacted_context,
804808
evaluation: {
805809
default: default.to_s,
806810
key: flag.key,
@@ -836,17 +840,21 @@ def debug_event(config, flag, context, variation, value, timestamp = starting_ti
836840
end
837841

838842
#
843+
# @param config [Config]
839844
# @param context [LDContext]
840845
# @param key [String]
841846
# @param data [any]
842847
# @param metric_value [any]
843848
# @return [Hash]
844849
#
845-
def custom_event(context, key, data, metric_value)
850+
def custom_event(config, context, key, data, metric_value)
851+
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
852+
redacted_context = context_filter.filter_redact_anonymous(context)
853+
846854
out = {
847855
kind: "custom",
848856
creationDate: starting_timestamp,
849-
contextKeys: context.keys,
857+
context: redacted_context,
850858
key: key,
851859
}
852860
out[:data] = data unless data.nil?

0 commit comments

Comments
 (0)