Skip to content

Instantly share code, notes, and snippets.

@hellodit
Created July 11, 2021 04:52
Show Gist options
  • Save hellodit/4eb63a2755d6123c47e8407be4999d65 to your computer and use it in GitHub Desktop.
Save hellodit/4eb63a2755d6123c47e8407be4999d65 to your computer and use it in GitHub Desktop.
Golang APM with Elastic
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