launchdarkly-server-sdk 8.5.0 → 8.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1774083dedfc1cdc4e32a2c2855a91c1075cd22aeb1ec55ff68d305c3d82d11
4
- data.tar.gz: a07b4851ed59e16271e5d32ad83027899846d8cc1dd18718ae2d3eed84ab27a2
3
+ metadata.gz: 5af0bbef2faa957948f0a7f50e15fcabe977389a33985907183d58325e1c6b3d
4
+ data.tar.gz: 4ecb07d71897441c2d02cc1972a75b63f07615b6fa1266330f7403c5e36c01c2
5
5
  SHA512:
6
- metadata.gz: 8407bb6f129c50da2b93c43cc17c53383ad1e01e7bc11ce803d1743d89bc42dda73734dd055e097f7fe11224082125e46aa23f63284fa06753f7e51678b065f1
7
- data.tar.gz: 313092bf41b6a3f82b603561f7fd3dd921318811ce542ac0c0d35d5d5677aba1060111b77dc810cf5caf7492c9e52161fbf54eac3bbd46709440eb4729abb055
6
+ metadata.gz: 22409520414843c8249e2fa303686289c3701d7802fb558fe87870d4d5293381fabbf4f0634f6a14784e77eb328a5601929e096555bdc14f66ee4826a6f36316
7
+ data.tar.gz: 36f9746807944960f161f83f4a37258d0d6ce1035018dc4d49c2e9b2a1d09fa96e83f35e6a1a0afeb30ee902bf4713e74ef06d32068611458d384a35561775e9
@@ -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 = {})
@@ -64,6 +65,7 @@ module LaunchDarkly
64
65
  @all_attributes_private = opts[:all_attributes_private] || false
65
66
  @private_attributes = opts[:private_attributes] || []
66
67
  @send_events = opts.has_key?(:send_events) ? opts[:send_events] : Config.default_send_events
68
+ @compress_events = opts.has_key?(:compress_events) ? opts[:compress_events] : Config.default_compress_events
67
69
  @context_keys_capacity = opts[:context_keys_capacity] || Config.default_context_keys_capacity
68
70
  @context_keys_flush_interval = opts[:context_keys_flush_interval] || Config.default_context_keys_flush_interval
69
71
  @data_source = opts[:data_source]
@@ -77,6 +79,7 @@ module LaunchDarkly
77
79
  @application = LaunchDarkly::Impl::Util.validate_application_info(opts[:application] || {}, @logger)
78
80
  @payload_filter_key = opts[:payload_filter_key]
79
81
  @hooks = (opts[:hooks] || []).keep_if { |hook| hook.is_a? Interfaces::Hooks::Hook }
82
+ @omit_anonymous_contexts = opts.has_key?(:omit_anonymous_contexts) && opts[:omit_anonymous_contexts]
80
83
  @data_source_update_sink = nil
81
84
  end
82
85
 
@@ -252,6 +255,17 @@ module LaunchDarkly
252
255
  #
253
256
  attr_reader :send_events
254
257
 
258
+ #
259
+ # Should the event payload sent to LaunchDarkly use gzip compression. By default this is false to prevent backward
260
+ # breaking compatibility issues with older versions of the relay proxy.
261
+ #
262
+ # Customers not using the relay proxy are strongly encouraged to enable this feature to reduce egress bandwidth
263
+ # cost.
264
+ #
265
+ # @return [Boolean]
266
+ #
267
+ attr_reader :compress_events
268
+
255
269
  #
256
270
  # The number of context keys that the event processor can remember at any one time. This reduces the
257
271
  # amount of duplicate context details sent in analytics events.
@@ -385,6 +399,15 @@ module LaunchDarkly
385
399
  #
386
400
  attr_reader :hooks
387
401
 
402
+ #
403
+ # Sets whether anonymous contexts should be omitted from index and identify events.
404
+ #
405
+ # The default value is false. Anonymous contexts will be included in index and identify events.
406
+ # @return [Boolean]
407
+ #
408
+ attr_reader :omit_anonymous_contexts
409
+
410
+
388
411
  #
389
412
  # The default LaunchDarkly client configuration. This configuration sets
390
413
  # reasonable defaults for most users.
@@ -528,6 +551,14 @@ module LaunchDarkly
528
551
  true
529
552
  end
530
553
 
554
+ #
555
+ # The default value for {#compress_events}.
556
+ # @return [Boolean] false
557
+ #
558
+ def self.default_compress_events
559
+ false
560
+ end
561
+
531
562
  #
532
563
  # The default value for {#context_keys_capacity}.
533
564
  # @return [Integer] 1000
@@ -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.
@@ -500,13 +513,13 @@ module LaunchDarkly
500
513
  evaluation: {
501
514
  key: event.key,
502
515
  value: event.evaluation.value,
516
+ reason: event.evaluation.reason,
503
517
  },
504
518
  }
505
519
 
506
520
  out[:evaluation][:version] = event.version unless event.version.nil?
507
521
  out[:evaluation][:default] = event.default unless event.default.nil?
508
522
  out[:evaluation][:variation] = event.evaluation.variation_index unless event.evaluation.variation_index.nil?
509
- out[:evaluation][:reason] = event.evaluation.reason unless event.evaluation.reason.nil?
510
523
  out[:samplingRatio] = event.sampling_ratio unless event.sampling_ratio.nil? || event.sampling_ratio == 1
511
524
 
512
525
  measurements = []
@@ -2,6 +2,8 @@ require "ldclient-rb/impl/unbounded_pool"
2
2
 
3
3
  require "securerandom"
4
4
  require "http"
5
+ require "stringio"
6
+ require "zlib"
5
7
 
6
8
  module LaunchDarkly
7
9
  module Impl
@@ -42,14 +44,24 @@ module LaunchDarkly
42
44
  @logger.debug { "[LDClient] sending #{description}: #{event_data}" }
43
45
  headers = {}
44
46
  headers["content-type"] = "application/json"
47
+ headers["content-encoding"] = "gzip" if @config.compress_events
45
48
  Impl::Util.default_http_headers(@sdk_key, @config).each { |k, v| headers[k] = v }
46
49
  unless is_diagnostic
47
50
  headers["X-LaunchDarkly-Event-Schema"] = CURRENT_SCHEMA_VERSION.to_s
48
51
  headers["X-LaunchDarkly-Payload-ID"] = payload_id
49
52
  end
53
+
54
+ body = event_data
55
+ if @config.compress_events
56
+ gzip = Zlib::GzipWriter.new(StringIO.new)
57
+ gzip << event_data
58
+
59
+ body = gzip.close.string
60
+ end
61
+
50
62
  response = http_client.request("POST", uri, {
51
63
  headers: headers,
52
- body: event_data,
64
+ body: body,
53
65
  })
54
66
  rescue StandardError => exn
55
67
  @logger.warn { "[LDClient] Error sending events: #{exn.inspect}." }
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "8.5.0" # x-release-please-version
2
+ VERSION = "8.7.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.7.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-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -248,6 +248,20 @@ dependencies:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
250
  version: 0.1.2
251
+ - !ruby/object:Gem::Dependency
252
+ name: zlib
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '3.1'
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '3.1'
251
265
  - !ruby/object:Gem::Dependency
252
266
  name: json
253
267
  requirement: !ruby/object:Gem::Requirement
@@ -376,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
376
390
  - !ruby/object:Gem::Version
377
391
  version: '0'
378
392
  requirements: []
379
- rubygems_version: 3.5.9
393
+ rubygems_version: 3.5.11
380
394
  signing_key:
381
395
  specification_version: 4
382
396
  summary: LaunchDarkly SDK for Ruby