Skip to content

Commit 4523496

Browse files
authored
fix: Mute analytics processor on failure (#57)
* Add logger * Add try catch guard for analytics processor * Add logger * Fix silly lint
1 parent 542aea2 commit 4523496

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/flagsmith.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def analytics_processor
9292
@analytics_processor ||=
9393
Flagsmith::AnalyticsProcessor.new(
9494
api_client: api_client,
95-
timeout: request_timeout_seconds
95+
timeout: request_timeout_seconds,
96+
logger: @config.logger
9697
)
9798
end
9899

lib/flagsmith/sdk/analytics_processor.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ def initialize(data)
1919
@analytics_data = {}
2020
@api_client = data.fetch(:api_client)
2121
@timeout = data.fetch(:timeout, 3)
22+
@logger = data.fetch(:logger)
2223
end
2324

2425
# Sends all the collected data to the api asynchronously and resets the timer
2526
def flush
2627
return if @analytics_data.empty?
2728

28-
@api_client.post(ENDPOINT, @analytics_data.to_json)
29+
begin
30+
@api_client.post(ENDPOINT, @analytics_data.to_json)
31+
@analytics_data = {}
32+
rescue StandardError => e
33+
@logger.warn "Temporarily unable to access flag analytics endpoint for exception: #{e}"
34+
end
2935

30-
@analytics_data = {}
3136
@last_flushed = Time.now
3237
end
3338

spec/sdk/analytics_processor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515

1616
subject do Flagsmith::AnalyticsProcessor.new(
17-
api_client: flagsmith.api_client, timeout: flagsmith.config.request_timeout_seconds
17+
api_client: flagsmith.api_client, timeout: flagsmith.config.request_timeout_seconds, logger: flagsmith.config.logger
1818
)
1919
end
2020

0 commit comments

Comments
 (0)