1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GitLab の Error Tracking を試してみる

Last updated at Posted at 2019-06-18

はじめに

GitLab 11.8 で導入された Error Tracking 機能を試してみました。
Error Tracking は、アプリケーションで発生したエラーを発見しやすく・確認しやすくするための機能で、 OSS のエラートラッキングシステムである Sentry と GitLab を連携させることで実現できます。

前提となる環境

Sentry にプロジェクトを作成

ここはさらっと。

  1. Create Project > Rails を選択します
  2. プロジェクト名とチームを入力して Create Project

Rails アプリに Sentry をインストール

Gemfilesentry-raven を追加します。

Gemfile
gem "sentry-raven"
$ bundle

config/application.rb にデータソース名を設定します。
実際には dotenv とかを使って環境変数として設定するのがよいと思います。

config/application.rb
Raven.configure do |config|
  config.dsn = 'https://xxx@sentry.io/xxx'
end

パラメータとセッション情報を取得するための設定をします。

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_action :set_raven_context

  private

  def set_raven_context
    Raven.user_context(id: session[:user_id])
    Raven.extra_context(params: params.to_unsafe_h, url: request.url)
  end
end

Sentry の Auth Token 取得

  1. Settings > Account > API > Auth Tokens > Create New Token
  2. event:readproject:read にチェックを入れて Create Token

生成された Token は次で使います。

スクリーンショット 2019-06-18 21.12.33.png

GitLab から Sentry へ接続

  1. Settings > Operations > Error Tracking > Expand
  2. Active にチェックを入れます
  3. 各項目を入力して、 Connect
    • Sentry API URL : https://sentry.io
    • Auth Token : 先ほど取得した Auth Token
  4. 接続に成功したら、 Project のドロップダウンから作成したプロジェクトを選択して Save

これで、 GitLab の Operations > Error Tracking からエラーのリストを確認できるようになります。
試しに Sentry から sample event を発生させてみると ↓ の感じになりました。
GitLab で確認できるのはエラーのリストまでで、各エラーの詳細を確認するには Sentry で見る必要があるようです。

スクリーンショット 2019-06-18 22.15.23.png

Sentry で見てみると ↓ な感じです。

スクリーンショット 2019-06-18 21.26.52.png

参考文献

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?