✨ feat(server): wire sampler hot-reload callback (ADR-0023 Phase 3, sub-phase 3.3) (#49)
Co-authored-by: Gabriel Radureau <arcodange@gmail.com> Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
This commit was merged in pull request #49.
This commit is contained in:
@@ -679,10 +679,11 @@ func (s *Server) Router() http.Handler {
|
||||
func (s *Server) Run() error {
|
||||
// Initialize OpenTelemetry if enabled
|
||||
var err error
|
||||
var telemetrySetup *telemetry.Setup
|
||||
if s.withOTEL {
|
||||
log.Trace().Msg("Initializing OpenTelemetry tracing")
|
||||
|
||||
telemetrySetup := &telemetry.Setup{
|
||||
telemetrySetup = &telemetry.Setup{
|
||||
ServiceName: s.config.GetServiceName(),
|
||||
OTLPEndpoint: s.config.GetOTLPEndpoint(),
|
||||
Insecure: s.config.GetTelemetryInsecure(),
|
||||
@@ -694,6 +695,7 @@ func (s *Server) Run() error {
|
||||
if s.tracerProvider, err = telemetrySetup.InitializeTracing(context.Background()); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to initialize OpenTelemetry, continuing without tracing")
|
||||
s.withOTEL = false
|
||||
telemetrySetup = nil
|
||||
} else {
|
||||
log.Trace().Msg("OpenTelemetry tracing initialized successfully")
|
||||
}
|
||||
@@ -714,7 +716,27 @@ func (s *Server) Run() error {
|
||||
s.userService.StartJWTSecretCleanupLoop(rootCtx, s.config.GetJWTSecretCleanupInterval())
|
||||
}
|
||||
|
||||
// Start config hot-reload watcher (ADR-0023 Phase 1: logging.level only).
|
||||
// Wire the sampler hot-reload callback (ADR-0023 Phase 3, sub-phase 3.3).
|
||||
// telemetrySetup is non-nil only when telemetry was successfully initialized
|
||||
// at startup — hot-reloading telemetry-on is out of scope (see ADR-0023).
|
||||
// The callback updates the SamplerType/Ratio on the captured Setup, then
|
||||
// rebuilds the global tracer provider via ReconfigureTracerProvider.
|
||||
if telemetrySetup != nil {
|
||||
s.config.SetSamplerReconfigureCallback(func(ctx context.Context, samplerType string, samplerRatio float64) error {
|
||||
telemetrySetup.SamplerType = samplerType
|
||||
telemetrySetup.SamplerRatio = samplerRatio
|
||||
newTP, rerr := telemetrySetup.ReconfigureTracerProvider(ctx, s.tracerProvider)
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
if newTP != nil {
|
||||
s.tracerProvider = newTP
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Start config hot-reload watcher (ADR-0023 Phase 1+2+3).
|
||||
// Stops automatically on rootCtx cancellation.
|
||||
s.config.WatchAndApply(rootCtx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user