forked from mtusi2026/mtusi2026lab6
33 lines
969 B
Go
33 lines
969 B
Go
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
|
|
}
|