Harden instrumentation, health checks and the admin server
CI / test (push) Failing after 43s

- Admin pprof is opt-in (AdminConfig.EnablePprof)
- Client spans drop the URL query string; HostFunc bounds the host label
- Config.HTTP/HTTPClient/GRPC configure the Observer's instrumentation
- A panic after a partial HTTP response counts as 500
- GaugeFunc, CounterFunc and RegisterDBStats panic on duplicates
- Abandoned client gRPC streams are recorded as Canceled
- OTEL_EXPORTER_OTLP_PROTOCOL selects the protocol when unset
- Health reports are cached for 1s; hung checks are not restarted
- Environment is exported as deployment.environment.name

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
M.ShakhmatovandClaude Fable 5.2 committed 2026-11-15 16:56:39 +03:00
1 parent 8647fdf1bb
commit c92fd9826b
21 files changed
+457 -101

No files matched your search

+17 -7
View File
@@ -279,13 +279,16 @@ func (g *grpcInstrumentation) streamClient(ctx context.Context, desc *grpc.Strea
g.finishClient(ctx, span, fullMethod, start, err)
return nil, err
}
return &clientStream{
s := &clientStream{
ClientStream: cs,
desc: desc,
finish: func(err error) {
g.finishClient(ctx, span, fullMethod, start, err)
},
}, nil
}
// A caller may cancel and walk away without reading the stream to the end.
s.stop = context.AfterFunc(ctx, func() { s.done(status.FromContextError(ctx.Err()).Err()) })
return s, nil
}
// serverStream overrides the stream context with the traced one.
@@ -304,21 +307,28 @@ type clientStream struct {
desc *grpc.StreamDesc
once sync.Once
finish func(error)
stop func() bool // unregisters the cancellation watcher
}
func (s *clientStream) done(err error) {
s.once.Do(func() { s.finish(err) })
}
// end finishes the stream from one of its own methods.
func (s *clientStream) end(err error) {
s.stop()
s.done(err)
}
func (s *clientStream) RecvMsg(m any) error {
err := s.ClientStream.RecvMsg(m)
switch {
case errors.Is(err, io.EOF):
s.done(nil)
s.end(nil)
case err != nil:
s.done(err)
s.end(err)
case !s.desc.ServerStreams:
s.done(nil)
s.end(nil)
}
return err
}
@@ -326,7 +336,7 @@ func (s *clientStream) RecvMsg(m any) error {
func (s *clientStream) SendMsg(m any) error {
err := s.ClientStream.SendMsg(m)
if err != nil && !errors.Is(err, io.EOF) {
s.done(err)
s.end(err)
}
return err
}
@@ -334,7 +344,7 @@ func (s *clientStream) SendMsg(m any) error {
func (s *clientStream) Header() (metadata.MD, error) {
md, err := s.ClientStream.Header()
if err != nil {
s.done(err)
s.end(err)
}
return md, err
}