diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /lib/gitlab/tracking | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'lib/gitlab/tracking')
-rw-r--r-- | lib/gitlab/tracking/destinations/base.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/tracking/destinations/snowplow.rb | 49 |
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/tracking/destinations/base.rb b/lib/gitlab/tracking/destinations/base.rb new file mode 100644 index 00000000000..00e92e0bd57 --- /dev/null +++ b/lib/gitlab/tracking/destinations/base.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Gitlab + module Tracking + module Destinations + class Base + def event(category, action, label: nil, property: nil, value: nil, context: nil) + raise NotImplementedError, "#{self} does not implement #{__method__}" + end + end + end + end +end diff --git a/lib/gitlab/tracking/destinations/snowplow.rb b/lib/gitlab/tracking/destinations/snowplow.rb new file mode 100644 index 00000000000..9cebcfe5ee1 --- /dev/null +++ b/lib/gitlab/tracking/destinations/snowplow.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'snowplow-tracker' + +module Gitlab + module Tracking + module Destinations + class Snowplow < Base + extend ::Gitlab::Utils::Override + + override :event + def event(category, action, label: nil, property: nil, value: nil, context: nil) + return unless enabled? + + tracker.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i) + end + + def self_describing_event(schema_url, event_data_json, context: nil) + return unless enabled? + + event_json = SnowplowTracker::SelfDescribingJson.new(schema_url, event_data_json) + tracker.track_self_describing_event(event_json, context, (Time.now.to_f * 1000).to_i) + end + + private + + def enabled? + Gitlab::CurrentSettings.snowplow_enabled? + end + + def tracker + @tracker ||= SnowplowTracker::Tracker.new( + emitter, + SnowplowTracker::Subject.new, + Gitlab::Tracking::SNOWPLOW_NAMESPACE, + Gitlab::CurrentSettings.snowplow_app_id + ) + end + + def emitter + SnowplowTracker::AsyncEmitter.new( + Gitlab::CurrentSettings.snowplow_collector_hostname, + protocol: 'https' + ) + end + end + end + end +end |