-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add command text to SQL command #49
Add command text to SQL command #49
Conversation
Hi @jaredcnance , We will get our security team review it as soon as possible. In the mean time could you confirm Thank you for the contribution. Best |
7c739bf
to
c7f1936
Compare
@yogiraj07 I've updated the PR to use In the absence of an ORM you would write your queries like: const string userId = "my-id";
using (var conn = new SqlConnection(connString))
{
var cmd = new SqlCommand("Select * From users Where userId=@userId", conn);
cmd.Parameters.Add(new SqlParameter("@userId", userId));
// the command text will not contain the parameter values
Assert.DoesNotContain(cmd.CommandText, userId);
// send the query
await conn.OpenAsync();
using(var reader = await cmd.ExecuteReaderAsync())
while(await reader.ReadAsync()) { /* ... */ }
} This puts the burden on the developers but also avoids any magic in-process string replacement and unnecessary allocations. There are also performance benefits when using parameterized queries (e.g. SQLServer caches the query execution plan instead of creating a new one). It seems that there is a mix of positions on this across the SDKs. The response for Java in January was "not yet". But it seems like it is already supported in go and python. Could this be put behind a global options flag that's disabled by default? At a minimum, I think aws-xray-sdk-dotnet/sdk/src/Handlers/SqlServer/TraceableSqlCommand.netstandard.cs Line 443 in 831c7e6
|
Hi @jaredcnance , |
@yogiraj07 I agree that All I want to do is add data to the published payload—whether or not |
Hi @jaredcnance , In addition to this, I think Can you please make the changes to both .NET and .NET Core platform. Thanks, |
Hi @jaredcnance , Please let me know. Thanks, |
@yogiraj07 i have the implementation completed already but it's my opinion that there need to be tests on this before it rolls out. The current design makes testing
So, mocking/stubbing the sql operations is not easy without some ugly decisions (such as creating a
So, at a minimum we need to:
In addition to the tests, I think configuring the collection of SQL queries should be 2 fold:
Let me know what your thoughts are and I can finish this work up. Also: this repo needs automated tests for CI. I am working on OSX and can't build the full-framework version (net45 runtime). |
Hi @jaredcnance , I think, XRayOptions and constructor options, as 2 way opt-in way is okay. However, we can document it clearly the precedence of constructor value is over the XRayOptions value. By default, in either case, the value will be We also need tests for XRayOptions. Once the PR is finalize, I will do a fast follow-up for NET45. Sure, I have CI for the repo in the backlog and will prioritize it soon. |
Converts XRayOptions fields to auto-properties Adds InternalsVisibleTo so tests can access internal members
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.
Hi @jaredcnance ,
Minor changes, but logically it looks good. I will do local testing soon. Thanks for the updates.
Best,
Yogi
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.
Hi @jaredcnance , Thank you for the update. I would expedite internal security review process and merge the PR at the earliest. As a fast follow-up, after merging the PR, I would add this support to NET45 platform.
Hi @jaredcnance , This is my json {
"XRay": {
"DisableXRayTracing": "false",
"SamplingRuleManifest": "sampling-rules.json",
"UseRuntimeErrors": "true",
"CollectSqlQueries": "true"
}
}
However, ShouldCollectSqlText returns false. The reason is, |
Ah, I see. Instead of the services.Configure<XRayOptions>(Configuration.GetSection("XRay"));
// or
var options = new XRayOptions();
Configuration.GetSection("XRay").Bind(options); But, for now I can make the change to add the |
@jaredcnance , good point. For the moment you can also add unit test for the new configuration. |
Any update on this @jaredcnance or @yogiraj07? What is missing to get this merged and a version published? |
@jaredcnance , can you submit another revision with necessary changes requested? I have added CI, the current PR fails while building since the changes are only for NET Core. The CI will help you to make changes only for NET Core platform. If you are okay, I can make those changes on your behalf and expedite the implementation for NET 45 framework. |
@yogiraj07 go ahead and commit on top of my branch, I don't think I will have cycles to work on this anytime soon. |
Issue #, if available: None
Description of changes: Adds the parameterized SQL command to the metadata. I tried adding it using the
AddSqlInformation
API, but it isn't available in the console/UI so I suspect there is a requisite backend change to handle this. I don't really expect this to get merged, but hope to either get some advice on how this should be done today, or start a discussion on how it should be done in the future.Example content of
CommandText
(generated by EntityFrameworkCore):It would be nice to strip the newlines out or pretty print them. That probably shouldn't be done application side since it could result in lots of string allocations, but it might make sense on the console side of things, especially if it receives special treatment as SQL command text.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.