posthog-ruby 3.9.2 → 3.9.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 +4 -4
- data/lib/posthog/client.rb +42 -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: 89fab2ec7ac4caec58095c06aacdc2ccc4a283cec328672291bfbed58a8ebf31
|
|
4
|
+
data.tar.gz: 4a8a95003bb34a4ddbeee89c2cd3d41daf1d1df4026de52f2f776f04a5225fef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc3a513fabd5d515ae95bb716a58ea28ecb0b303db57ac91d50e0c0d14995af3da2de6a0f6a121cd0601e3e161535410f54b4b2fa765d858a89174cdbb067c94
|
|
7
|
+
data.tar.gz: a1528a5562c611c1a1a9115bd7bf64ac772f0cc2207c4a27326c44be4190221d168035e17954cc86d363f307f2c32ab079922ba7851326eae5bc27c6feed3415
|
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,10 @@ module PostHog
|
|
|
105
106
|
@feature_flags_poller = nil
|
|
106
107
|
@personal_api_key = opts[:personal_api_key]
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
logger.error('api_key is empty after trimming whitespace; check your project API key') if @api_key == ''
|
|
109
|
+
logger.error('api_key is missing or empty after trimming whitespace; check your project API key') if @disabled
|
|
110
110
|
|
|
111
111
|
# Warn when multiple clients are created with the same API key (can cause dropped events)
|
|
112
|
-
unless opts[:test_mode] || opts[:disable_singleton_warning]
|
|
112
|
+
unless @disabled || opts[:test_mode] || opts[:disable_singleton_warning]
|
|
113
113
|
previous_count = self.class._increment_instance_count(@api_key)
|
|
114
114
|
if previous_count >= 1
|
|
115
115
|
logger.warn(
|
|
@@ -121,16 +121,18 @@ module PostHog
|
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
@
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
unless @disabled
|
|
125
|
+
@feature_flags_poller =
|
|
126
|
+
FeatureFlagsPoller.new(
|
|
127
|
+
opts[:feature_flags_polling_interval],
|
|
128
|
+
opts[:personal_api_key],
|
|
129
|
+
@api_key,
|
|
130
|
+
opts[:host],
|
|
131
|
+
opts[:feature_flag_request_timeout_seconds] || Defaults::FeatureFlags::FLAG_REQUEST_TIMEOUT_SECONDS,
|
|
132
|
+
opts[:on_error],
|
|
133
|
+
flag_definition_cache_provider: opts[:flag_definition_cache_provider]
|
|
134
|
+
)
|
|
135
|
+
end
|
|
134
136
|
|
|
135
137
|
@distinct_id_has_sent_flag_calls = SizeLimitedHash.new(Defaults::MAX_HASH_SIZE) do |hash, key|
|
|
136
138
|
hash[key] = []
|
|
@@ -198,6 +200,8 @@ module PostHog
|
|
|
198
200
|
# @return [Boolean] Whether the event was queued or sent.
|
|
199
201
|
# @macro common_attrs
|
|
200
202
|
def capture(attrs)
|
|
203
|
+
return false if @disabled
|
|
204
|
+
|
|
201
205
|
symbolize_keys! attrs
|
|
202
206
|
enrich_capture_attrs_with_context(attrs)
|
|
203
207
|
|
|
@@ -226,7 +230,7 @@ module PostHog
|
|
|
226
230
|
end
|
|
227
231
|
|
|
228
232
|
send_feature_flags_param = attrs[:send_feature_flags]
|
|
229
|
-
if send_feature_flags_param
|
|
233
|
+
if send_feature_flags_param && !@disabled
|
|
230
234
|
_emit_deprecation(
|
|
231
235
|
:capture_send_feature_flags,
|
|
232
236
|
'`send_feature_flags` on `capture` is deprecated and will be removed in a future major ' \
|
|
@@ -388,6 +392,8 @@ module PostHog
|
|
|
388
392
|
# @param flag_key [String, Symbol] The unique flag key of the remote config feature flag.
|
|
389
393
|
# @return [Hash] The parsed remote config payload response.
|
|
390
394
|
def get_remote_config_payload(flag_key)
|
|
395
|
+
return nil if @disabled
|
|
396
|
+
|
|
391
397
|
@feature_flags_poller.get_remote_config_payload(flag_key.to_s)
|
|
392
398
|
end
|
|
393
399
|
|
|
@@ -465,6 +471,8 @@ module PostHog
|
|
|
465
471
|
'`flags.get_flag_payload(key)` instead — this consolidates flag evaluation into a single ' \
|
|
466
472
|
'`/flags` request per incoming request.'
|
|
467
473
|
)
|
|
474
|
+
return nil if @disabled
|
|
475
|
+
|
|
468
476
|
_get_feature_flag_result(
|
|
469
477
|
key, distinct_id,
|
|
470
478
|
groups: groups, person_properties: person_properties, group_properties: group_properties,
|
|
@@ -507,6 +515,8 @@ module PostHog
|
|
|
507
515
|
return FeatureFlagEvaluations.new(host: host, distinct_id: '', flags: {})
|
|
508
516
|
end
|
|
509
517
|
|
|
518
|
+
return FeatureFlagEvaluations.new(host: host, distinct_id: distinct_id, flags: {}, groups: groups) if @disabled
|
|
519
|
+
|
|
510
520
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
511
521
|
distinct_id, groups, person_properties, group_properties
|
|
512
522
|
)
|
|
@@ -620,6 +630,8 @@ module PostHog
|
|
|
620
630
|
group_properties: {},
|
|
621
631
|
only_evaluate_locally: false
|
|
622
632
|
)
|
|
633
|
+
return {} if @disabled
|
|
634
|
+
|
|
623
635
|
person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
|
|
624
636
|
person_properties, group_properties)
|
|
625
637
|
@feature_flags_poller.get_all_flags(distinct_id, groups, person_properties, group_properties,
|
|
@@ -657,6 +669,8 @@ module PostHog
|
|
|
657
669
|
'instead — this consolidates flag evaluation into a single `/flags` request per ' \
|
|
658
670
|
'incoming request.'
|
|
659
671
|
)
|
|
672
|
+
return nil if @disabled
|
|
673
|
+
|
|
660
674
|
key = key.to_s
|
|
661
675
|
person_properties, group_properties = add_local_person_and_group_properties(distinct_id, groups,
|
|
662
676
|
person_properties, group_properties)
|
|
@@ -683,6 +697,8 @@ module PostHog
|
|
|
683
697
|
group_properties: {},
|
|
684
698
|
only_evaluate_locally: false
|
|
685
699
|
)
|
|
700
|
+
return { featureFlags: {}, featureFlagPayloads: {} } if @disabled
|
|
701
|
+
|
|
686
702
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
687
703
|
distinct_id, groups, person_properties, group_properties
|
|
688
704
|
)
|
|
@@ -700,6 +716,8 @@ module PostHog
|
|
|
700
716
|
#
|
|
701
717
|
# @return [void]
|
|
702
718
|
def reload_feature_flags
|
|
719
|
+
return if @disabled
|
|
720
|
+
|
|
703
721
|
unless @personal_api_key
|
|
704
722
|
logger.error(
|
|
705
723
|
'You need to specify a personal_api_key to locally evaluate feature flags'
|
|
@@ -713,8 +731,8 @@ module PostHog
|
|
|
713
731
|
#
|
|
714
732
|
# @return [void]
|
|
715
733
|
def shutdown
|
|
716
|
-
self.class._decrement_instance_count(@api_key)
|
|
717
|
-
@feature_flags_poller
|
|
734
|
+
self.class._decrement_instance_count(@api_key) unless @disabled
|
|
735
|
+
@feature_flags_poller&.shutdown_poller
|
|
718
736
|
flush
|
|
719
737
|
if @sync_mode
|
|
720
738
|
@sync_lock.synchronize { @transport&.shutdown }
|
|
@@ -810,6 +828,8 @@ module PostHog
|
|
|
810
828
|
only_evaluate_locally: false,
|
|
811
829
|
send_feature_flag_events: true
|
|
812
830
|
)
|
|
831
|
+
return nil if @disabled
|
|
832
|
+
|
|
813
833
|
key = key.to_s
|
|
814
834
|
person_properties, group_properties = add_local_person_and_group_properties(
|
|
815
835
|
distinct_id, groups, person_properties, group_properties
|
|
@@ -875,6 +895,8 @@ module PostHog
|
|
|
875
895
|
#
|
|
876
896
|
# returns Boolean of whether the item was added to the queue.
|
|
877
897
|
def enqueue(action)
|
|
898
|
+
return false if @disabled
|
|
899
|
+
|
|
878
900
|
action = process_before_send(action)
|
|
879
901
|
return false if action.nil? || action.empty?
|
|
880
902
|
|
|
@@ -901,11 +923,6 @@ module PostHog
|
|
|
901
923
|
end
|
|
902
924
|
end
|
|
903
925
|
|
|
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
926
|
def normalize_string_option(value, blank_as_nil: false)
|
|
910
927
|
return value unless value.is_a?(String)
|
|
911
928
|
|
|
@@ -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