The TrustPort Beacon Go SDK (github.com/trustportidentity/beacon-go) gives you fast and lightweight performance monitoring for Go applications with almost zero CPU overhead.
Add the Beacon Go package to your go.mod dependencies:
go get github.com/trustportidentity/beacon-go@latestInitialize the SDK globally during startup and attach the Gin middleware to your router instance:
package main
import (
"context"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/trustportidentity/beacon-go"
"github.com/trustportidentity/beacon-go/adapter/beacongin"
)
func main() {
// 1. Initialize Beacon Client
beacon.Init(beacon.Config{
IngestURL: "https://beacon-api.trustportidentity.com",
APIKey: os.Getenv("BEACON_API_KEY"), // tb_live_...
ServiceName: "payment-gateway",
Environment: "production",
BatchSize: 500, // Asynchronous batch flushing
})
defer beacon.Close()
r := gin.Default()
// 2. Attach W3C Traceparent Middleware
r.Use(beacongin.Middleware("payment-gateway"))
// 3. Application Route Handler
r.POST("/api/v1/charge", func(c *gin.Context) {
ctx := c.Request.Context()
// Create a custom child span for database operation
span := beacon.StartSpan(ctx, "db.postgresql.charge_account")
// Perform work...
span.SetTag("customer_id", c.GetString("user_id"))
span.SetTag("currency", "USD")
span.End()
c.JSON(http.StatusOK, gin.H{
"status": "success",
"trace_id": beacon.TraceID(ctx),
})
})
r.Run(":8080")
}Use beaconfiber.New() for Go Fiber web servers:
app.Use(beaconfiber.Middleware("auth-service"))Wrap any standard HTTP handler with beaconhttp.Handler:
http.Handle("/api", beaconhttp.Handler(myHandler))Every request is already batched (BatchSize/FlushPeriod) instead of sent one call per request. On top of that, set Config.SampleRate (0.0β1.0, default 1.0) to trace only a fraction of requests in high-traffic services β this is what actually keeps you inside your plan's monthly quota. Exceptions are always sent regardless of sampling.
beacon.Init(beacon.Config{ ..., SampleRate: 0.2 }) // trace ~20% of requestsOur senior architects can inspect your pipeline configuration.