Git Product home page Git Product logo

play2-sentry's Introduction

Play2向け Sentryログ出力サポート

Play2においてSentryへのログ出力にHTTPリクエストの内容を記録させるためのモジュールです。
Play2では、Java Servletとは違う独自の構造でHTTPリクエスト情報を保持しているため、それをSentry向けに変換する必要があります、

また、1リクエスト内でもマルチスレッドで処理することが多いため、スレッド内でのログにリクエスト情報を付与するためにはスレッド間でリクエスト情報を共有する必要があります。

これらに対処するため、本モジュールでは主に以下のことを行っています。

  • PlayのHTTPリクエスト情報をSentryに送信するためのフォーマット変換処理を実装
  • 本モジュールを有効化したSentryClientを生成するための独自SentryClientFactoryを定義
  • Playのリクエスト情報をスレッドローカル変数に保存するためのフィルタを定義
  • Akkaでのスレッド起動時に、HTTP情報を持つスレッドローカル変数とlogbackのMDCを引き継ぐようにする処理を追加

使い方

本モジュールの導入方法は以下のとおりです。

  1. Playアプリの依存に追加する
libraryDependencies ++= Seq(
    "com.m3.play2" % "play2-sentry" % "1.0.0-SNAPSHOT"
)
  1. sentry設定でfactoryを指定する

sentry.properties

factory=com.m3.play2.sentry.PlaySentryFactory
  1. Akkaのデフォルトdispatcherを本モジュールのクラスに指定する

application.conf

play {
  akka {
    actor {
      default-dispatcher = {
        // Dispatcherを指定する
        type = "com.m3.play2.sentry.SentryDispatcherConfigurator"
      }
    }
  }
}
  1. HTTPフィルタにSentryLoggingFilterを追加
import com.m3.play2.sentry.SentryLoggingFilter

class ApplicationComponents(context: Context) extends BuiltInComponentsFromContext(context) {
  // filter を追加
  override lazy val httpFilters = Seq(
    new SentryLoggingFilter()
  )
}
  1. Sentryの標準的な導入設定を行う

参考: https://docs.sentry.io/clients/java/

  • ログ出力設定でSentryAppenderを指定する
  • アプリケーション固有のパッケージ名を明記
  • etc...

本モジュールの開発方法

ビルド

$ sbt package

ローカル環境での動作確認

  1. モジュールをivyのローカルキャッシュにインストールする
$ sbt publishLocal
  1. 動作確認用Playアプリで、resolvers にローカルキャッシュディレクトリを追加する

build.sbt

resolvers += "MyLocalIvy" at "file://"+Path.userHome.absolutePath+"/.ivy2/local"
  1. アプリに組み込む

  2. アプリを実行する

artifactory にデプロイ

以下のコマンドでartifactoryにjarを登録します

$ export REPOSITORY_URL={{デプロイ先のartifactoryのURL}}
$ sbt clean package publish

play2-sentry's People

Contributors

bloodysnowx avatar namutaka avatar seratch avatar tak-nakamura-m3 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

play2-sentry's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.