Commit a359ac57 authored by Dmitriy Zaporozhets (DZ)'s avatar Dmitriy Zaporozhets (DZ)

Merge branch 'dz-integrated-error-tracking-error-creation' into 'master'

Improve error reporting for integrated tracking

See merge request gitlab-org/gitlab!68952
parents 9416e05b 7fa6307f
...@@ -22,11 +22,15 @@ class ErrorTracking::Error < ApplicationRecord ...@@ -22,11 +22,15 @@ class ErrorTracking::Error < ApplicationRecord
def self.report_error(name:, description:, actor:, platform:, timestamp:) def self.report_error(name:, description:, actor:, platform:, timestamp:)
safe_find_or_create_by( safe_find_or_create_by(
name: name, name: name,
description: description,
actor: actor, actor: actor,
platform: platform platform: platform
) do |error| ).tap do |error|
error.update!(last_seen_at: timestamp) error.update!(
# Description can contain object id, so it can't be
# used as a group criteria for similar errors.
description: description,
last_seen_at: timestamp
)
end end
end end
......
...@@ -18,7 +18,7 @@ module ErrorTracking ...@@ -18,7 +18,7 @@ module ErrorTracking
# Together with occured_at these are 2 main attributes that we need to save here. # Together with occured_at these are 2 main attributes that we need to save here.
error.events.create!( error.events.create!(
environment: event['environment'], environment: event['environment'],
description: exception['type'], description: exception['value'],
level: event['level'], level: event['level'],
occurred_at: event['timestamp'], occurred_at: event['timestamp'],
payload: event payload: event
......
# frozen_string_literal: true
class ChangeDescriptionLimitErrorTrackingEvent < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
def up
remove_text_limit :error_tracking_error_events, :description
add_text_limit :error_tracking_error_events, :description, 1024
end
def down
remove_text_limit :error_tracking_error_events, :description
add_text_limit :error_tracking_error_events, :description, 255
end
end
ab678fb5e8ddf7e6dc84f36248440e94953d7c85ee6a50f4e5c06f32c6ee66ec
\ No newline at end of file
...@@ -12929,7 +12929,7 @@ CREATE TABLE error_tracking_error_events ( ...@@ -12929,7 +12929,7 @@ CREATE TABLE error_tracking_error_events (
payload jsonb DEFAULT '{}'::jsonb NOT NULL, payload jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL,
CONSTRAINT check_92ecc3077b CHECK ((char_length(description) <= 255)), CONSTRAINT check_92ecc3077b CHECK ((char_length(description) <= 1024)),
CONSTRAINT check_c67d5b8007 CHECK ((char_length(level) <= 255)), CONSTRAINT check_c67d5b8007 CHECK ((char_length(level) <= 255)),
CONSTRAINT check_f4b52474ad CHECK ((char_length(environment) <= 255)) CONSTRAINT check_f4b52474ad CHECK ((char_length(environment) <= 255))
); );
...@@ -16,6 +16,24 @@ RSpec.describe ErrorTracking::Error, type: :model do ...@@ -16,6 +16,24 @@ RSpec.describe ErrorTracking::Error, type: :model do
it { is_expected.to validate_presence_of(:actor) } it { is_expected.to validate_presence_of(:actor) }
end end
describe '.report_error' do
it 'updates existing record with a new timestamp' do
timestamp = Time.zone.now
reported_error = described_class.report_error(
name: error.name,
description: 'Lorem ipsum',
actor: error.actor,
platform: error.platform,
timestamp: timestamp
)
expect(reported_error.id).to eq(error.id)
expect(reported_error.last_seen_at).to eq(timestamp)
expect(reported_error.description).to eq('Lorem ipsum')
end
end
describe '#title' do describe '#title' do
it { expect(error.title).to eq('ActionView::MissingTemplate Missing template posts/edit') } it { expect(error.title).to eq('ActionView::MissingTemplate Missing template posts/edit') }
end end
......
...@@ -34,7 +34,7 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -34,7 +34,7 @@ RSpec.describe ErrorTracking::CollectErrorService do
expect(error.platform).to eq 'ruby' expect(error.platform).to eq 'ruby'
expect(error.last_seen_at).to eq '2021-07-08T12:59:16Z' expect(error.last_seen_at).to eq '2021-07-08T12:59:16Z'
expect(event.description).to eq 'ActionView::MissingTemplate' expect(event.description).to start_with 'Missing template posts/error2'
expect(event.occurred_at).to eq '2021-07-08T12:59:16Z' expect(event.occurred_at).to eq '2021-07-08T12:59:16Z'
expect(event.level).to eq 'error' expect(event.level).to eq 'error'
expect(event.environment).to eq 'development' expect(event.environment).to eq 'development'
......
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