Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

whatap/go-api-example

Open more actions menu

Repository files navigation

WhaTap Go API Instrumentation Examples

This repository contains example code demonstrating how to instrument Go applications using the WhaTap Go API.

Quick Start

All examples follow a common instrumentation pattern:

  1. Initialize - Call trace.Init(nil) at application startup
  2. Add Middleware - Add WhaTap middleware to your web framework
  3. Use Context - Pass context to track SQL, HTTP calls, and custom methods
  4. Shutdown - Call defer trace.Shutdown() for graceful cleanup

Supported Libraries

Web Frameworks

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)

Databases

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()

Cache & NoSQL

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()

Message Queues

Library Example Instrumentation
IBM/sarama (Kafka) github.com/IBM/sarama/ Producer/Consumer interceptors
Shopify/sarama (Kafka) github.com/Shopify/sarama/ Producer/Consumer interceptors

HTTP Client

Library Example Instrumentation
net/http client net/http/client/ httpc.Start/End or whataphttp.NewRoundTrip()

Cloud & RPC

Library Example Instrumentation
gRPC google.golang.org/grpc/ whatapgrpc interceptors
Kubernetes client-go k8s.io/client-go/kubernetes/ whatapkubernetes.NewForConfig()

Logging

Library Example Instrumentation
fmt fmt/ whatapfmt.Print/Printf/Println()

Key Features

  • 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

Running Examples

Each example can be run with:

cd <example-directory>
go run *.go -whatap

Related Links

About

go-api-example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.