0
3

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.

GoでNewRelicまわり

Posted at

基本

公式参照

Go 用 New Relic のインストール | Degica x New Relic (New Relic 日本代理店)
https://newrelic.degica.com/docs/agents/go-agent/get-started/get-new-relic-go

smacker/newrelic-context

httpのContextベースでトランザクションを設定して、RDBやRedis等のセグメント計測を行ってくれる。便利。

gorm.DBredis.Clientインスタンスをcontextを使ってWrapする必要があるので予め想定したアーキテクチャにしておく。

gocraft/work用middleware

func NewrelicJobQueueMiddleware(appname, license string) (work.GenericMiddlewareHandler, error) {
	app, err := newrelic.NewApplication(newrelic.NewConfig(appname, license))
	if err != nil {
		return nil, err
	}
	return func(job *work.Job, next work.NextMiddlewareFunc) error {
		txn := app.StartTransaction(job.Name, nil, nil)
		defer txn.End()

		return next()
	}, nil
}

//...

nm, _ := NewrelicJobQueueMiddleware("your_app", "YOUR_LICENSE")
pool.Middleware(nm)
0
3
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
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?