From 9ec456a2275585c51511401d6bd331735bbb0137 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Tue, 29 Oct 2024 21:36:23 +0100 Subject: [PATCH 1/3] remove explicit `Content-Length` header in civisibility transport --- ddtrace/tracer/civisibility_transport.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/ddtrace/tracer/civisibility_transport.go b/ddtrace/tracer/civisibility_transport.go index 0731332022..e9361ca685 100644 --- a/ddtrace/tracer/civisibility_transport.go +++ b/ddtrace/tracer/civisibility_transport.go @@ -13,7 +13,6 @@ import ( "net/http" "os" "runtime" - "strconv" "strings" "gopkg.in/DataDog/dd-trace-go.v1/internal" @@ -154,7 +153,6 @@ func (t *ciVisibilityTransport) send(p *payload) (body io.ReadCloser, err error) for header, value := range t.headers { req.Header.Set(header, value) } - req.Header.Set("Content-Length", strconv.Itoa(buffer.Len())) if t.agentless { req.Header.Set("Content-Encoding", "gzip") } From 5355c5d8648991e18d8e64bf00f17b461d6bf1a6 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Tue, 29 Oct 2024 21:37:20 +0100 Subject: [PATCH 2/3] use the direct request.ContentLength instead of manually setting the header in default transport --- ddtrace/tracer/transport.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddtrace/tracer/transport.go b/ddtrace/tracer/transport.go index c6a900c055..a5f1c597c2 100644 --- a/ddtrace/tracer/transport.go +++ b/ddtrace/tracer/transport.go @@ -143,11 +143,11 @@ func (t *httpTransport) send(p *payload) (body io.ReadCloser, err error) { if err != nil { return nil, fmt.Errorf("cannot create http request: %v", err) } + req.ContentLength = int64(p.size()) for header, value := range t.headers { req.Header.Set(header, value) } req.Header.Set(traceCountHeader, strconv.Itoa(p.itemCount())) - req.Header.Set("Content-Length", strconv.Itoa(p.size())) req.Header.Set(headerComputedTopLevel, "yes") if t, ok := traceinternal.GetGlobalTracer().(*tracer); ok { if t.config.canComputeStats() { From 67cdba75e7428e661ac12047cd4dc36e2b945f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Casta=C3=B1=C3=A9?= Date: Wed, 30 Oct 2024 12:49:07 +0100 Subject: [PATCH 3/3] feat(ddtrace/tracer): check Content-Length header for HTTP transport --- ddtrace/tracer/transport_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ddtrace/tracer/transport_test.go b/ddtrace/tracer/transport_test.go index aaaddbbacf..8c1148277c 100644 --- a/ddtrace/tracer/transport_test.go +++ b/ddtrace/tracer/transport_test.go @@ -249,6 +249,11 @@ func TestWithHTTPClient(t *testing.T) { var hits int srv := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { hits++ + if r.Method == http.MethodGet { + return + } + cl := r.Header.Get("Content-Length") + assert.NotZero(cl) })) defer srv.Close() @@ -266,6 +271,7 @@ func TestWithHTTPClient(t *testing.T) { assert.Len(rt.reqs, 2) assert.Contains(rt.reqs[0].URL.Path, "/info") assert.Contains(rt.reqs[1].URL.Path, "/traces") + assert.NotZero(rt.reqs[1].ContentLength) assert.Equal(hits, 2) }