launchdarkly-server-sdk 8.5.0 → 8.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1774083dedfc1cdc4e32a2c2855a91c1075cd22aeb1ec55ff68d305c3d82d11
4
- data.tar.gz: a07b4851ed59e16271e5d32ad83027899846d8cc1dd18718ae2d3eed84ab27a2
3
+ metadata.gz: 2a732ff00a5e21bfc907dff44adc5bd3f1651bd80c2483273a1a9730f443448f
4
+ data.tar.gz: 1ca26bf847c2387ed585e07b18c6aa42a78496110a7bf9643751a0e2b04d2908
5
5
  SHA512:
6
- metadata.gz: 8407bb6f129c50da2b93c43cc17c53383ad1e01e7bc11ce803d1743d89bc42dda73734dd055e097f7fe11224082125e46aa23f63284fa06753f7e51678b065f1
7
- data.tar.gz: 313092bf41b6a3f82b603561f7fd3dd921318811ce542ac0c0d35d5d5677aba1060111b77dc810cf5caf7492c9e52161fbf54eac3bbd46709440eb4729abb055
6
+ metadata.gz: 901e6f7562f0861916bf06fd07088561713579633cc5e052ae5cf86c6acdbdd0497b55e273c2f92244a5653d0fa806c9776f92a853bad22232634489c630f85d
7
+ data.tar.gz: a325418b21c256a8b2d846d187e8bc91ba1e323955f460a418732b77f30354b64fc2dbfdadd04c4be4a41217779a4f217d522799ace4ce46a3ebc5019baf060c
@@ -43,6 +43,7 @@ module LaunchDarkly
43
43
  # @option opts [BigSegmentsConfig] :big_segments See {#big_segments}.
44
44
  # @option opts [Hash] :application See {#application}
45
45
  # @option opts [String] :payload_filter_key See {#payload_filter_key}
46
+ # @option opts [Boolean] :omit_anonymous_contexts See {#omit_anonymous_contexts}
46
47
  # @option hooks [Array<Interfaces::Hooks::Hook]
47
48
  #
48
49
  def initialize(opts = {})
@@ -77,6 +78,7 @@ module LaunchDarkly
77
78
  @application = LaunchDarkly::Impl::Util.validate_application_info(opts[:application] || {}, @logger)
78
79
  @payload_filter_key = opts[:payload_filter_key]
79
80
  @hooks = (opts[:hooks] || []).keep_if { |hook| hook.is_a? Interfaces::Hooks::Hook }
81
+ @omit_anonymous_contexts = opts.has_key?(:omit_anonymous_contexts) && opts[:omit_anonymous_contexts]
80
82
  @data_source_update_sink = nil
81
83
  end
82
84
 
@@ -385,6 +387,15 @@ module LaunchDarkly
385
387
  #
386
388
  attr_reader :hooks
387
389
 
390
+ #
391
+ # Sets whether anonymous contexts should be omitted from index and identify events.
392
+ #
393
+ # The default value is false. Anonymous contexts will be included in index and identify events.
394
+ # @return [Boolean]
395
+ #
396
+ attr_reader :omit_anonymous_contexts
397
+
398
+
388
399
  #
389
400
  # The default LaunchDarkly client configuration. This configuration sets
390
401
  # reasonable defaults for most users.
@@ -101,6 +101,26 @@ module LaunchDarkly
101
101
  @error.nil?
102
102
  end
103
103
 
104
+ #
105
+ # For a multi-kind context:
106
+ #
107
+ # A multi-kind context is made up of two or more single-kind contexts. This method will first discard any
108
+ # single-kind contexts which are anonymous. It will then create a new multi-kind context from the remaining
109
+ # single-kind contexts. This may result in an invalid context (e.g. all single-kind contexts are anonymous).
110
+ #
111
+ # For a single-kind context:
112
+ #
113
+ # If the context is not anonymous, this method will return the current context as is and unmodified.
114
+ #
115
+ # If the context is anonymous, this method will return an invalid context.
116
+ #
117
+ def without_anonymous_contexts
118
+ contexts = multi_kind? ? @contexts : [self]
119
+ contexts = contexts.reject { |c| c.anonymous }
120
+
121
+ LDContext.create_multi(contexts)
122
+ end
123
+
104
124
  #
105
125
  # Returns a hash mapping each context's kind to its key.
106
126
  #
@@ -144,6 +144,7 @@ module LaunchDarkly
144
144
  Impl::EventSender.new(sdk_key, config, client || Util.new_http_client(config.events_uri, config))
145
145
 
146
146
  @timestamp_fn = (test_properties || {})[:timestamp_fn] || proc { Impl::Util.current_time_millis }
147
+ @omit_anonymous_contexts = config.omit_anonymous_contexts
147
148
 
148
149
  EventDispatcher.new(@inbox, sdk_key, config, diagnostic_accumulator, event_sender)
149
150
  end
@@ -167,7 +168,8 @@ module LaunchDarkly
167
168
  end
168
169
 
169
170
  def record_identify_event(context)
170
- post_to_inbox(LaunchDarkly::Impl::IdentifyEvent.new(timestamp, context))
171
+ target_context = !@omit_anonymous_contexts ? context : context.without_anonymous_contexts
172
+ post_to_inbox(LaunchDarkly::Impl::IdentifyEvent.new(timestamp, target_context)) if target_context.valid?
171
173
  end
172
174
 
173
175
  def record_custom_event(context, key, data = nil, metric_value = nil)
@@ -319,16 +321,27 @@ module LaunchDarkly
319
321
  will_add_full_event = true
320
322
  end
321
323
 
322
- # For each context we haven't seen before, we add an index event - unless this is already
323
- # an identify event for that context.
324
- if !event.context.nil? && !notice_context(event.context) && !event.is_a?(LaunchDarkly::Impl::IdentifyEvent) && !event.is_a?(LaunchDarkly::Impl::MigrationOpEvent)
325
- outbox.add_event(LaunchDarkly::Impl::IndexEvent.new(event.timestamp, event.context))
324
+ get_indexable_context(event) do |ctx|
325
+ outbox.add_event(LaunchDarkly::Impl::IndexEvent.new(event.timestamp, ctx))
326
326
  end
327
327
 
328
328
  outbox.add_event(event) if will_add_full_event && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
329
329
  outbox.add_event(debug_event) if !debug_event.nil? && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
330
330
  end
331
331
 
332
+ private def get_indexable_context(event, &block)
333
+ return if event.context.nil?
334
+
335
+ context = !@config.omit_anonymous_contexts ? event.context : event.context.without_anonymous_contexts
336
+ return unless context.valid?
337
+
338
+ return if notice_context(context)
339
+ return if event.is_a?(LaunchDarkly::Impl::IdentifyEvent)
340
+ return if event.is_a?(LaunchDarkly::Impl::MigrationOpEvent)
341
+
342
+ yield context unless block.nil?
343
+ end
344
+
332
345
  #
333
346
  # Add to the set of contexts we've noticed, and return true if the context
334
347
  # was already known to us.
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "8.5.0" # x-release-please-version
2
+ VERSION = "8.6.0" # x-release-please-version
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.5.0
4
+ version: 8.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-10 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
376
376
  - !ruby/object:Gem::Version
377
377
  version: '0'
378
378
  requirements: []
379
- rubygems_version: 3.5.9
379
+ rubygems_version: 3.5.11
380
380
  signing_key:
381
381
  specification_version: 4
382
382
  summary: LaunchDarkly SDK for Ruby