posthog-ruby 3.9.2 → 3.9.4
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 +52 -25
- data/lib/posthog/flag_definition_cache.rb +0 -2
- 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: fa0374a1bdfa7b8d76b8f2ffeee64e868883148c50ab714ed3072db48862ee42
|
|
4
|
+
data.tar.gz: b2729eb5375aea69389ff2fb7ba012a5644e60723fda3b2bc60647161cca11b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7287da0e6624013013c6bddc1565791be27486cfdb9bf7f196c0fc5663fd5f963375d1d3d7f5b8b6cf6e2f57c515991cf605c9abf44dba197a4f85f8f0e352af
|
|
7
|
+
data.tar.gz: 7e16531f9ca40884c42ef54eff1507efec2b64c09b0f9cd09da7e16186d9e337846699fde96792b4d1ed75c403d95222e37a8de5ec768b8fbd1f16882ecb2225
|
data/lib/posthog/client.rb
CHANGED
|
@@ -52,7 +52,7 @@ module PostHog
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# @param opts [Hash] Client configuration.
|
|
55
|
-
# @option opts [String] :api_key Your project's API key.
|
|
55
|
+
# @option opts [String, nil] :api_key Your project's API key. Missing or blank values disable the client.
|
|
56
56
|
# @option opts [String, nil] :personal_api_key Your personal API key. Required for local feature flag evaluation.
|
|
57
57
|
# @option opts [String] :host Fully qualified hostname of the PostHog server. Defaults to `https://us.i.posthog.com`.
|
|
58
58
|
# @option opts [Integer] :max_queue_size Maximum number of calls to remain queued. Defaults to 10_000.
|
|
@@ -72,7 +72,7 @@ module PostHog
|
|
|
72
72
|
# @option opts [Boolean] :skip_ssl_verification +true+ to disable SSL certificate verification for requests.
|
|
73
73
|
# Intended only for local development or custom deployments.
|
|
74
74
|
# @option opts [Object] :flag_definition_cache_provider An object implementing the {FlagDefinitionCacheProvider}
|
|
75
|
-
# interface for distributed flag definition caching.
|
|
75
|
+
# interface for distributed flag definition caching.
|
|
76
76
|
def initialize(opts = {})
|
|
77
77
|
symbolize_keys!(opts)
|
|
78
78
|
|
|
@@ -82,11 +82,12 @@ module PostHog
|
|
|
82
82
|
|
|
83
83
|
@queue = Queue.new
|
|
84
84
|
@api_key = opts[:api_key]
|
|
85
|
+
@disabled = @api_key.nil? || @api_key.empty?
|
|
85
86
|
@max_queue_size = opts[:max_queue_size] || Defaults::Queue::MAX_SIZE
|
|
86
87
|
@worker_mutex = Mutex.new
|
|
87
|
-
@sync_mode = opts[:sync_mode] == true && !opts[:test_mode]
|
|
88
|
+
@sync_mode = opts[:sync_mode] == true && !opts[:test_mode] && !@disabled
|
|
88
89
|
@on_error = opts[:on_error] || proc { |status, error| }
|
|
89
|
-
@worker = if opts[:test_mode]
|
|
90
|
+
@worker = if opts[:test_mode] || @disabled
|
|
90
91
|
NoopWorker.new(@queue)
|
|
91
92
|
elsif @sync_mode
|
|
92
93
|
nil
|
|
@@ -105,11 +106,12 @@ module PostHog
|
|
|
105
106
|
@feature_flags_poller = nil
|
|
106
107
|
@personal_api_key = opts[:personal_api_key]
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
if @disabled && !opts[:silence_disabled_client_error]
|
|
110
|
+
logger.error('api_key is missing or empty after trimming whitespace; check your project API key')
|
|
111
|
+
end
|
|
110
112
|
|
|
111
113
|
# Warn when multiple clients are created with the same API key (can cause dropped events)
|
|
112
|
-
unless opts[:test_mode] || opts[:disable_singleton_warning]
|
|
114
|
+
unless @disabled || opts[:test_mode] || opts[:disable_singleton_warning]
|
|
113
115
|
previous_count = self.class._increment_instance_count(@api_key)
|
|
114
116
|
if previous_count >= 1
|
|
115
117
|
logger.warn(
|
|
@@ -121,16 +123,18 @@ module PostHog
|
|
|
121
123
|
end
|
|
122
124
|
end
|
|
123
125
|
|
|
124
|
-
@
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
unless @disabled
|
|
127
|
+
@feature_flags_poller =
|
|
128
|
+
FeatureFlagsPoller.new(
|
|
129
|
+
opts[:feature_flags_polling_interval],
|
|
130
|
+
opts[:personal_api_key],
|
|
131
|
+
@api_key,
|
|
132
|
+
opts[:host],
|
|
133
|
+
opts[:feature_flag_request_timeout_seconds] || Defaults::FeatureFlags::FLAG_REQUEST_TIMEOUT_SECONDS,
|
|
134
|
+
opts[:on_error],
|
|
135
|
+
flag_definition_cache_provider: opts[:flag_definition_cache_provider]
|
|
136
|
+
)
|
|
137
|
+
end
|
|
134
138
|
|
|
135
139
|
@distinct_id_has_sent_flag_calls = SizeLimitedHash.new(Defaults::MAX_HASH_SIZE) do |hash, key|
|
|
136
140
|
hash[key] = []
|
|
@@ -198,6 +202,8 @@ module PostHog
|
|
|
198
202
|
# @return [Boolean] Whether the event was queued or sent.
|
|
199
203
|
# @macro common_attrs
|
|
200
204
|
def capture(attrs)
|
|
205
|
+
return false if @disabled
|
|
206
|
+
|
|
201
207
|
symbolize_keys! attrs
|
|
202
208
|
enrich_capture_attrs_with_context(attrs)
|
|
203
209
|
|
|
@@ -226,7 +232,7 @@ module PostHog
|
|
|
226
232
|
end
|
|
227
233
|
|
|
228
234
|
send_feature_flags_param = attrs[:send_feature_flags]
|
|
229
|
-
if send_feature_flags_param
|
|
235
|
+
if send_feature_flags_param && !@disabled
|
|
230
236
|
_emit_deprecation(
|
|
231
237
|
:capture_send_feature_flags,
|
|
232
238
|
'`send_feature_flags` on `capture` is deprecated and will be removed in a future major ' \
|
|
@@ -280,6 +286,8 @@ module PostHog
|
|
|
280
286
|
# same `$feature/<key>` and `$active_feature_flags` properties as the snapshot.
|
|
281
287
|
# @return [Boolean, nil] Whether the exception event was queued or sent, or nil if the input could not be parsed.
|
|
282
288
|
def capture_exception(exception, distinct_id = nil, additional_properties = {}, flags: nil)
|
|
289
|
+
return false if @disabled
|
|
290
|
+
|
|
283
291
|
exception_info = ExceptionCapture.build_parsed_exception(exception)
|
|
284
292
|
|
|
285
293
|
return if exception_info.nil?
|
|
@@ -306,6 +314,8 @@ module PostHog
|
|
|
306
314
|
# @return [Boolean] Whether the identify event was queued or sent.
|
|
307
315
|
# @macro common_attrs
|
|
308
316
|
def identify(attrs)
|
|
317
|
+
return false if @disabled
|
|
318
|
+
|
|
309
319
|
symbolize_keys! attrs
|
|
310
320
|
enqueue(FieldParser.parse_for_identify(attrs))
|
|
311
321
|
end
|
|
@@ -321,6 +331,8 @@ module PostHog
|
|
|
321
331
|
# @return [Boolean] Whether the group identify event was queued or sent.
|
|
322
332
|
# @macro common_attrs
|
|
323
333
|
def group_identify(attrs)
|
|
334
|
+
return false if @disabled
|
|
335
|
+
|
|
324
336
|
symbolize_keys! attrs
|
|
325
337
|
enqueue(FieldParser.parse_for_group_identify(attrs))
|
|
326
338
|
end
|
|
@@ -333,6 +345,8 @@ module PostHog
|
|
|
333
345
|
# @return [Boolean] Whether the alias event was queued or sent.
|
|
334
346
|
# @macro common_attrs
|
|
335
347
|
def alias(attrs)
|
|
348
|
+
return false if @disabled
|
|
349
|
+
|
|
336
350
|
symbolize_keys! attrs
|
|
337
351
|
enqueue(FieldParser.parse_for_alias(attrs))
|
|
338
352
|
end
|
|
@@ -388,6 +402,8 @@ module PostHog
|
|
|
388
402
|
# @param flag_key [String, Symbol] The unique flag key of the remote config feature flag.
|
|
389
403
|
# @return [Hash] The parsed remote config payload response.
|
|
390
404
|
def get_remote_config_payload(flag_key)
|
|
405
|
+
return nil if @disabled
|
|
406
|
+
|
|
391
407
|
@feature_flags_poller.get_remote_config_payload(flag_key.to_s)
|
|
392
408
|
end
|
|
393
409
|
|
|
@@ -465,6 +481,8 @@ module PostHog
|
|
|
465
481
|
'`flags.get_flag_payload(key)` instead — this consolidates flag evaluation into a single ' \
|
|
466
482
|
'`/flags` request per incoming request.'
|
|
467
483
|
)
|
|
484
|
+
return nil if @disabled
|
|
485
|
+
|
|
468
486
|
_get_feature_flag_result(
|
|
469
487
|
key, distinct_id,
|
|
470
488
|
groups: groups, person_properties: person_properties, group_properties: group_properties,
|
|
@@ -507,6 +525,8 @@ module PostHog
|
|
|
507
525
|
return FeatureFlagEvaluations.new(host: host, distinct_id: '', flags: {})
|
|
508
526
|
end
|
|
509
527
|
|
|
528
|
+
return FeatureFlagEvaluations.new(host: host, distinct_id: distinct_id, flags: {}, groups: groups) if @disabled
|
|
529
|
+
|
|
510
530
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
511
531
|
distinct_id, groups, person_properties, group_properties
|
|
512
532
|
)
|
|
@@ -620,6 +640,8 @@ module PostHog
|
|
|
620
640
|
group_properties: {},
|
|
621
641
|
only_evaluate_locally: false
|
|
622
642
|
)
|
|
643
|
+
return {} if @disabled
|
|
644
|
+
|
|
623
645
|
person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
|
|
624
646
|
person_properties, group_properties)
|
|
625
647
|
@feature_flags_poller.get_all_flags(distinct_id, groups, person_properties, group_properties,
|
|
@@ -657,6 +679,8 @@ module PostHog
|
|
|
657
679
|
'instead — this consolidates flag evaluation into a single `/flags` request per ' \
|
|
658
680
|
'incoming request.'
|
|
659
681
|
)
|
|
682
|
+
return nil if @disabled
|
|
683
|
+
|
|
660
684
|
key = key.to_s
|
|
661
685
|
person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
|
|
662
686
|
person_properties, group_properties)
|
|
@@ -683,6 +707,8 @@ module PostHog
|
|
|
683
707
|
group_properties: {},
|
|
684
708
|
only_evaluate_locally: false
|
|
685
709
|
)
|
|
710
|
+
return { featureFlags: {}, featureFlagPayloads: {} } if @disabled
|
|
711
|
+
|
|
686
712
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
687
713
|
distinct_id, groups, person_properties, group_properties
|
|
688
714
|
)
|
|
@@ -700,6 +726,8 @@ module PostHog
|
|
|
700
726
|
#
|
|
701
727
|
# @return [void]
|
|
702
728
|
def reload_feature_flags
|
|
729
|
+
return if @disabled
|
|
730
|
+
|
|
703
731
|
unless @personal_api_key
|
|
704
732
|
logger.error(
|
|
705
733
|
'You need to specify a personal_api_key to locally evaluate feature flags'
|
|
@@ -713,8 +741,8 @@ module PostHog
|
|
|
713
741
|
#
|
|
714
742
|
# @return [void]
|
|
715
743
|
def shutdown
|
|
716
|
-
self.class._decrement_instance_count(@api_key)
|
|
717
|
-
@feature_flags_poller
|
|
744
|
+
self.class._decrement_instance_count(@api_key) unless @disabled
|
|
745
|
+
@feature_flags_poller&.shutdown_poller
|
|
718
746
|
flush
|
|
719
747
|
if @sync_mode
|
|
720
748
|
@sync_lock.synchronize { @transport&.shutdown }
|
|
@@ -810,6 +838,8 @@ module PostHog
|
|
|
810
838
|
only_evaluate_locally: false,
|
|
811
839
|
send_feature_flag_events: true
|
|
812
840
|
)
|
|
841
|
+
return nil if @disabled
|
|
842
|
+
|
|
813
843
|
key = key.to_s
|
|
814
844
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
815
845
|
distinct_id, groups, person_properties, group_properties
|
|
@@ -875,6 +905,8 @@ module PostHog
|
|
|
875
905
|
#
|
|
876
906
|
# returns Boolean of whether the item was added to the queue.
|
|
877
907
|
def enqueue(action)
|
|
908
|
+
return false if @disabled
|
|
909
|
+
|
|
878
910
|
action = process_before_send(action)
|
|
879
911
|
return false if action.nil? || action.empty?
|
|
880
912
|
|
|
@@ -901,11 +933,6 @@ module PostHog
|
|
|
901
933
|
end
|
|
902
934
|
end
|
|
903
935
|
|
|
904
|
-
# private: Checks that the api_key is properly initialized
|
|
905
|
-
def check_api_key!
|
|
906
|
-
raise ArgumentError, 'API key must be initialized' if @api_key.nil?
|
|
907
|
-
end
|
|
908
|
-
|
|
909
936
|
def normalize_string_option(value, blank_as_nil: false)
|
|
910
937
|
return value unless value.is_a?(String)
|
|
911
938
|
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
module PostHog
|
|
4
4
|
# Interface for external caching of feature flag definitions.
|
|
5
5
|
#
|
|
6
|
-
# EXPERIMENTAL: This API may change in future minor version bumps.
|
|
7
|
-
#
|
|
8
6
|
# Enables multi-worker environments (Kubernetes, load-balanced servers,
|
|
9
7
|
# serverless functions) to share flag definitions via an external cache,
|
|
10
8
|
# reducing redundant API calls.
|
data/lib/posthog/version.rb
CHANGED