Skip to content

Commit

Permalink
feat: Redact anonymous attributes within feature events
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Jan 9, 2024
1 parent cb5a84f commit e9b0c8b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'event-sampling',
'context-comparison',
'inline-context',
'anonymous-redaction',
],
}.to_json
end
Expand Down
10 changes: 9 additions & 1 deletion lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ class EventOutputFormatter

def initialize(config)
@context_filter = LaunchDarkly::Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
@anonymous_context_filter = LaunchDarkly::Impl::ContextFilter.new(true, [])
end

# Transforms events into the format used for event sending.
Expand All @@ -481,12 +482,19 @@ def make_output_events(events, summary)
key: event.key,
value: event.value,
}

out[:context] = if event.context.get_value('anonymous')
@anonymous_context_filter.filter(event.context)
else
@context_filter.filter(event.context)
end

out[:default] = event.default unless event.default.nil?
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[:context] = @context_filter.filter(event.context)
out[:reason] = event.reason unless event.reason.nil?

out

when LaunchDarkly::Impl::MigrationOpEvent
Expand Down
6 changes: 5 additions & 1 deletion spec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,14 @@ def identify_event(config, context, timestamp = starting_timestamp)
#
def feature_event(config, flag, context, variation, value, timestamp = starting_timestamp)
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
anonymous_filter = Impl::ContextFilter.new(true, [])

redacted_context = context.get_value('anonymous') ? anonymous_filter.filter(context) : context_filter.filter(context)

out = {
kind: 'feature',
creationDate: timestamp,
context: context_filter.filter(context),
context: redacted_context,
key: flag[:key],
variation: variation,
version: flag[:version],
Expand Down

0 comments on commit e9b0c8b

Please sign in to comment.