feat(tracing): add OpenTelemetry instrumentation to API gateway
CI / Vet, test, build (push) Successful in 3m43s
CI / Build and push image (push) Successful in 1m33s

- 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:
Admin Bot
2026-08-31 15:01:56 -07:00
parent de34a6c8cc
commit f9addf945d
8 changed files with 367 additions and 32 deletions
+3 -2
View File
@@ -15,6 +15,7 @@ import (
"forgejo.riotpiao.com/rock/homelab-frontend/internal/config"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/logging"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/tracing"
)
// Handler is a reverse proxy that routes requests to configured upstreams.
@@ -325,8 +326,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Set the director to apply path rewriting
proxy.Director = route.Director
// Use the connection-pooled transport
proxy.Transport = route.Transport
// Use the connection-pooled transport wrapped with tracing
proxy.Transport = tracing.NewTransport(route.Transport)
// Set error handler to log upstream errors
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {