Class: Gitlab::ErrorTracking::ErrorRepository::OpenApiStrategy

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

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ OpenApiStrategy

Returns a new instance of OpenApiStrategy.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 7

def initialize(project)
  @project = project

  api_url = configured_api_url

  open_api.configure do |config|
    config.scheme = api_url.scheme
    config.host = [api_url.host, api_url.port].compact.join(':')
    config.server_index = nil
    config.api_key['internalToken'] = api_key
    config.logger = Gitlab::AppLogger
  end
end

Instance Method Details

#dsn_url(public_key) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 92

def dsn_url(public_key)
  config = open_api::Configuration.default

  base_url = [
    config.scheme,
    "://",
    public_key,
    '@',
    config.host,
    config.base_path
  ].join('')

  "#{base_url}/projects/#{project_id}"
end

#find_error(id) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 28

def find_error(id)
  api = build_api_client
  error = api.get_error(project_id, id)

  to_sentry_detailed_error(error)
rescue ErrorTrackingOpenAPI::ApiError => e
  log_exception(e)
  nil
end

#last_event_for(id) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 64

def last_event_for(id)
  event = newest_event_for(id)
  return unless event

  api = build_api_client
  error = api.get_error(project_id, id)
  return unless error

  to_sentry_error_event(event, error)
rescue ErrorTrackingOpenAPI::ApiError => e
  log_exception(e)
  nil
end

#list_errors(filters:, query:, sort:, limit:, cursor:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 38

def list_errors(filters:, query:, sort:, limit:, cursor:)
  opts = {
    sort: "#{sort}_desc",
    status: filters[:status],
    query: query,
    cursor: cursor,
    limit: limit
  }.compact

  api = build_api_client
  errors, _status, headers = api.list_errors_with_http_info(project_id, opts)
  pagination = pagination_from_headers(headers)

  if errors.size < limit
    # Don't show next link if amount of errors is less then requested.
    # This a workaround until the Golang backend returns link cursor
    # only if there is a next page.
    pagination.next = nil
  end

  [errors.map { to_sentry_error(_1) }, pagination]
rescue ErrorTrackingOpenAPI::ApiError => e
  log_exception(e)
  [[], ErrorRepository::Pagination.new]
end

#report_error(name:, description:, actor:, platform:, environment:, level:, occurred_at:, payload:) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
24
25
26
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 21

def report_error(
  name:, description:, actor:, platform:,
  environment:, level:, occurred_at:, payload:
)
  raise NotImplementedError, 'Use ingestion endpoint'
end

#update_error(id, **attributes) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gitlab/error_tracking/error_repository/open_api_strategy.rb', line 78

def update_error(id, **attributes)
  opts = attributes.slice(:status)

  body = open_api::ErrorUpdatePayload.new(opts)

  api = build_api_client
  api.update_error(project_id, id, body)

  true
rescue ErrorTrackingOpenAPI::ApiError => e
  log_exception(e)
  false
end