posthog-ruby 3.15.1 → 3.15.3

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: edb7fbf2f848ccb05f6a79f9c3429d395ac39cde5fdd1f83c59d97990231cbc8
4
- data.tar.gz: bf96ccaccf1cf2117b502311895d95eb32de786b005809bf1d03471c67fc3920
3
+ metadata.gz: 36a73ef4ffe63b9e2c722441bd8d3c5732e8e162ea1431bdc68bc861b2c8a452
4
+ data.tar.gz: cf1f040865ce0df9fc7c68d0cac9f0903114b959b1b162d83afecfbdfe8697d1
5
5
  SHA512:
6
- metadata.gz: a60d451d311741d7d3407515a8b05a0029a24d098445aae51fe4c4d51ab894c4005c0f78267f4d5717681a258ef83091e62e508d8f902068a6e9321ceead274b
7
- data.tar.gz: 01b522405e918921a9667a1cf47271b314cf55cada33687ea31d8c2ed04239f602f61adf35c891920691c25a10d0ac6ad76c816ef2160b3ccfaf6208e564baa1
6
+ metadata.gz: 5214a1df75497519ac214d1134549a9d41e98bb16ca7e82df800fca062957ecc17c382472902cd7a8161fe4a6a92786c2fe243ec10663dbbaeb7ae1ddd54562f
7
+ data.tar.gz: 3adf9801fe9b1a64427d8c7a0fd4abbc15b78c77fa80566e2be23bc97ff9d3d9808be9ba0513f71d00b814ae9e70da532e82495ce3c4bf763b00ac1adf30b076
@@ -558,7 +558,7 @@ module PostHog
558
558
  return FeatureFlagEvaluations.new(host: host, distinct_id: distinct_id, flags: {}, groups: groups) if @disabled
559
559
 
560
560
  person_properties, group_properties = add_local_person_and_group_properties(
561
- distinct_id, groups, person_properties, group_properties
561
+ groups, person_properties, group_properties
562
562
  )
563
563
 
564
564
  records = {}
@@ -672,8 +672,8 @@ module PostHog
672
672
  )
673
673
  return {} if @disabled
674
674
 
675
- person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
676
- person_properties, group_properties)
675
+ person_properties, group_properties = add_local_person_and_group_properties(groups, person_properties,
676
+ group_properties)
677
677
  @feature_flags_poller.get_all_flags(distinct_id, groups, person_properties, group_properties,
678
678
  only_evaluate_locally)
679
679
  end
@@ -712,8 +712,8 @@ module PostHog
712
712
  return nil if @disabled
713
713
 
714
714
  key = key.to_s
715
- person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
716
- person_properties, group_properties)
715
+ person_properties, group_properties = add_local_person_and_group_properties(groups, person_properties,
716
+ group_properties)
717
717
  @feature_flags_poller.get_feature_flag_payload(key, distinct_id, match_value, groups, person_properties,
718
718
  group_properties, only_evaluate_locally)
719
719
  end
@@ -740,7 +740,7 @@ module PostHog
740
740
  return { featureFlags: {}, featureFlagPayloads: {} } if @disabled
741
741
 
742
742
  person_properties, group_properties = add_local_person_and_group_properties(
743
- distinct_id, groups, person_properties, group_properties
743
+ groups, person_properties, group_properties
744
744
  )
745
745
  response = @feature_flags_poller.get_all_flags_and_payloads(
746
746
  distinct_id, groups, person_properties, group_properties, only_evaluate_locally
@@ -902,7 +902,7 @@ module PostHog
902
902
 
903
903
  key = key.to_s
904
904
  person_properties, group_properties = add_local_person_and_group_properties(
905
- distinct_id, groups, person_properties, group_properties
905
+ groups, person_properties, group_properties
906
906
  )
907
907
  feature_flag_response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload =
908
908
  @feature_flags_poller.get_feature_flag(
@@ -1048,7 +1048,7 @@ module PostHog
1048
1048
  @shutdown_mutex.synchronize { @shutdown }
1049
1049
  end
1050
1050
 
1051
- def add_local_person_and_group_properties(distinct_id, groups, person_properties, group_properties)
1051
+ def add_local_person_and_group_properties(groups, person_properties, group_properties)
1052
1052
  groups ||= {}
1053
1053
  person_properties ||= {}
1054
1054
  group_properties ||= {}
@@ -1061,8 +1061,6 @@ module PostHog
1061
1061
  symbolize_keys! value
1062
1062
  end
1063
1063
 
1064
- all_person_properties = { distinct_id: distinct_id }.merge(person_properties)
1065
-
1066
1064
  all_group_properties = {}
1067
1065
  groups&.each do |group_name, group_key|
1068
1066
  all_group_properties[group_name] = {
@@ -1070,7 +1068,7 @@ module PostHog
1070
1068
  }.merge((group_properties && group_properties[group_name]) || {})
1071
1069
  end
1072
1070
 
1073
- [all_person_properties, all_group_properties]
1071
+ [person_properties, all_group_properties]
1074
1072
  end
1075
1073
  end
1076
1074
  end
@@ -36,8 +36,9 @@ module PostHog
36
36
  # @param feature_flag_request_timeout_seconds [Integer] Timeout for feature flag requests.
37
37
  # @param on_error [Proc, nil] Callback invoked as `on_error.call(status, error)`.
38
38
  # @param flag_definition_cache_provider [Object, nil] Optional {FlagDefinitionCacheProvider} implementation.
39
- # @param feature_flag_request_max_retries [Integer, nil] Retries after a transient network error on a flag
40
- # request. Defaults to {Defaults::FeatureFlags::FLAG_REQUEST_MAX_RETRIES}. Set to 0 to disable retrying.
39
+ # @param feature_flag_request_max_retries [Integer, nil] Retries after a transient network error or retryable
40
+ # HTTP response status on a flag request. Defaults to {Defaults::FeatureFlags::FLAG_REQUEST_MAX_RETRIES}.
41
+ # Set to 0 to disable retrying.
41
42
  def initialize(
42
43
  polling_interval,
43
44
  personal_api_key,
@@ -921,7 +922,12 @@ module PostHog
921
922
 
922
923
  aggregation_group_type_index = flag_filters[:aggregation_group_type_index]
923
924
  if aggregation_group_type_index.nil?
924
- return match_feature_flag_properties(flag, distinct_id, person_properties, evaluation_cache, @cohorts,
925
+ local_person_properties = person_properties || {}
926
+ unless local_person_properties.key?(:distinct_id) || local_person_properties.key?('distinct_id')
927
+ local_person_properties = local_person_properties.merge(distinct_id: distinct_id)
928
+ end
929
+
930
+ return match_feature_flag_properties(flag, distinct_id, local_person_properties, evaluation_cache, @cohorts,
925
931
  groups: groups, group_properties: group_properties)
926
932
  end
927
933
 
@@ -1234,7 +1240,12 @@ module PostHog
1234
1240
  data['token'] = @project_api_key
1235
1241
  req.body = data.to_json
1236
1242
 
1237
- _request(uri, req, @feature_flag_request_timeout_seconds)
1243
+ _request(
1244
+ uri,
1245
+ req,
1246
+ @feature_flag_request_timeout_seconds,
1247
+ retry_status_codes: RETRYABLE_FLAGS_REQUEST_STATUS_CODES
1248
+ )
1238
1249
  end
1239
1250
 
1240
1251
  def _request_remote_config_payload(flag_key)
@@ -1256,14 +1267,15 @@ module PostHog
1256
1267
  Errno::ECONNRESET,
1257
1268
  EOFError
1258
1269
  ].freeze
1270
+ RETRYABLE_FLAGS_REQUEST_STATUS_CODES = [502, 504].freeze
1259
1271
 
1260
- def _request(uri, request_object, timeout = nil, include_etag: false)
1272
+ def _request(uri, request_object, timeout = nil, include_etag: false, retry_status_codes: [])
1261
1273
  request_object['User-Agent'] = "posthog-ruby/#{PostHog::VERSION}"
1262
1274
  request_timeout = timeout || 10
1263
1275
  backoff_policy = nil
1264
1276
  attempts = 0
1265
1277
 
1266
- begin
1278
+ loop do
1267
1279
  attempts += 1
1268
1280
  Net::HTTP.start(
1269
1281
  uri.hostname,
@@ -1277,6 +1289,16 @@ module PostHog
1277
1289
  status_code = res.code.to_i
1278
1290
  etag = include_etag ? res['ETag'] : nil
1279
1291
 
1292
+ if retry_status_codes.include?(status_code) && attempts <= @feature_flag_request_max_retries
1293
+ backoff_policy ||= BackoffPolicy.new
1294
+ interval = backoff_policy.next_interval.to_f / 1000
1295
+ logger.debug(
1296
+ "Retrying request to #{_mask_tokens_in_url(uri.to_s)} after HTTP #{status_code} (attempt #{attempts})"
1297
+ )
1298
+ sleep(interval)
1299
+ next
1300
+ end
1301
+
1280
1302
  # Handle 304 Not Modified - return special response indicating no change
1281
1303
  if status_code == 304
1282
1304
  logger.debug("#{request_object.method} #{_mask_tokens_in_url(uri.to_s)} returned 304 Not Modified")
@@ -1304,7 +1326,7 @@ module PostHog
1304
1326
  interval = backoff_policy.next_interval.to_f / 1000
1305
1327
  logger.debug("Retrying request to #{_mask_tokens_in_url(uri.to_s)} after #{e.class} (attempt #{attempts})")
1306
1328
  sleep(interval)
1307
- retry
1329
+ next
1308
1330
  end
1309
1331
  logger.debug("Unable to complete request to #{_mask_tokens_in_url(uri.to_s)}")
1310
1332
  raise
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.15.1'
4
+ VERSION = '3.15.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthog-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.15.1
4
+ version: 3.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''