diff --git a/go.mod b/go.mod index 5a8ae88..ba7751f 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,23 @@ module github.com/microsoft/kiota-http-go -go 1.23.0 - -toolchain go1.24.1 +go 1.25.0 require ( github.com/google/uuid v1.6.0 github.com/microsoft/kiota-abstractions-go v1.9.4 github.com/stretchr/testify v1.11.1 - go.opentelemetry.io/otel v1.35.0 - go.opentelemetry.io/otel/trace v1.35.0 + go.opentelemetry.io/otel v1.43.0 + go.opentelemetry.io/otel/trace v1.43.0 ) require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.3 // indirect - go.opentelemetry.io/auto/sdk v1.1.0 // indirect - go.opentelemetry.io/otel/metric v1.35.0 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/otel/metric v1.43.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8c21cd6..b3c4d09 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,10 @@ +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= -github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -23,14 +25,14 @@ github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.3 h1:7hth9376EoQEd1hH4lAp3 github.com/std-uritemplate/std-uritemplate/go/v2 v2.0.3/go.mod h1:Z5KcoM0YLC7INlNhEezeIZ0TZNYf7WSNO0Lvah4DSeQ= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= -go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= -go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= -go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= -go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= -go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= -go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= +go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= +go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= +go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= +go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= +go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/kiota_client_factory_test.go b/kiota_client_factory_test.go index 7e24ba9..ad137fd 100644 --- a/kiota_client_factory_test.go +++ b/kiota_client_factory_test.go @@ -42,7 +42,7 @@ func TestGetDefaultMiddleWareWithMultipleOptions(t *testing.T) { &headersInspectionOptions, ) if err != nil { - t.Errorf(err.Error()) + t.Error(err) } if len(options) != 6 { t.Errorf("expected 6 middleware, got %v", len(options)) @@ -80,7 +80,7 @@ func TestGetDefaultMiddleWareWithOptionsDeprecated(t *testing.T) { func verifyMiddlewareWithDisabledCompression(t *testing.T, options []Middleware, err error) { if err != nil { - t.Errorf(err.Error()) + t.Error(err) } if len(options) != 6 { t.Errorf("expected 6 middleware, got %v", len(options)) diff --git a/nethttp_request_adapter.go b/nethttp_request_adapter.go index 4bf170a..07a4a33 100644 --- a/nethttp_request_adapter.go +++ b/nethttp_request_adapter.go @@ -209,14 +209,15 @@ func (a *NetHttpRequestAdapter) setBaseUrlForRequestInformation(requestInfo *abs requestInfo.PathParameters["baseurl"] = a.GetBaseUrl() } -func (a *NetHttpRequestAdapter) prepareContext(ctx context.Context, requestInfo *abs.RequestInformation) context.Context { +func (a *NetHttpRequestAdapter) prepareContext(ctx context.Context, requestInfo *abs.RequestInformation) (context.Context, context.CancelFunc) { if ctx == nil { ctx = context.Background() } + cancel := func() {} // no-op placeholder used when no timeout is applied // set deadline if not set in receiving context // ignore if timeout is 0 as it means no timeout if _, deadlineSet := ctx.Deadline(); !deadlineSet && a.httpClient.Timeout != 0 { - ctx, _ = context.WithTimeout(ctx, a.httpClient.Timeout) + ctx, cancel = context.WithTimeout(ctx, a.httpClient.Timeout) } for _, value := range requestInfo.GetRequestOptions() { @@ -231,7 +232,7 @@ func (a *NetHttpRequestAdapter) prepareContext(ctx context.Context, requestInfo if !obsOptionsSet { ctx = context.WithValue(ctx, observabilityOptionsKeyValue, &a.observabilityOptions) } - return ctx + return ctx, cancel } // ConvertToNativeRequest converts the given RequestInformation into a native HTTP request. @@ -322,7 +323,8 @@ func (a *NetHttpRequestAdapter) Send(ctx context.Context, requestInfo *abs.Reque if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "Send") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -382,7 +384,8 @@ func (a *NetHttpRequestAdapter) SendEnum(ctx context.Context, requestInfo *abs.R if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendEnum") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -436,7 +439,8 @@ func (a *NetHttpRequestAdapter) SendCollection(ctx context.Context, requestInfo if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendCollection") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -490,7 +494,8 @@ func (a *NetHttpRequestAdapter) SendEnumCollection(ctx context.Context, requestI if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendEnumCollection") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -552,7 +557,8 @@ func (a *NetHttpRequestAdapter) SendPrimitive(ctx context.Context, requestInfo * if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendPrimitive") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -636,7 +642,8 @@ func (a *NetHttpRequestAdapter) SendPrimitiveCollection(ctx context.Context, req if requestInfo == nil { return nil, errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendPrimitiveCollection") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span) @@ -690,7 +697,8 @@ func (a *NetHttpRequestAdapter) SendNoContent(ctx context.Context, requestInfo * if requestInfo == nil { return errors.New("requestInfo cannot be nil") } - ctx = a.prepareContext(ctx, requestInfo) + ctx, cancel := a.prepareContext(ctx, requestInfo) + defer cancel() ctx, span := a.startTracingSpan(ctx, requestInfo, "SendNoContent") defer span.End() response, err := a.getHttpResponseMessage(ctx, requestInfo, "", span)