Created
July 11, 2021 04:52
-
-
Save hellodit/4eb63a2755d6123c47e8407be4999d65 to your computer and use it in GitHub Desktop.
Golang APM with Elastic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"net/http" | |
"time" | |
"github.com/labstack/echo/v4" | |
"github.com/labstack/echo/v4/middleware" | |
"go.elastic.co/apm" | |
"go.elastic.co/apm/module/apmechov4" | |
) | |
type Post struct { | |
UserID int `json:"userId"` | |
ID int `json:"id"` | |
Title string `json:"title"` | |
Body string `json:"body"` | |
} | |
func main() { | |
e := echo.New() | |
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ | |
Format: "method=${method}, uri=${uri}, status=${status}\n", | |
})) | |
e.Use(apmechov4.Middleware()) | |
e.GET("/", func(c echo.Context) error { | |
return c.String(http.StatusOK, "Hello, World!") | |
}) | |
e.GET("/posts", fetchPostsHandler) | |
e.Logger.Fatal(e.Start(":1323")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment