feat(tracing): add OpenTelemetry instrumentation to API gateway
- Add internal/tracing package with OTel tracer initialization - HTTP middleware for server-side tracing (request/response attributes) - Transport wrapper for client-side upstream call tracing - Update proxy to use tracing transport - Add OTEL_* env vars to k8s deployment Traces flow: api-gateway -> otel-collector -> tempo -> grafana
This commit is contained in:
+21
-1
@@ -14,9 +14,26 @@ import (
|
||||
"forgejo.riotpiao.com/rock/homelab-frontend/internal/server"
|
||||
"forgejo.riotpiao.com/rock/homelab-frontend/internal/serviceadapter"
|
||||
"forgejo.riotpiao.com/rock/homelab-frontend/internal/temporal"
|
||||
"forgejo.riotpiao.com/rock/homelab-frontend/internal/tracing"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Initialize OpenTelemetry tracing
|
||||
tracingCfg := tracing.DefaultConfig()
|
||||
shutdownTracer, err := tracing.Init(ctx, tracingCfg)
|
||||
if err != nil {
|
||||
log.Printf("warning: failed to initialize tracing: %v", err)
|
||||
} else {
|
||||
log.Printf("tracing initialized: service=%s endpoint=%s", tracingCfg.ServiceName, tracingCfg.OTLPEndpoint)
|
||||
defer func() {
|
||||
if err := shutdownTracer(ctx); err != nil {
|
||||
log.Printf("error shutting down tracer: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Load configuration
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
@@ -63,7 +80,10 @@ func main() {
|
||||
// Create router that handles health endpoints, X-Service (ServiceAdapter) routing,
|
||||
// temporal endpoints, and passes others to upstream handler
|
||||
router := server.NewRouter(healthChecker, dispatcher, temporalHandler, upstreamHandler)
|
||||
srv.SetHandler(router)
|
||||
|
||||
// Wrap router with tracing middleware
|
||||
tracedRouter := tracing.Middleware(router)
|
||||
srv.SetHandler(tracedRouter)
|
||||
|
||||
// Set up signal handling
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
|
||||
Reference in New Issue
Block a user