Skip to content

Commit 89e7584

Browse files
prepare 6.1.0 release (#172)
1 parent 39a5fbd commit 89e7584

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-3
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
launchdarkly-server-sdk (5.8.2)
4+
launchdarkly-server-sdk (6.0.0)
55
concurrent-ruby (~> 1.1)
66
http (~> 4.4.1)
77
json (~> 2.3.1)

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ About LaunchDarkly
5555
* [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
5656
* [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
5757
* [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
58-
* [Feature Flagging Guide](https://github.com/launchdarkly/featureflags/ "Feature Flagging Guide") for best practices and strategies

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
workingDirectory: $(System.DefaultWorkingDirectory)
4646
script: |
4747
ruby -v
48-
gem install bundler
48+
gem install bundler:2.2.7
4949
bundle install
5050
mkdir rspec
5151
bundle exec rspec --format progress --format RspecJunitFormatter -o ./rspec/rspec.xml spec

lib/ldclient-rb/events.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ def make_output_event(event)
439439
out[:variation] = event[:variation] if event.has_key?(:variation)
440440
out[:version] = event[:version] if event.has_key?(:version)
441441
out[:prereqOf] = event[:prereqOf] if event.has_key?(:prereqOf)
442+
out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind)
442443
if @inline_users || is_debug
443444
out[:user] = process_user(event)
444445
else
@@ -466,6 +467,7 @@ def make_output_event(event)
466467
out[:userKey] = event[:user].nil? ? nil : event[:user][:key]
467468
end
468469
out[:metricValue] = event[:metricValue] if event.has_key?(:metricValue)
470+
out[:contextKind] = event[:contextKind] if event.has_key?(:contextKind)
469471
out
470472
when "index"
471473
{

lib/ldclient-rb/impl/event_factory.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def new_eval_event(flag, user, detail, default_value, prereq_of_flag = nil)
2828
e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
2929
e[:prereqOf] = prereq_of_flag[:key] if !prereq_of_flag.nil?
3030
e[:reason] = detail.reason if add_experiment_data || @with_reasons
31+
e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
3132
e
3233
end
3334

@@ -43,6 +44,7 @@ def new_default_event(flag, user, default_value, reason)
4344
e[:trackEvents] = true if flag[:trackEvents]
4445
e[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
4546
e[:reason] = reason if @with_reasons
47+
e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
4648
e
4749
end
4850

@@ -55,6 +57,7 @@ def new_unknown_flag_event(key, user, default_value, reason)
5557
default: default_value
5658
}
5759
e[:reason] = reason if @with_reasons
60+
e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
5861
e
5962
end
6063

@@ -66,6 +69,16 @@ def new_identify_event(user)
6669
}
6770
end
6871

72+
def new_alias_event(current_context, previous_context)
73+
{
74+
kind: 'alias',
75+
key: current_context[:key],
76+
contextKind: context_to_context_kind(current_context),
77+
previousKey: previous_context[:key],
78+
previousContextKind: context_to_context_kind(previous_context)
79+
}
80+
end
81+
6982
def new_custom_event(event_name, user, data, metric_value)
7083
e = {
7184
kind: 'custom',
@@ -74,11 +87,20 @@ def new_custom_event(event_name, user, data, metric_value)
7487
}
7588
e[:data] = data if !data.nil?
7689
e[:metricValue] = metric_value if !metric_value.nil?
90+
e[:contextKind] = context_to_context_kind(user) if !user.nil? && user[:anonymous]
7791
e
7892
end
7993

8094
private
8195

96+
def context_to_context_kind(user)
97+
if !user.nil? && user[:anonymous]
98+
return "anonymousUser"
99+
else
100+
return "user"
101+
end
102+
end
103+
82104
def is_experiment(flag, reason)
83105
return false if !reason
84106
case reason[:kind]

lib/ldclient-rb/ldclient.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,23 @@ def track(event_name, user, data = nil, metric_value = nil)
282282
@event_processor.add_event(@event_factory_default.new_custom_event(event_name, user, data, metric_value))
283283
end
284284

285+
#
286+
# Associates a new and old user object for analytics purposes via an alias event.
287+
#
288+
# @param current_context [Hash] The current version of a user.
289+
# @param previous_context [Hash] The previous version of a user.
290+
# @return [void]
291+
#
292+
def alias(current_context, previous_context)
293+
if !current_context || current_context[:key].nil? || !previous_context || previous_context[:key].nil?
294+
@config.logger.warn("Alias called with nil user or nil user key!")
295+
return
296+
end
297+
sanitize_user(current_context)
298+
sanitize_user(previous_context)
299+
@event_processor.add_event(@event_factory_default.new_alias_event(current_context, previous_context))
300+
end
301+
285302
#
286303
# Returns all feature flag values for the given user.
287304
#

spec/events_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ def with_processor_and_sender(config)
408408
end
409409
end
410410

411+
it "queues alias event" do
412+
with_processor_and_sender(default_config) do |ep, sender|
413+
e = { kind: "alias", key: "a", contextKind: "user", previousKey: "b", previousContextKind: "user" }
414+
ep.add_event(e)
415+
416+
output = flush_and_get_events(ep, sender)
417+
expect(output).to contain_exactly(e)
418+
end
419+
end
420+
411421
it "treats nil value for custom the same as an empty hash" do
412422
with_processor_and_sender(default_config) do |ep, sender|
413423
user_with_nil_custom = { key: "userkey", custom: nil }

spec/ldclient_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
}
2626
}
2727
end
28+
let(:user_anonymous) do
29+
{
30+
31+
anonymous: true
32+
}
33+
end
2834
let(:numeric_key_user) do
2935
{
3036
key: 33,
@@ -155,6 +161,24 @@ def event_processor
155161
client.variation("key", nil, "default")
156162
end
157163

164+
it "queues a feature event for an existing feature when user is anonymous" do
165+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
166+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
167+
expect(event_processor).to receive(:add_event).with(hash_including(
168+
kind: "feature",
169+
key: "key",
170+
version: 100,
171+
contextKind: "anonymousUser",
172+
user: user_anonymous,
173+
variation: 0,
174+
value: "value",
175+
default: "default",
176+
trackEvents: true,
177+
debugEventsUntilDate: 1000
178+
))
179+
client.variation("key", user_anonymous, "default")
180+
end
181+
158182
it "queues a feature event for an existing feature when user key is nil" do
159183
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
160184
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
@@ -455,6 +479,12 @@ def event_processor
455479
client.track("custom_event_name", user, nil, 1.5)
456480
end
457481

482+
it "includes contextKind with anonymous user" do
483+
expect(event_processor).to receive(:add_event).with(hash_including(
484+
kind: "custom", key: "custom_event_name", user: user_anonymous, metricValue: 2.2, contextKind: "anonymousUser"))
485+
client.track("custom_event_name", user_anonymous, nil, 2.2)
486+
end
487+
458488
it "sanitizes the user in the event" do
459489
expect(event_processor).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
460490
client.track("custom_event_name", numeric_key_user, nil)
@@ -473,6 +503,26 @@ def event_processor
473503
end
474504
end
475505

506+
describe '#alias' do
507+
it "queues up an alias event" do
508+
expect(event_processor).to receive(:add_event).with(hash_including(
509+
kind: "alias", key: user[:key], contextKind: "user", previousKey: user_anonymous[:key], previousContextKind: "anonymousUser"))
510+
client.alias(user, user_anonymous)
511+
end
512+
513+
it "does not send an event, and logs a warning, if user is nil" do
514+
expect(event_processor).not_to receive(:add_event)
515+
expect(logger).to receive(:warn)
516+
client.alias(nil, nil)
517+
end
518+
519+
it "does not send an event, and logs a warning, if user key is nil" do
520+
expect(event_processor).not_to receive(:add_event)
521+
expect(logger).to receive(:warn)
522+
client.alias(user_without_key, user_without_key)
523+
end
524+
end
525+
476526
describe '#identify' do
477527
it "queues up an identify event" do
478528
expect(event_processor).to receive(:add_event).with(hash_including(kind: "identify", key: user[:key], user: user))

0 commit comments

Comments
 (0)