Skip to content

Commit

Permalink
Fixes issue with nil HttpResponse causing panics
Browse files Browse the repository at this point in the history
  • Loading branch information
odannyc committed Mar 30, 2021
1 parent 06c801d commit f9ed425
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion v3/integrations/nrawssdk-v1/nrawssdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package nrawssdk

import (
"net/http"

"github.com/aws/aws-sdk-go/aws/request"
"github.com/newrelic/go-agent/v3/internal"
"github.com/newrelic/go-agent/v3/internal/awssupport"
Expand All @@ -25,7 +27,13 @@ func startSegment(req *request.Request) {

func endSegment(req *request.Request) {
ctx := req.HTTPRequest.Context()
awssupport.EndSegment(ctx, req.HTTPResponse.Header)

hdr := http.Header{}
if req.HTTPRequest != nil {
hdr = req.HTTPRequest.Header
}

awssupport.EndSegment(ctx, hdr)
}

// InstrumentHandlers will add instrumentation to the given *request.Handlers.
Expand Down
2 changes: 2 additions & 0 deletions v3/integrations/nrawssdk-v1/nrawssdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ func TestGetRequestID(t *testing.T) {
primary: []string{"hello"},
secondary: []string{"world"},
}, expected: "hello"},

{hdr: http.Header{}, expected: ""},
}

// Make sure our assumptions still hold against aws-sdk-go
Expand Down
2 changes: 1 addition & 1 deletion v3/internal/awssupport/awssupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func StartSegment(input StartSegmentInputs) *http.Request {

var segment endable
// Service name capitalization is different for v1 and v2.
if input.ServiceName == "dynamodb" || input.ServiceName == "DynamoDB" {
if input.ServiceName == "dynamodb" || input.ServiceName == "DynamoDB" || input.ServiceName == "dax" {
segment = &newrelic.DatastoreSegment{
Product: newrelic.DatastoreDynamoDB,
Collection: getTableName(input.Params),
Expand Down
2 changes: 2 additions & 0 deletions v3/internal/awssupport/awssupport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func TestGetRequestID(t *testing.T) {
primary: []string{"hello"},
secondary: []string{"world"},
}, expected: "hello"},

{hdr: http.Header{}, expected: ""},
}

for i, test := range testcases {
Expand Down

0 comments on commit f9ed425

Please sign in to comment.