Update dependencies

This commit is contained in:
bluepython508
2025-04-09 01:00:12 +01:00
parent f0641ffd6e
commit 5a9cfc022c
882 changed files with 68930 additions and 24201 deletions

View File

@@ -6,7 +6,9 @@ import (
"net/http"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/metrics"
"github.com/aws/smithy-go/middleware"
"github.com/aws/smithy-go/tracing"
)
// ClientDo provides the interface for custom HTTP client implementations.
@@ -27,13 +29,30 @@ func (fn ClientDoFunc) Do(r *http.Request) (*http.Response, error) {
// implementation is http.Client.
type ClientHandler struct {
client ClientDo
Meter metrics.Meter // For HTTP client metrics.
}
// NewClientHandler returns an initialized middleware handler for the client.
//
// Deprecated: Use [NewClientHandlerWithOptions].
func NewClientHandler(client ClientDo) ClientHandler {
return ClientHandler{
return NewClientHandlerWithOptions(client)
}
// NewClientHandlerWithOptions returns an initialized middleware handler for the client
// with applied options.
func NewClientHandlerWithOptions(client ClientDo, opts ...func(*ClientHandler)) ClientHandler {
h := ClientHandler{
client: client,
}
for _, opt := range opts {
opt(&h)
}
if h.Meter == nil {
h.Meter = metrics.NopMeterProvider{}.Meter("")
}
return h
}
// Handle implements the middleware Handler interface, that will invoke the
@@ -42,6 +61,14 @@ func NewClientHandler(client ClientDo) ClientHandler {
func (c ClientHandler) Handle(ctx context.Context, input interface{}) (
out interface{}, metadata middleware.Metadata, err error,
) {
ctx, span := tracing.StartSpan(ctx, "DoHTTPRequest")
defer span.End()
ctx, client, err := withMetrics(ctx, c.client, c.Meter)
if err != nil {
return nil, metadata, fmt.Errorf("instrument with HTTP metrics: %w", err)
}
req, ok := input.(*Request)
if !ok {
return nil, metadata, fmt.Errorf("expect Smithy http.Request value as input, got unsupported type %T", input)
@@ -52,7 +79,17 @@ func (c ClientHandler) Handle(ctx context.Context, input interface{}) (
return nil, metadata, err
}
resp, err := c.client.Do(builtRequest)
span.SetProperty("http.method", req.Method)
span.SetProperty("http.request_content_length", -1) // at least indicate unknown
length, ok, err := req.StreamLength()
if err != nil {
return nil, metadata, err
}
if ok {
span.SetProperty("http.request_content_length", length)
}
resp, err := client.Do(builtRequest)
if resp == nil {
// Ensure a http response value is always present to prevent unexpected
// panics.
@@ -79,6 +116,10 @@ func (c ClientHandler) Handle(ctx context.Context, input interface{}) (
_ = builtRequest.Body.Close()
}
span.SetProperty("net.protocol.version", fmt.Sprintf("%d.%d", resp.ProtoMajor, resp.ProtoMinor))
span.SetProperty("http.status_code", resp.StatusCode)
span.SetProperty("http.response_content_length", resp.ContentLength)
return &Response{Response: resp}, metadata, err
}