diff --git a/lib/gitlab/usage_data_counters/hll_redis_counter.rb b/lib/gitlab/usage_data_counters/hll_redis_counter.rb index 5cb202913c750c6ff8309316d5a75f0d220d1702..336bef081a6dbfb0ee76d3e23327aac594fb87d9 100644 --- a/lib/gitlab/usage_data_counters/hll_redis_counter.rb +++ b/lib/gitlab/usage_data_counters/hll_redis_counter.rb @@ -132,6 +132,10 @@ def track(values, event_name, context: '', time: Time.zone.now) return unless feature_enabled?(event) Gitlab::Redis::HLL.add(key: redis_key(event, time, context), value: values, expiry: expiry(event)) + rescue => e + # Ignore any exceptions unless is dev or test env + # The application flow should not be blocked by erros in tracking + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) end # The array of valid context on which we allow tracking diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 41e63e80649c3691d93247ee4baf92b04d843c44..8aaa7c055b67ce708ddfb59110549745fcc669db 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -154,6 +154,13 @@ expect { described_class.track_event('unknown', values: entity1, time: Date.current) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent) end + it 'reports an error if Feature.enabled raise an error' do + expect(Feature).to receive(:enabled?).and_raise(StandardError.new) + expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception) + + described_class.track_event(:g_analytics_contribution, values: entity1, time: Date.current) + end + context 'for weekly events' do it 'sets the keys in Redis to expire automatically after the given expiry time' do described_class.track_event("g_analytics_contribution", values: entity1)