Class: Gitlab::ErrorTracking::ErrorRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/error_tracking/error_repository.rb,
lib/gitlab/error_tracking/error_repository/open_api_strategy.rb

Overview

Data access layer for errors and events related to Error Tracking feature.

Defined Under Namespace

Classes: OpenApiStrategy, Pagination

Constant Summary collapse

DatabaseError =

Generic database error

Class.new(StandardError)
RecordInvalidError =

Record was invalid

Class.new(DatabaseError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy) ⇒ ErrorRepository

Returns a new instance of ErrorRepository.



24
25
26
# File 'lib/gitlab/error_tracking/error_repository.rb', line 24

def initialize(strategy)
  @strategy = strategy
end

Class Method Details

.build(project) ⇒ self

Builds an instance of error repository backed by a strategy.

Returns:

  • (self)


17
18
19
20
21
# File 'lib/gitlab/error_tracking/error_repository.rb', line 17

def self.build(project)
  strategy = OpenApiStrategy.new(project)

  new(strategy)
end

Instance Method Details

#dsn_url(public_key) ⇒ Object



109
110
111
# File 'lib/gitlab/error_tracking/error_repository.rb', line 109

def dsn_url(public_key)
  strategy.dsn_url(public_key)
end

#find_error(id) ⇒ Gitlab::ErrorTracking::DetailedError

Finds an error by id.

Parameters:

  • id (Integer, String)

    unique error identifier

Returns:



66
67
68
# File 'lib/gitlab/error_tracking/error_repository.rb', line 66

def find_error(id)
  strategy.find_error(id)
end

#last_event_for(id) ⇒ Gitlab::ErrorTracking::ErrorEvent

Fetches last event for error id.

Parameters:

  • id (Integer, String)

    unique error identifier

Returns:

Raises:



93
94
95
# File 'lib/gitlab/error_tracking/error_repository.rb', line 93

def last_event_for(id)
  strategy.last_event_for(id)
end

#list_errors(sort: 'last_seen', filters: {}, query: nil, limit: 20, cursor: {}) ⇒ Array<Array<Gitlab::ErrorTracking::Error>, Pagination>

Lists errors.

Parameters:

  • sort (String) (defaults to: 'last_seen')

    order list by ‘first_seen’, ‘last_seen’, or ‘frequency’

  • filters (Hash<Symbol, String>) (defaults to: {})

    filter list by

  • limit (Integer, String) (defaults to: 20)

    limit result

  • cursor (Hash) (defaults to: {})

    pagination information

Options Hash (filters:):

  • :status (String)

    error status

Returns:



80
81
82
83
84
# File 'lib/gitlab/error_tracking/error_repository.rb', line 80

def list_errors(sort: 'last_seen', filters: {}, query: nil, limit: 20, cursor: {})
  limit = [limit.to_i, 100].min

  strategy.list_errors(filters: filters, query: query, sort: sort, limit: limit, cursor: cursor)
end

#report_error(name:, description:, actor:, platform:, environment:, level:, occurred_at: Time.zone.now, payload: {}) ⇒ void

This method returns an undefined value.

Stores an error and the related error event.

Parameters:

  • name (String)

    name of the error

  • description (String)

    description of the error

  • actor (String)

    culprit (class/method/function) which triggered this error

  • platform (String)

    platform on which the error occurred

  • environment (String)

    environment on which the error occurred

  • level (String)

    severity of this error

  • occurred_at (Time) (defaults to: Time.zone.now)

    timestamp when the error occurred

  • payload (Hash) (defaults to: {})

    original error payload

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/error_tracking/error_repository.rb', line 43

def report_error(
  name:, description:, actor:, platform:,
  environment:, level:, occurred_at: Time.zone.now, payload: {}
)
  strategy.report_error(
    name: name,
    description: description,
    actor: actor,
    platform: platform,
    environment: environment,
    level: level,
    occurred_at: occurred_at,
    payload: payload
  )

  nil
end

#update_error(id, status:) ⇒ true, false

Updates attributes of an error.

Parameters:

  • id (Integer, String)

    unique error identifier

  • status (String)

    error status

Returns:

  • (true, false)

    if update was successful

Raises:



105
106
107
# File 'lib/gitlab/error_tracking/error_repository.rb', line 105

def update_error(id, status:)
  strategy.update_error(id, status: status)
end