posthog-ruby 3.18.0 → 3.19.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: 75e17034bb60a9af9539cfe28137a91a71d83305e4d3dc7d1db3844870efac38
4
- data.tar.gz: b511f71723032dff61fc998ae145d1e650eb6d90bdb4df84024e9335613aed71
3
+ metadata.gz: b23e0da0723e7582825d0888d8c6ffd9b3ad0a77e5eec513a40ab3de1faaa306
4
+ data.tar.gz: 1fc203c912147dc865cb342213ef8ccd3604e4d84f0b0005932c559aa30c8017
5
5
  SHA512:
6
- metadata.gz: d27932884831bba0abb8b90315c1c8c684ae821aa85a5f6df8b486339d53097022ee2d58303b913a46cb05cf576230bf1f45b2ffdbdf465c79fce4875239cfb9
7
- data.tar.gz: 043c0f02fb14f744898e7910623757931021d03cb0fbcacc46a305ec2f4d753df81a1ed8482b72f6e9c7e8bc1c826c78b86e889491ceb4c112dfa1844b1cf82a
6
+ metadata.gz: 8409ba6d5fb0801643cbd6556a1dabf41441ff522b85d612601ac8547482c5eb139ac68f21250f2f240654f08c03b3ca6cdc0409f57f1c6af9cdd880c677805f
7
+ data.tar.gz: c7a146c293985480777e6f5139588ca0d897170b8fe15412e9d60561711cb57bec53e70225b8b209916a50835f249b9816bece364be754a56e6f1118454feb52
@@ -609,7 +609,8 @@ module PostHog
609
609
  id: definition[:id],
610
610
  version: nil,
611
611
  reason: FeatureFlagEvaluations::EVALUATED_LOCALLY_REASON,
612
- locally_evaluated: true
612
+ locally_evaluated: true,
613
+ has_experiment: definition[:has_experiment]
613
614
  )
614
615
  locally_evaluated_keys << key.to_s
615
616
  end
@@ -649,7 +650,8 @@ module PostHog
649
650
  id: metadata ? metadata.id : nil,
650
651
  version: metadata ? metadata.version : nil,
651
652
  reason: reason ? (reason.description || reason.code) : nil,
652
- locally_evaluated: false
653
+ locally_evaluated: false,
654
+ has_experiment: metadata&.has_experiment
653
655
  )
654
656
  end
655
657
  rescue StandardError => e
@@ -766,6 +768,7 @@ module PostHog
766
768
  # Remove internal information
767
769
  response.delete(:requestId)
768
770
  response.delete(:evaluatedAt)
771
+ response.delete(:flagDetails)
769
772
  response
770
773
  end
771
774
 
@@ -921,7 +924,8 @@ module PostHog
921
924
  person_properties, group_properties = add_local_person_and_group_properties(
922
925
  groups, person_properties, group_properties
923
926
  )
924
- feature_flag_response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload =
927
+ feature_flag_response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload,
928
+ has_experiment =
925
929
  @feature_flags_poller.get_feature_flag(
926
930
  key, distinct_id, groups, person_properties, group_properties, only_evaluate_locally
927
931
  )
@@ -931,6 +935,7 @@ module PostHog
931
935
  '$feature_flag_response' => feature_flag_response,
932
936
  'locally_evaluated' => flag_was_locally_evaluated
933
937
  }
938
+ properties['$feature_flag_has_experiment'] = has_experiment unless has_experiment.nil?
934
939
  properties['$feature_flag_request_id'] = request_id if request_id
935
940
  properties['$feature_flag_evaluated_at'] = evaluated_at if evaluated_at
936
941
  properties['$feature_flag_error'] = feature_flag_error if feature_flag_error
@@ -68,7 +68,7 @@ module PostHog
68
68
  #
69
69
  # @api private
70
70
  class FeatureFlagMetadata
71
- attr_reader :id, :version, :payload, :description
71
+ attr_reader :id, :version, :payload, :description, :has_experiment
72
72
 
73
73
  # @param json [Hash] Raw metadata returned by /flags.
74
74
  def initialize(json)
@@ -77,6 +77,9 @@ module PostHog
77
77
  @version = json['version']
78
78
  @payload = json['payload']
79
79
  @description = json['description']
80
+ # Whether the flag is linked to an experiment. nil when the server
81
+ # (an older deployment) does not report the field.
82
+ @has_experiment = json['has_experiment']
80
83
  end
81
84
  end
82
85
  end
@@ -13,7 +13,7 @@ module PostHog
13
13
  EVALUATED_LOCALLY_REASON = 'Evaluated locally'
14
14
 
15
15
  EvaluatedFlagRecord = Struct.new(
16
- :key, :enabled, :variant, :payload, :id, :version, :reason, :locally_evaluated,
16
+ :key, :enabled, :variant, :payload, :id, :version, :reason, :locally_evaluated, :has_experiment,
17
17
  keyword_init: true
18
18
  )
19
19
 
@@ -169,6 +169,7 @@ module PostHog
169
169
  }
170
170
 
171
171
  if flag
172
+ properties['$feature_flag_has_experiment'] = flag.has_experiment unless flag.has_experiment.nil?
172
173
  properties['$feature_flag_payload'] = flag.payload unless flag.payload.nil?
173
174
  properties['$feature_flag_id'] = flag.id if flag.id
174
175
  properties['$feature_flag_version'] = flag.version if flag.version
@@ -221,6 +221,11 @@ module PostHog
221
221
  end
222
222
 
223
223
  flag_was_locally_evaluated = !response.nil?
224
+ # Whether the flag is linked to an experiment, as reported by the server.
225
+ # Locally-evaluated flags carry it in the stored definition; remotely
226
+ # evaluated flags carry it in the response metadata. nil when the server
227
+ # (an older deployment) does not report it.
228
+ has_experiment = feature_flag[:has_experiment] if flag_was_locally_evaluated
224
229
 
225
230
  request_id = nil
226
231
  evaluated_at = nil
@@ -253,6 +258,9 @@ module PostHog
253
258
  payload = payloads[key]
254
259
  feature_flag_error = errors.join(',') unless errors.empty?
255
260
 
261
+ flag_detail = flags_data[:flagDetails]&.[](key.to_sym)
262
+ has_experiment = flag_detail&.metadata&.has_experiment
263
+
256
264
  logger.debug "Successfully computed flag remotely: #{key} -> #{response}"
257
265
  rescue Timeout::Error => e
258
266
  @on_error.call(-1, "Timeout while fetching flags remotely: #{e}")
@@ -266,7 +274,7 @@ module PostHog
266
274
  end
267
275
  end
268
276
 
269
- [response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload]
277
+ [response, flag_was_locally_evaluated, request_id, evaluated_at, feature_flag_error, payload, has_experiment]
270
278
  end
271
279
 
272
280
  def get_all_flags(
@@ -324,10 +332,12 @@ module PostHog
324
332
  errors_while_computing = false
325
333
  quota_limited = nil
326
334
  status_code = nil
335
+ flag_details = nil
327
336
 
328
337
  if fallback_to_server && !only_evaluate_locally
329
338
  begin
330
339
  flags_and_payloads = get_flags(distinct_id, groups, person_properties, group_properties)
340
+ flag_details = flags_and_payloads[:flags]
331
341
  errors_while_computing = flags_and_payloads[:errorsWhileComputingFlags] || false
332
342
  quota_limited = flags_and_payloads[:quotaLimited]
333
343
  status_code = flags_and_payloads[:status]
@@ -368,6 +378,7 @@ module PostHog
368
378
  {
369
379
  featureFlags: flags,
370
380
  featureFlagPayloads: payloads,
381
+ flagDetails: flag_details,
371
382
  requestId: request_id,
372
383
  evaluatedAt: evaluated_at,
373
384
  errorsWhileComputingFlags: errors_while_computing,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostHog
4
- VERSION = '3.18.0'
4
+ VERSION = '3.19.0'
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.18.0
4
+ version: 3.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''