Skip to content

Commit

Permalink
fix nilp error by aws#102
Browse files Browse the repository at this point in the history
  • Loading branch information
t-yuki authored and Logan Hanks committed Jul 2, 2019
1 parent 445cf09 commit 3062273
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xray/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var xRayAfterSendHandler = request.NamedHandler{
Fn: func(r *request.Request) {
curseg := GetSegment(r.HTTPRequest.Context())

if curseg.Name == "attempt" {
if curseg != nil && curseg.Name == "attempt" {
// An error could have prevented the connect subsegment from closing,
// so clean it up here.
for _, subsegment := range curseg.rawSubsegments {
Expand Down
22 changes: 22 additions & 0 deletions xray/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,25 @@ func TestClientFailedConnection(t *testing.T) {
assert.NotZero(t, connectSubseg.EndTime)
assert.NotEmpty(t, connectSubseg.Subsegments)
}

func TestClientWithoutSegment(t *testing.T) {
Configure(Config{ContextMissingStrategy: &TestContextMissingStrategy{}})
defer ResetConfig()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b := []byte(`{}`)
w.WriteHeader(http.StatusOK)
w.Write(b)
}))

svc := lambda.New(session.Must(session.NewSession(&aws.Config{
Endpoint: aws.String(ts.URL),
Region: aws.String("fake-moon-1"),
Credentials: credentials.NewStaticCredentials("akid", "secret", "noop")})))

ctx := context.Background()

AWS(svc.Client)

_, err := svc.ListFunctionsWithContext(ctx, &lambda.ListFunctionsInput{})
assert.NoError(t, err)
}

0 comments on commit 3062273

Please sign in to comment.