debian-mirror-gitlab/lib/gitlab/tracking.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
3.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Gitlab
module Tracking
class << self
def enabled?
2022-08-13 15:12:31 +05:30
tracker.enabled?
2019-12-04 20:38:33 +05:30
end
2021-04-29 21:17:54 +05:30
def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
2023-06-20 00:43:36 +05:30
action = action.to_s
contexts = [
Tracking::StandardContext.new(
project: project,
user: user,
namespace: namespace,
**extra).to_context, *context
]
track_struct_event(tracker, category, action, label: label, property: property, value: value, contexts: contexts)
end
2021-03-08 18:12:59 +05:30
2023-06-20 00:43:36 +05:30
def database_event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
2022-10-11 01:57:18 +05:30
action = action.to_s
2023-06-20 00:43:36 +05:30
destination = Gitlab::Tracking::Destinations::DatabaseEventsSnowplow.new
contexts = [
Tracking::StandardContext.new(
project: project,
user: user,
namespace: namespace,
**extra).to_context, *context
]
2022-10-11 01:57:18 +05:30
2023-06-20 00:43:36 +05:30
track_struct_event(destination, category, action, label: label, property: property, value: value, contexts: contexts)
2019-12-21 20:55:43 +05:30
end
2022-06-21 17:19:12 +05:30
def definition(basename, category: nil, action: nil, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
definition = YAML.load_file(Rails.root.join("config/events/#{basename}.yml"))
dispatch_from_definition(definition, label: label, property: property, value: value, context: context, project: project, user: user, namespace: namespace, **extra)
end
def dispatch_from_definition(definition, **event_data)
definition = definition.with_indifferent_access
category ||= definition[:category]
action ||= definition[:action]
event(category, action, **event_data)
end
2021-11-11 11:23:49 +05:30
def options(group)
2022-08-13 15:12:31 +05:30
tracker.options(group)
2021-12-11 22:18:48 +05:30
end
def collector_hostname
2022-08-13 15:12:31 +05:30
tracker.hostname
2019-12-04 20:38:33 +05:30
end
2022-01-26 12:08:38 +05:30
def snowplow_micro_enabled?
2022-08-13 15:12:31 +05:30
Rails.env.development? && Gitlab.config.snowplow_micro.enabled
rescue Settingslogic::MissingSetting
2022-08-27 11:52:29 +05:30
false
2022-01-26 12:08:38 +05:30
end
2019-12-04 20:38:33 +05:30
private
2023-06-20 00:43:36 +05:30
def track_struct_event(destination, category, action, label:, property:, value:, contexts:) # rubocop:disable Metrics/ParameterLists
destination
.event(category, action, label: label, property: property, value: value, context: contexts)
rescue StandardError => error
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end
2022-08-13 15:12:31 +05:30
def tracker
@tracker ||= if snowplow_micro_enabled?
Gitlab::Tracking::Destinations::SnowplowMicro.new
else
Gitlab::Tracking::Destinations::Snowplow.new
end
2020-11-24 15:15:51 +05:30
end
2019-12-04 20:38:33 +05:30
end
end
end
2022-06-21 17:19:12 +05:30
Gitlab::Tracking.prepend_mod_with('Gitlab::Tracking')