-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contrib/aws/aws-sdk-go: add WithErrorCheck option #1682
contrib/aws/aws-sdk-go: add WithErrorCheck option #1682
Conversation
WithErrorCheck specifies a function which determines whether the passed error should be marked as an error. The fn is called whenever an aws operation finishes with an error.
@knusbaum sorry for the direct ping, but any chance to get this or something similar merge? This is currently polluting our error tracking :-/ |
@katiehockman any chance this could also be added to next milestone? |
cfg := aws.NewConfig().WithRegion("us-west-2") | ||
sess := session.Must(session.NewSession(cfg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cfg := aws.NewConfig().WithRegion("us-west-2") | |
sess := session.Must(session.NewSession(cfg)) | |
sess := session.Must(session.NewSession( aws.NewConfig().WithRegion("us-west-2"))) |
spans := mt.FinishedSpans() | ||
assert.True(t, len(spans) > 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is failing in the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written below, I ran the contrib test with ./test.sh --contrib and every test under contrib/aws/aws-sdk-go/aws succeeded.
s := spans[len(spans)-1] | ||
assert.Equal(t, errExist, s.Tag(ext.Error) != nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s := spans[len(spans)-1] | |
assert.Equal(t, errExist, s.Tag(ext.Error) != nil) | |
assert.Equal(t, errExist, spans[0].Tag(ext.Error) != nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
contrib/aws/aws-sdk-go/aws/option.go
Outdated
|
||
// WithErrorCheck specifies a function fn which determines whether the passed | ||
// error should be marked as an error. The fn is called whenever an aws operation | ||
// finishes with an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// finishes with an error | |
// finishes with an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
|
||
func TestWithErrorCheck(t *testing.T) { | ||
testOpts := func(errExist bool, opts ...awstrace.Option) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this test belongs in aws_test.go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved.
t.Run("errcheck", testOpts(false, awstrace.WithErrorCheck(func(err error) bool { | ||
return !strings.Contains(err.Error(), `InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error that is actually received doesn't contain this text, so it will fail. For the test purposes, it's best to check for different content. NoCredentialProviders: no valid providers in chain. Deprecated.
t.Run("errcheck", testOpts(false, awstrace.WithErrorCheck(func(err error) bool { | |
return !strings.Contains(err.Error(), `InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records`) | |
t.Run("errcheck", testOpts(false, awstrace.WithErrorCheck(func(err error) bool { | |
return !strings.Contains(err.Error(), `NoCredentialProviders: no valid providers in chain`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran the contrib test with ./test.sh --contrib and every test under contrib/aws/aws-sdk-go/aws
succeeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the workflow is still failing - link. Since the error I received signified the lack of credentials, it is possible that you have some environment variables set on your machine. I would recommend to rerun this test specifically and include a different error check.
I have changed the assertion to log the error:
assert.Equal(t, errExist, spans[0].Tag(ext.Error) != nil, fmt.Sprintf("error.message isn't nil: %s", spans[0].Tag(ext.Error)))
Here is the output of running a test on my machine.
Error Trace: /Users/diana.shevchenko/go/src/github.com/dd-trace-go/contrib/aws/aws-sdk-go/aws/aws_test.go:273
Error: Not equal:
expected: false
actual : true
Test: TestWithErrorCheck/errcheck
Messages: error.message isn't nil: NoCredentialProviders: no valid providers in chain. Deprecated.
For verbose messaging see aws.Config.CredentialsChainVerboseErrors
Like I have mentioned previously, the error contains NoCredentialProviders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I didn't think about some issues related to my local environment.
I pushed new code according to your suggestion.
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
|
||
cfg := aws.NewConfig().WithRegion("us-west-2") | ||
sess := session.Must(session.NewSession(cfg)) | ||
sess = awstrace.WrapSession(sess, opts...) | ||
|
||
s3api := s3.New(sess) | ||
s3api.CreateBucket(&s3.CreateBucketInput{ | ||
Bucket: aws.String("some-bucket-name"), | ||
}) | ||
|
||
spans := mt.FinishedSpans() | ||
assert.True(t, len(spans) > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One has to create a span before hand, an example of that can be found in other tests of aws_test.go
.
root, ctx := tracer.StartSpanFromContext(context.Background(), "test")
sess := session.Must(session.NewSession(aws.NewConfig().WithRegion("us-west-2")))
sess = WrapSession(sess, opts...)
s3api := s3.New(sess)
s3api.CreateBucketWithContext(ctx, &s3.CreateBucketInput{
Bucket: aws.String("some-bucket-name"),
})
root.Finish()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the creation of the span.
@dianashevchenko is there still any problem with this PR? I saw it had been tagged as related to v1.49.0 release but then never merged. |
…nflict resolution in tests
LGTM Just a minor change to only check the return boolean value in the tests. As we update AWS libraries, the exact string of the error will most likely change (which it did) and will break the test every time, so we future proofed it by only checking the boolean return value. |
Co-authored-by: Diana Shevchenko <40775148+dianashevchenko@users.noreply.github.com> Co-authored-by: Zarir Hamza <zarir.hamza@datadoghq.com>
Adds an WithErrorCheck function similar to #1682
What does this PR do?
It adds an option to
aws/aws-sdk-go
tracer. This option is calledWithErrorCheck
and it specifies a function which determines whether the passed error should be marked as an error. The fn is called whenever an aws operation finishes with an error.Motivation
This applies the same logic introduced by #1315 on sql tracer.
We need this otherwise DD raises an issue for every kind of error.
Describe how to test/QA your changes
Reviewer's Checklist
Triage
milestone is set.