feat(storage): lab6 add PostgreSQL, Redis and S3 tracing and DB pool metrics

This commit is contained in:
Голиков Maximillian Антон
2026-11-16 14:48:07 +03:00
parent c403b23595
commit 472b4761d6
11 changed files with 225 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
package s3
import (
"net/http"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
// Один span на HTTP-попытку MinIO до получения заголовков ответа.
type tracingTransport struct {
next http.RoundTripper
tracer trace.Tracer
}
func (t tracingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
ctx, span := t.tracer.Start(req.Context(), "s3."+req.Method, trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(attribute.String("http.request.method", req.Method)))
defer span.End()
resp, err := t.next.RoundTrip(req.WithContext(ctx))
if err != nil {
span.SetStatus(codes.Error, "ошибка соединения с S3")
} else {
span.SetAttributes(attribute.Int("http.response.status_code", resp.StatusCode))
if resp.StatusCode >= 400 {
span.SetStatus(codes.Error, http.StatusText(resp.StatusCode))
}
}
return resp, err
}