aws / aws-xray-sdk-go

AWS X-Ray SDK for the Go programming language.
Apache License 2.0
276 stars 117 forks source link

panic when using timestream QueryWithContext with X-Ray #411

Open sportlane opened 1 year ago

sportlane commented 1 year ago

Describe the bug

When using timestreamquery QueryWithContext function with X-Ray, the program panic with the error: "panic: failed to begin subsegment named 'Timestream Query': segment cannot be found."

The DescribeEndpoints call queued before QueryWithContext is not getting context set up.

Current Behavior

panic: failed to begin subsegment named 'Timestream Query': segment cannot be found.

goroutine 1 [running]:
github.com/aws/aws-xray-sdk-go/strategy/ctxmissing.(*DefaultRuntimeErrorStrategy).ContextMissing(0xc0000302d0?, {0x17376e0?, 0xc00062cd70?})
        /Users/user/go/pkg/mod/github.com/aws/aws-xray-sdk-go@v1.7.0/strategy/ctxmissing/default_context_missing.go:60 +0x29
github.com/aws/aws-xray-sdk-go/xray.BeginSubsegment({0x1ae9510, 0xc000028068}, {0x18433c3, 0x10})
        /Users/user/go/pkg/mod/github.com/aws/aws-xray-sdk-go@v1.7.0/xray/segment.go:272 +0x6a8
github.com/aws/aws-xray-sdk-go/xray.glob..func1(0xc000368500)
        /Users/user/go/pkg/mod/github.com/aws/aws-xray-sdk-go@v1.7.0/xray/aws.go:67 +0x75
github.com/aws/aws-sdk-go/aws/request.(*HandlerList).Run(0xc0003686a8, 0xc000368500)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/handlers.go:267 +0x9a
github.com/aws/aws-sdk-go/aws/request.(*Request).Build(0xc000368500)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:416 +0x39
github.com/aws/aws-sdk-go/aws/request.(*Request).Sign(0xc000368500)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:437 +0x25
github.com/aws/aws-sdk-go/aws/request.(*Request).Send(0xc000368500)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:550 +0x13b
github.com/aws/aws-sdk-go/service/timestreamquery.(*TimestreamQuery).DescribeEndpoints(0x18394a4?, 0x4?)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/service/timestreamquery/api.go:465 +0x25
github.com/aws/aws-sdk-go/service/timestreamquery.(*discovererDescribeEndpoints).Discover(0xc000638340)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/service/timestreamquery/api.go:496 +0x5e
github.com/aws/aws-sdk-go/aws/crr.(*EndpointCache).discover(0xc000513908?, {0x1ae3ac0?, 0xc000638340?}, {0x1839e2f, 0x5})
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/crr/cache.go:113 +0x66
github.com/aws/aws-sdk-go/aws/crr.(*EndpointCache).Get(0xc000638000, {0x1ae3ac0?, 0xc000638340}, {0x1839e2f, 0x5}, 0x1)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/crr/cache.go:64 +0x11b
github.com/aws/aws-sdk-go/service/timestreamquery.(*discovererDescribeEndpoints).Handler(0xc000638340, 0xc000368000)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/service/timestreamquery/api.go:545 +0x86
github.com/aws/aws-sdk-go/aws/request.(*HandlerList).Run(0xc0003681c8, 0xc000368000)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/handlers.go:267 +0x9a
github.com/aws/aws-sdk-go/aws/request.(*Request).Build(0xc000368000)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:421 +0x67
github.com/aws/aws-sdk-go/aws/request.(*Request).Sign(0xc000368000)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:437 +0x25
github.com/aws/aws-sdk-go/aws/request.(*Request).Send(0xc000368000)
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/aws/request/request.go:550 +0x13b
github.com/aws/aws-sdk-go/service/timestreamquery.(*TimestreamQuery).QueryWithContext(0x1ae9510?, {0x1ae9580, 0xc0006139e0}, 0x4?, {0x0, 0x0, 0xc00034b0e0?})
        /Users/user/go/pkg/mod/github.com/aws/aws-sdk-go@v1.44.142/service/timestreamquery/api.go:1396 +0x186
main.main()
        /Users/user/Documents/Source/test/ts-test.go:25 +0x185
exit status 2

Reproduction Steps

package main

import (
    "context"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/timestreamquery"
    "github.com/aws/aws-xray-sdk-go/xray"
)

func main() {

    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
        Config: aws.Config{
            Region: aws.String("us-east-1"),
        },
    }))

    tsclient := timestreamquery.New(sess)
    xray.AWS(tsclient.Client)

    ctx, _ := xray.BeginSegment(context.Background(), "test")
    tsclient.QueryWithContext(ctx, &timestreamquery.QueryInput{
        QueryString: aws.String("SELECT * FROM FOO"),
    })
}

SDK version used

v1.7.0

Environment details (Version of Go (go version)? OS name and version, etc.)

go version go1.19.3 darwin/amd64