Commit fea0d8f2 authored by alinamihaila's avatar alinamihaila

Rescue any exception when tracking

  - The application flow should not be
  blocked by erros in tracking
  - Ignore exceptions unless dev or test
  environments
parent 671bfebb
......@@ -132,6 +132,10 @@ module Gitlab
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
......
......@@ -154,6 +154,13 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment