Skip to content

feat: Inline context for custom and migration op events #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contract-tests/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'event-sampling',
'context-comparison',
'polling-gzip',
'inline-context',
'inline-context-all',
'anonymous-redaction',
'evaluation-hooks',
'omit-anonymous-contexts',
Expand Down
4 changes: 2 additions & 2 deletions lib/ldclient-rb/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def make_output_events(events, summary)
out = {
kind: MIGRATION_OP_KIND,
creationDate: event.timestamp,
contextKeys: event.context.keys,
context: @context_filter.filter_redact_anonymous(event.context),
operation: event.operation.to_s,
evaluation: {
key: event.key,
Expand Down Expand Up @@ -577,7 +577,7 @@ def make_output_events(events, summary)
key: event.key,
}
out[:data] = event.data unless event.data.nil?
out[:contextKeys] = event.context.keys
out[:context] = @context_filter.filter_redact_anonymous(event.context)
out[:metricValue] = event.metric_value unless event.metric_value.nil?
out

Expand Down
12 changes: 6 additions & 6 deletions lib/ldclient-rb/impl/migrations/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class OpTracker
include LaunchDarkly::Interfaces::Migrations::OpTracker

#
# @param logger [Logger] logger
# @param key [string] key
# @param flag [LaunchDarkly::Impl::Model::FeatureFlag] flag
# @param context [LaunchDarkly::LDContext] context
# @param detail [LaunchDarkly::EvaluationDetail] detail
# @param default_stage [Symbol] default_stage
# @param logger [Logger]
# @param key [string]
# @param flag [LaunchDarkly::Impl::Model::FeatureFlag]
# @param context [LaunchDarkly::LDContext]
# @param detail [LaunchDarkly::EvaluationDetail]
# @param default_stage [Symbol]
#
def initialize(logger, key, flag, context, detail, default_stage)
@logger = logger
Expand Down
22 changes: 15 additions & 7 deletions spec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(default_config, context)),
eq(custom_event(context, 'eventkey', { thing: 'stuff' }, 1.5))
eq(custom_event(default_config, context, 'eventkey', { thing: 'stuff' }, 1.5))
)
end
end
Expand All @@ -404,7 +404,7 @@ module LaunchDarkly
output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(index_event(config, context)),
eq(custom_event(context, 'eventkey', nil, nil))
eq(custom_event(config, context, 'eventkey', nil, nil))
)
end
end
Expand Down Expand Up @@ -476,7 +476,7 @@ module LaunchDarkly

output = flush_and_get_events(ep, sender)
expect(output).to contain_exactly(
eq(migration_op_event(flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
eq(migration_op_event(default_config, flag, context, 0, true, LaunchDarkly::Migrations::STAGE_OFF, reason, starting_timestamp+1))
)
end
end
Expand Down Expand Up @@ -786,6 +786,7 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
end

#
# @param config [Config]
# @param flag [LaunchDarkly::Impl::Models::FeatureFlag]
# @param context [LDContext]
# @param variation [Integer]
Expand All @@ -795,12 +796,15 @@ def feature_event(config, flag, context, variation, value, timestamp = starting_
# @param timestamp [Integer]
# @return [Hash]
#
def migration_op_event(flag, context, variation, value, default, reason, timestamp = starting_timestamp)
def migration_op_event(config, flag, context, variation, value, default, reason, timestamp = starting_timestamp)
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
redacted_context = context_filter.filter_redact_anonymous(context)

out = {
kind: 'migration_op',
operation: 'read',
creationDate: timestamp,
contextKeys: context.keys,
context: redacted_context,
evaluation: {
default: default.to_s,
key: flag.key,
Expand Down Expand Up @@ -836,17 +840,21 @@ def debug_event(config, flag, context, variation, value, timestamp = starting_ti
end

#
# @param config [Config]
# @param context [LDContext]
# @param key [String]
# @param data [any]
# @param metric_value [any]
# @return [Hash]
#
def custom_event(context, key, data, metric_value)
def custom_event(config, context, key, data, metric_value)
context_filter = Impl::ContextFilter.new(config.all_attributes_private, config.private_attributes)
redacted_context = context_filter.filter_redact_anonymous(context)

out = {
kind: "custom",
creationDate: starting_timestamp,
contextKeys: context.keys,
context: redacted_context,
key: key,
}
out[:data] = data unless data.nil?
Expand Down