Skip to main content

Go Agent v0.1.7

Release date: 2022-01-04

Beta - update

The database/SQL library is supported.

Use the whatapsql.OpenContext function instead of the sql.Open function from the database/sql package. It is recommended to use the functions that pass the context, such as PrepareContext, QueryContext, and ExecContext.

The context to be delivered must have the whatap TraceCtx data through trace.Start().

Install guide

import (
_ "github.com/go-sql-driver/mysql"
"github.com/whatap/go-api/instrumentation/database/sql/whatapsql"
)

func main() {
config := make(map[string]string)
trace.Init(config)
defer trace.Shutdown()

// Create the whatap TraceCtx inside whataphttp.Func.
http.HandleFunc("/query", whataphttp.Func(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

// Use the WhaTap driver. Deliver the context where the whatap's TraceCtx exists.
db, err := whatapsql.OpenContext(ctx, "mysql", dataSource)
if err != nil {
fmt.Println("Error whatapsql.Open ", err)
return
}
defer db.Close()

...
query := "select id, subject from tbl_faq limit 10"

// Deliver the context that has the whatap TraceCtx.
if rows, err := db.QueryContext(ctx, query); err == nil {
...
}
}
...
}

Reference example

Configuration

go.sql_profile_enabled
#Default : true#
#Type : boolean#

It sets whether or not to collect the database/SQL data.

Supporting the github.com/go-gonic/gin library

Install guide
import (
"github.com/go-gonic/gin"

"github.com/whatap/go-api/trace"
"github.com/whatap/go-api/instrumentation/github.com/go-gonic/gin/whatapgin"
)

func main() {
config := make(map[string]string)
trace.Init(config)
defer trace.Shutdown()

r := gin.Default()

// Set the whatap
r.Use(whatapgin.Middleware())

r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "ok",
})
})
}

Reference example

Supporting the github.com/gorilla/mux library

Install guide

import (
"github.com/gorilla/mux"

"github.com/whatap/go-api/trace"
"github.com/whatap/go-api/instrumentation/github.com/gorilla/mux/whatapmux"
)

func main() {
config := make(map[string]string)
trace.Init(config)
defer trace.Shutdown()

r := mux.NewRouter()

// Set the whatap
r.Use(whatapmux.Middleware())

r.HandleFunc("/index", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/html")
reply := "/index <br/>Test Body"
_, _ = w.Write(([]byte)(reply))
fmt.Println("Response -", r.Response)
}
}

Reference example

Supporting the github.com/labstack/echo library

Install guide
import (
"github.com/labstack/echo"

"github.com/whatap/go-api/trace"
"github.com/whatap/go-api/instrumentation/github.com/labstack/echo/whatapecho"
)

func main() {
config := make(map[string]string)
trace.Init(config)
defer trace.Shutdown()

...

e := echo.New()

// Set the whatap
e.Use(whatapecho.Middleware())

e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!\n")
})
}

Reference example