WhaTap Go API Instrumentation Examples
This repository contains example code demonstrating how to instrument Go applications using the WhaTap Go API.
All examples follow a common instrumentation pattern:
- Initialize - Call
trace.Init(nil) at application startup
- Add Middleware - Add WhaTap middleware to your web framework
- Use Context - Pass context to track SQL, HTTP calls, and custom methods
- Shutdown - Call
defer trace.Shutdown() for graceful cleanup
| Library |
Example |
Middleware Pattern |
| Gin |
github.com/gin-gonic/gin/ |
r.Use(whatapgin.Middleware()) |
| Echo v4 |
github.com/labstack/echo/v4/ |
e.Use(whatapecho.Middleware()) |
| Echo v3 |
github.com/labstack/echo/ |
e.Use(whatapecho.Middleware()) |
| Fiber v2 |
github.com/gofiber/fiber/ |
app.Use(whatapfiber.Middleware()) |
| Chi |
github.com/go-chi/chi/ |
r.Use(whatapchi.Middleware) (no parentheses) |
| Gorilla Mux |
github.com/gorilla/mux/ |
r.Use(whatapmux.Middleware()) |
| FastHTTP |
github.com/valyala/fasthttp/ |
whatapfasthttp.Func(handler) wrapper |
| net/http |
net/http/server/ |
whataphttp.Func()/Handler() wrapper |
Note: In addition to middleware patterns, Wrap functions are available for struct field initialization:
WrapEngine() (Gin), WrapEcho() (Echo), WrapApp() (Fiber), WrapRouter() (Chi/Gorilla),
WrapHandler() (net/http, FastHTTP), WrapConfig() (Sarama), WrapLogger() (logrus)
| Library |
Example |
Instrumentation |
| database/sql |
database/sql/ |
whatapsql.OpenContext() or manual Start/End |
| GORM v2 |
github.com/go-gorm/gorm/ |
whatapgorm.OpenWithContext() |
| GORM v1 (jinzhu) |
github.com/jinzhu/gorm/ |
whatapgorm.Open() |
| sqlx |
github.com/jmoiron/sqlx/ |
whatapsqlx.OpenContext() |
| Library |
Example |
Instrumentation |
| go-redis v9 |
github.com/redis/go-redis/v9/ |
whatapgoredis.NewClient() |
| go-redis v8 |
github.com/go-redis/redis/v8/ |
whatapgoredis.NewClient() |
| Redigo |
github.com/gomodule/redigo/ |
whatapredigo.DialContext() |
| MongoDB |
go.mongodb.org/mongo-driver/mongo/ |
whatapmongo.Connect() |
| Library |
Example |
Instrumentation |
| net/http client |
net/http/client/ |
httpc.Start/End or whataphttp.NewRoundTrip() |
| Library |
Example |
Instrumentation |
| gRPC |
google.golang.org/grpc/ |
whatapgrpc interceptors |
| Kubernetes client-go |
k8s.io/client-go/kubernetes/ |
whatapkubernetes.NewForConfig() |
| Library |
Example |
Instrumentation |
| fmt |
fmt/ |
whatapfmt.Print/Printf/Println() |
- Automatic HTTP transaction tracking - Request/Response details
- SQL query tracking - Query text, parameters, execution time
- HTTP client call tracking - Outgoing HTTP calls with
httpc.Start/End
- Custom method tracing - Track any function with
method.Start/End
- Distributed tracing - Multi-transaction trace via
trace.GetMTrace(ctx)
- Error tracking - Automatic error capture and reporting
Each example can be run with:
cd <example-directory>
go run *.go -whatap