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 +4 -4
- data/lib/posthog/client.rb +8 -3
- data/lib/posthog/feature_flag.rb +4 -1
- data/lib/posthog/feature_flag_evaluations.rb +2 -1
- data/lib/posthog/feature_flags.rb +12 -1
- data/lib/posthog/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b23e0da0723e7582825d0888d8c6ffd9b3ad0a77e5eec513a40ab3de1faaa306
|
|
4
|
+
data.tar.gz: 1fc203c912147dc865cb342213ef8ccd3604e4d84f0b0005932c559aa30c8017
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8409ba6d5fb0801643cbd6556a1dabf41441ff522b85d612601ac8547482c5eb139ac68f21250f2f240654f08c03b3ca6cdc0409f57f1c6af9cdd880c677805f
|
|
7
|
+
data.tar.gz: c7a146c293985480777e6f5139588ca0d897170b8fe15412e9d60561711cb57bec53e70225b8b209916a50835f249b9816bece364be754a56e6f1118454feb52
|
data/lib/posthog/client.rb
CHANGED
|
@@ -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
|
data/lib/posthog/feature_flag.rb
CHANGED
|
@@ -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,
|
data/lib/posthog/version.rb
CHANGED