Help us understand the problem. What is going on with this article?

Go+Echoの環境にNewRelicを導入する

More than 1 year has passed since last update.

Echoのmiddlewareを使ってNewRelicを導入する方法を紹介します。
自分のメモ用に書いているので深い解説は載せていません。

下準備

NewRelic でアカウントを作って
ライセンスキーをメモっておきます。

やり方

echo-middlewareを使います.
https://github.com/dafiti/echo-middleware
型定義を参考に書いていきます。

main.go
package main


import (
    "github.com/labstack/echo"
    "github.com/labstack/echo/middleware"
    mw "github.com/dafiti/echo-middleware"
    "github.com/newrelic/go-agent"
)

func handler(c echo.Context) error {
    return c.JSON(http.StatusOK, nil)
}

func main() {
    // Echo初期化
    e := echo.New()

    // Middleware初期化
    nrConf := newrelic.NewConfig("アプリ名", "ライセンスキー")
    newRelicApp, err := newrelic.NewApplication(nrConf)
    if err != nil {
        panic(err)
    }

    e.Use(mw.NewRelicWithApplication(newRelicApp))

    e.GET("/sample", handler)

    start := e.Start(":80")
    e.Logger.Fatal(start)
}

立ち上げる。

$ go run main.go

これでhttp://localhost:80/sampleにリクエストを投げてみて、
NewRelicの管理画面で処理時間などのメトリクスが確認できればOKです。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away