Skip to content

Commit c92eac9

Browse files
committed
http.method attr key is now http.request.method. unit tests were failing because of this
1 parent ce398e7 commit c92eac9

File tree

8 files changed

+28
-25
lines changed

8 files changed

+28
-25
lines changed

examples/mux-server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"log"
88
"net/http"
99
"time"
@@ -36,7 +36,7 @@ type person struct {
3636
}
3737

3838
func fooHandler(w http.ResponseWriter, r *http.Request) {
39-
sBody, err := ioutil.ReadAll(r.Body)
39+
sBody, err := io.ReadAll(r.Body)
4040
if err != nil {
4141
w.WriteHeader(http.StatusInternalServerError)
4242
return

examples/sql-query/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"database/sql"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"log"
1010
"net/http"
1111
"time"
@@ -48,7 +48,7 @@ type person struct {
4848
}
4949

5050
func fooHandler(db *sql.DB, w http.ResponseWriter, r *http.Request) {
51-
sBody, err := ioutil.ReadAll(r.Body)
51+
sBody, err := io.ReadAll(r.Body)
5252
if err != nil {
5353
w.WriteHeader(http.StatusInternalServerError)
5454
return

instrumentation/opentelemetry/github.com/gin-gonic/hypergin/gin_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package hypergin
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net"
88
"net/http"
99
"net/http/httptest"
@@ -61,7 +61,8 @@ func TestSpanRecordedCorrectly(t *testing.T) {
6161
assert.Equal(t, span.SpanKind(), trace.SpanKindServer)
6262

6363
attrs := tracetesting.LookupAttributes(span.Attributes())
64-
assert.Equal(t, "POST", attrs.Get("http.method").AsString())
64+
// "http.request.method" replaces "http.method"
65+
assert.Equal(t, "POST", attrs.Get("http.request.method").AsString())
6566
assert.Equal(t, "abc123xyz", attrs.Get("http.request.header.api_key").AsString())
6667
assert.Equal(t, `{"name":"Jacinto"}`, attrs.Get("http.request.body").AsString())
6768
assert.Equal(t, "xyz123abc", attrs.Get("http.response.header.request_id").AsString())
@@ -113,7 +114,7 @@ func TestTraceContextIsPropagated(t *testing.T) {
113114
})
114115
return
115116
}
116-
bodyBytes, _ := ioutil.ReadAll(res.Body)
117+
bodyBytes, _ := io.ReadAll(res.Body)
117118
bodyString := string(bodyBytes)
118119
c.JSON(200, gin.H{
119120
"success": true,
@@ -133,7 +134,7 @@ func TestTraceContextIsPropagated(t *testing.T) {
133134
fmt.Sprintf("http://localhost:%d/send_thing_request", p2), nil)
134135

135136
res, err := client.Do(req)
136-
_, readErr := ioutil.ReadAll(res.Body)
137+
_, readErr := io.ReadAll(res.Body)
137138
require.NoError(t, readErr)
138139

139140
if err != nil {

instrumentation/opentelemetry/github.com/gorilla/hypermux/mux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func TestSpanRecordedCorrectly(t *testing.T) {
7676
assert.Equal(t, span.SpanKind(), trace.SpanKindServer)
7777

7878
attrs := tracetesting.LookupAttributes(span.Attributes())
79-
assert.Equal(t, "POST", attrs.Get("http.method").AsString())
79+
// "http.request.method" replaces "http.method"
80+
assert.Equal(t, "POST", attrs.Get("http.request.method").AsString())
8081
assert.Equal(t, "abc123xyz", attrs.Get("http.request.header.api_key").AsString())
8182
assert.Equal(t, `{"name":"Jacinto"}`, attrs.Get("http.request.body").AsString())
8283
assert.Equal(t, "xyz123abc", attrs.Get("http.response.header.request_id").AsString())

instrumentation/opentelemetry/init_additional_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package opentelemetry
33
import (
44
"context"
55
"encoding/json"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -23,7 +23,7 @@ import (
2323
func TestInitAdditional(t *testing.T) {
2424
zipkinSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2525
zs := []model.SpanModel{}
26-
b, err := ioutil.ReadAll(r.Body)
26+
b, err := io.ReadAll(r.Body)
2727
require.NoError(t, err)
2828
defer r.Body.Close()
2929

instrumentation/opentelemetry/net/hyperhttp/transport_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"bytes"
55
"context"
66
"errors"
7-
"google.golang.org/protobuf/types/known/wrapperspb"
8-
"io/ioutil"
7+
"io"
98
"log"
109
"net/http"
1110
"net/http/httptest"
1211
"testing"
1312

13+
"google.golang.org/protobuf/types/known/wrapperspb"
14+
1415
config "github.com/hypertrace/agent-config/gen/go/v1"
1516
"github.com/hypertrace/goagent/instrumentation/opentelemetry/internal/tracetesting"
1617
sdkconfig "github.com/hypertrace/goagent/sdk/config"
@@ -66,7 +67,7 @@ func TestClientRequestIsSuccessfullyTraced(t *testing.T) {
6667

6768
assert.Equal(t, 202, res.StatusCode)
6869

69-
resBody, err := ioutil.ReadAll(res.Body)
70+
resBody, err := io.ReadAll(res.Body)
7071
assert.Nil(t, err)
7172
assert.Equal(t, `{"id":123}`, string(resBody))
7273

@@ -78,7 +79,8 @@ func TestClientRequestIsSuccessfullyTraced(t *testing.T) {
7879
assert.Equal(t, trace.SpanKindClient, span.SpanKind())
7980

8081
attrs := tracetesting.LookupAttributes(span.Attributes())
81-
assert.Equal(t, "POST", attrs.Get("http.method").AsString())
82+
// "http.request.method" replaces "http.method"
83+
assert.Equal(t, "POST", attrs.Get("http.request.method").AsString())
8284
assert.Equal(t, "abc123xyz", attrs.Get("http.request.header.api_key").AsString())
8385
assert.Equal(t, `{"name":"Jacinto"}`, attrs.Get("http.request.body").AsString())
8486
assert.Equal(t, "xyz123abc", attrs.Get("http.response.header.request_id").AsString())
@@ -176,7 +178,7 @@ func TestClientRecordsRequestAndResponseBodyAccordingly(t *testing.T) {
176178

177179
assert.Equal(t, 202, res.StatusCode)
178180

179-
_, err = ioutil.ReadAll(res.Body)
181+
_, err = io.ReadAll(res.Body)
180182
assert.Nil(t, err)
181183

182184
span := flusher()[0]

sdk/instrumentation/net/http/transport.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package http // import "github.com/hypertrace/goagent/sdk/instrumentation/net/ht
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77

88
config "github.com/hypertrace/agent-config/gen/go/v1"
@@ -44,7 +44,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
4444
// the content type is not streamable, otherwise we could end up in a very
4545
// expensive parsing of a big body in memory.
4646
if req.Body != nil && rt.dataCaptureConfig.HttpBody.Request.Value && ShouldRecordBodyOfContentType(reqHeadersAccessor) {
47-
body, err := ioutil.ReadAll(req.Body)
47+
body, err := io.ReadAll(req.Body)
4848
if err != nil {
4949
return rt.delegate.RoundTrip(req)
5050
}
@@ -55,7 +55,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
5555
HasMultiPartFormDataContentTypeHeader(reqHeadersAccessor))
5656
}
5757

58-
req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
58+
req.Body = io.NopCloser(bytes.NewBuffer(body))
5959
}
6060

6161
res, err := rt.delegate.RoundTrip(req)
@@ -66,7 +66,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
6666

6767
// Notice, parsing a streamed content in memory can be expensive.
6868
if rt.dataCaptureConfig.HttpBody.Response.Value && ShouldRecordBodyOfContentType(resHeadersAccessor) {
69-
body, err := ioutil.ReadAll(res.Body)
69+
body, err := io.ReadAll(res.Body)
7070
if err != nil {
7171
return res, nil
7272
}
@@ -77,7 +77,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
7777
HasMultiPartFormDataContentTypeHeader(resHeadersAccessor))
7878
}
7979

80-
res.Body = ioutil.NopCloser(bytes.NewBuffer(body))
80+
res.Body = io.NopCloser(bytes.NewBuffer(body))
8181
}
8282

8383
if rt.dataCaptureConfig.HttpHeaders.Response.Value {

sdk/instrumentation/net/http/transport_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/base64"
77
"errors"
88
"io"
9-
"io/ioutil"
109
"log"
1110
"net/http"
1211
"net/http/httptest"
@@ -65,7 +64,7 @@ func TestClientRequestIsSuccessfullyTraced(t *testing.T) {
6564

6665
assert.Equal(t, 202, res.StatusCode)
6766

68-
resBody, err := ioutil.ReadAll(res.Body)
67+
resBody, err := io.ReadAll(res.Body)
6968
assert.Nil(t, err)
7069
assert.Equal(t, `{"id":123}`, string(resBody))
7170

@@ -131,7 +130,7 @@ func TestClientRequestHeadersAreCapturedAccordingly(t *testing.T) {
131130

132131
assert.Equal(t, 202, res.StatusCode)
133132

134-
resBody, err := ioutil.ReadAll(res.Body)
133+
resBody, err := io.ReadAll(res.Body)
135134
assert.Nil(t, err)
136135
assert.Equal(t, `{"id":123}`, string(resBody))
137136

@@ -341,7 +340,7 @@ func TestClientRecordsRequestAndResponseBodyAccordingly(t *testing.T) {
341340

342341
assert.Equal(t, 202, res.StatusCode)
343342

344-
_, err = ioutil.ReadAll(res.Body)
343+
_, err = io.ReadAll(res.Body)
345344
assert.Nil(t, err)
346345

347346
span := tr.spans[0]

0 commit comments

Comments
 (0)