Skip to content

Commit f9ed425

Browse files
committed
Fixes issue with nil HttpResponse causing panics
1 parent 06c801d commit f9ed425

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

v3/integrations/nrawssdk-v1/nrawssdk.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package nrawssdk
66

77
import (
8+
"net/http"
9+
810
"github.com/aws/aws-sdk-go/aws/request"
911
"github.com/newrelic/go-agent/v3/internal"
1012
"github.com/newrelic/go-agent/v3/internal/awssupport"
@@ -25,7 +27,13 @@ func startSegment(req *request.Request) {
2527

2628
func endSegment(req *request.Request) {
2729
ctx := req.HTTPRequest.Context()
28-
awssupport.EndSegment(ctx, req.HTTPResponse.Header)
30+
31+
hdr := http.Header{}
32+
if req.HTTPRequest != nil {
33+
hdr = req.HTTPRequest.Header
34+
}
35+
36+
awssupport.EndSegment(ctx, hdr)
2937
}
3038

3139
// InstrumentHandlers will add instrumentation to the given *request.Handlers.

v3/integrations/nrawssdk-v1/nrawssdk_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ func TestGetRequestID(t *testing.T) {
620620
primary: []string{"hello"},
621621
secondary: []string{"world"},
622622
}, expected: "hello"},
623+
624+
{hdr: http.Header{}, expected: ""},
623625
}
624626

625627
// Make sure our assumptions still hold against aws-sdk-go

v3/internal/awssupport/awssupport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func StartSegment(input StartSegmentInputs) *http.Request {
7070

7171
var segment endable
7272
// Service name capitalization is different for v1 and v2.
73-
if input.ServiceName == "dynamodb" || input.ServiceName == "DynamoDB" {
73+
if input.ServiceName == "dynamodb" || input.ServiceName == "DynamoDB" || input.ServiceName == "dax" {
7474
segment = &newrelic.DatastoreSegment{
7575
Product: newrelic.DatastoreDynamoDB,
7676
Collection: getTableName(input.Params),

v3/internal/awssupport/awssupport_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ func TestGetRequestID(t *testing.T) {
7373
primary: []string{"hello"},
7474
secondary: []string{"world"},
7575
}, expected: "hello"},
76+
77+
{hdr: http.Header{}, expected: ""},
7678
}
7779

7880
for i, test := range testcases {

0 commit comments

Comments
 (0)