Skip to content

Commit

Permalink
fix(pkg/server): use hostname for OpenTelemetry tracer name (#154)
Browse files Browse the repository at this point in the history
### TL;DR

Updated OpenTelemetry middleware configuration to use dynamic hostname instead of static tracer name

### What changed?

Replaced the static `tracerName` with `s.cache.GetHostname()` in both the OpenTelemetry Chi middleware and metrics base configuration. This change ensures that telemetry data is properly tagged with the actual host identifier.

### How to test?

1. Deploy the application
2. Check OpenTelemetry traces and metrics
3. Verify that the service name in traces and metrics matches the host's hostname
4. Confirm that all middleware functions (heartbeat, RealIP, Recoverer) continue to work as expected

### Why make this change?

Using the actual hostname instead of a static tracer name provides better observability by allowing proper identification of the source of telemetry data in distributed environments. This makes it easier to track and debug issues across multiple instances of the service.
  • Loading branch information
kalbasit authored Dec 25, 2024
1 parent db06680 commit 6d256e1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (s *Server) createRouter() {
s.router = chi.NewRouter()

mp := otel.GetMeterProvider()
baseCfg := otelchimetric.NewBaseConfig(tracerName, otelchimetric.WithMeterProvider(mp))
baseCfg := otelchimetric.NewBaseConfig(s.cache.GetHostname(), otelchimetric.WithMeterProvider(mp))

s.router.Use(middleware.Heartbeat("/healthz"))
s.router.Use(middleware.RealIP)
s.router.Use(middleware.Recoverer)
s.router.Use(
otelchi.Middleware(tracerName, otelchi.WithChiRoutes(s.router)),
otelchi.Middleware(s.cache.GetHostname(), otelchi.WithChiRoutes(s.router)),
otelchimetric.NewRequestDurationMillis(baseCfg),
otelchimetric.NewRequestInFlight(baseCfg),
otelchimetric.NewResponseSizeBytes(baseCfg),
Expand Down

0 comments on commit 6d256e1

Please sign in to comment.