lab6 done
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package observability
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Transport records dependency timing without URLs, headers, object names or credentials.
|
||||
type Transport struct{ Base http.RoundTripper }
|
||||
|
||||
func (t Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
ctx, span := Start(r.Context(), "s3 "+r.Method, trace.SpanKindClient)
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("rpc.system", "s3"), attribute.String("http.request.method", r.Method))
|
||||
response, err := t.Base.RoundTrip(r.Clone(ctx))
|
||||
Result(span, err)
|
||||
if response != nil {
|
||||
span.SetAttributes(attribute.Int("http.response.status_code", response.StatusCode))
|
||||
if response.StatusCode >= 500 {
|
||||
span.SetStatus(codes.Error, "storage unavailable")
|
||||
}
|
||||
}
|
||||
return response, err
|
||||
}
|
||||
Reference in New Issue
Block a user