Commit 05c4cd32 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'ali/rescue-snowplow-failures' into 'master'

Rescue errors when emitting Snowplow events

See merge request gitlab-org/gitlab!56607
parents 0d4008ff f8f00f00
...@@ -14,6 +14,8 @@ module Gitlab ...@@ -14,6 +14,8 @@ module Gitlab
snowplow.event(category, action, label: label, property: property, value: value, context: contexts) snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
product_analytics.event(category, action, label: label, property: property, value: value, context: contexts) product_analytics.event(category, action, label: label, property: property, value: value, context: contexts)
rescue => error
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end end
def self_describing_event(schema_url, data:, context: nil) def self_describing_event(schema_url, data:, context: nil)
......
...@@ -36,12 +36,12 @@ RSpec.describe Gitlab::Tracking do ...@@ -36,12 +36,12 @@ RSpec.describe Gitlab::Tracking do
end end
describe '.event' do describe '.event' do
before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
end
shared_examples 'delegates to destination' do |klass| shared_examples 'delegates to destination' do |klass|
before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
end
it "delegates to #{klass} destination" do it "delegates to #{klass} destination" do
other_context = double(:context) other_context = double(:context)
...@@ -70,8 +70,17 @@ RSpec.describe Gitlab::Tracking do ...@@ -70,8 +70,17 @@ RSpec.describe Gitlab::Tracking do
end end
end end
include_examples 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
include_examples 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics
it 'tracks errors' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(
an_instance_of(ContractError),
snowplow_category: nil, snowplow_action: 'some_action'
)
described_class.event(nil, 'some_action')
end
end end
describe '.self_describing_event' do describe '.self_describing_event' do
......
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