Make SQL settings available unconditionally#1864
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1864 +/- ##
==========================================
+ Coverage 83.79% 83.87% +0.07%
==========================================
Files 251 251
Lines 8857 8857
==========================================
+ Hits 7422 7429 +7
+ Misses 1435 1428 -7
|
45db513 to
87b3051
Compare
|
Ah, this confusing API again! Thanks @roederja2! For context, this was first added in #1599 and then slightly renamed in #1645. The issue we were trying to solve then was this:
So back then we decided to have different API:
The "netcore" options above actually get compiled for the netstandard2.0 target though, which now makes the following scenario (described in #1862 that this PR is about) possible:
Now because classLib is netstandard, it uses the I am not sure what the best way to go about this. I think typically the SDK should be configured by the host code (consoleApp) targeting specific runtime, not the library code. But it looks like there are legitimate scenarios where configuring it in a netstandard library is desirable. Besides this SqlClient api issue, can anyone think of any other problems this might cause? If we want to change the api, there are several options:
Not sure which one is best 🤷 @CodeBlanch , @cijothomas , @roederja2 - any thoughts? |
|
I like option 2. The reason why I have the configuration in a netstandard library is that it is the same for all our services - some of which are already .net core while some are still on framework. |
|
Looking at the comment for |
fa69071 to
daf831e
Compare
There was a problem hiding this comment.
Should this be something like:
bool captureText = this.options.SetDbStatementForText && eventData.EventSource == this.mdsEventSource;
bool captureSp = this.options.SetDbStatementForStoredProcedure && eventData.EventSource == this.adoNetEventSource;
if (captureText || captureSp) { ... }There was a problem hiding this comment.
The logic looks good to me, but it could lead to some confusion. If you have SetDbStatementForText=true & SetDbStatementForStoredProcedure=false and eventData.EventSource != this.adoNetEventSource then you could still end up with stored procedures, which you told it you didn't want. Right?
That is probably not the end of the world, but maybe it would be more clear as an enum?
public enum SqlCommandTextCaptureMode
{
None,
StoredProcedure,
StoredProducureAndText
}🤷
There was a problem hiding this comment.
But then you couldn't capture only Text which is currently possibly under .net core, ok you could turn the enum into flags... But personally I would leave it as it is.
There was a problem hiding this comment.
Ya I did that intentionally. My thinking was... having the two isn't particularly useful to anyone. Is there a use case where you would want Text and not Stored Procedures? I doubt it 😄 IMO most people will do Stored Procedures, some will also kick on Text. But Text and NOT Stored Procedures? The enum simplifies it and is trying to avoid letting users configure something that is impossible.
There was a problem hiding this comment.
StoredProducureAndText is still impossible on .NET framework with System.Data.SqlClient . In any case this will be a breaking change of the API for .NET core users. So far it's only breaking for framework users. As I said, I think the way it is now is fine, but I will change it to an enum if that will get the PR merged :)
|
@roederja2 - thanks! I think this is more clear than what we had before! Still confusing a bit, but can't get away from that with the difference between the event sources it seems. I also like that we can now capture SP on System.Data.SqlClient by default - that's useful (and safe). I've added a couple comments - not sure if I misunderstood the behavior you intended for SetDbStatementForText on adoNet? Would like @cijothomas and @CodeBlanch to take a look as well :) |
|
I think there are some tests that spuriously fail. How do I re-run the failed task? |
Don't think you can unfortunately 😞 . Can only push new commits. Currently only maintainers can re-trigger CI, could be good to have a bot to let more folks do that though. I'll open an issue/suggestion for that to discuss! |
94e6388 to
14e6770
Compare
Simply Close/Open the PR and it'll retrigger every CI. (you can't do individual CI trigger) |
|
Anything else to be done here? Should I change the interface to use an Enum instead. I can confirm that this change works in my setup now to get the sproc name logged by default - using System.Data.SqlClient with net48. |
…`RecordException` available on all platforms. Remove `SetDbStatement`.
cce4786 to
6b1731c
Compare
|
I can't see the codecov report - get a 403 error |
cijothomas
left a comment
There was a problem hiding this comment.
LGTM. This does solves the original runtime issue.
The SetDbStatement config part is not ideal for .NET FW, but given the inherent limitation, this seems a good tradeoff.
|
@mbakalov @CodeBlanch Do you have concerns with this or are we okay for merge? |
…unconditional # Conflicts: # src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
Sorry been away from this for some time! Looks good to me as well! |
|
I just noticed that the HTTP instrumentation has a similar problem. I think it is generally not a good idea to use conditional compilation on public API method signatures in .net standard libraries. |
|
Ping |
I have reached out to .NET team for an official guidance on this issue. (We discussed this in last SIG meeting and decided to get an official recommendation from .NET team before making changes). Will share an update here once we hear back. Thanks for your patience! |
|
Thanks for the update. Here is my suggested fix for the Http instrumentation: #2005 |
…rja2/opentelemetry-dotnet into sql_settings_unconditional
|
Any update on this? |
…unconditional # Conflicts: # src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/net452/PublicAPI.Unshipped.txt # src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
|
@cijothomas : Ping |
|
Is there any update when we might get this moved forward? We are in the process of migrating a large solution across to .net standard with a view to ultimately switching pieces out to dotnet core. We're struggling to implement SQL telemetry as our DB layer is in dotnet standard however the main web application is still dotnet framework so we run into this exact problem. Thanks for all the hard work on this - much appreciated. |
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
|
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Fixes #1862.
Changes
SQL settings should be available regardless of the compile target because .netstandard libraries can be run in framework or .net core. Currently you get runtime exceptions about methods not found when using certain properties and then executing under .net framework.
For significant contributions please make sure you have completed the following items:
CHANGELOG.mdupdated for non-trivial changes