Skip to content
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

[SqlClient] Refactor SqlConnectionDetails #2233

Merged

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Oct 21, 2024

This is a refactor that extracts SqlConnectionDetails from the SqlClientTraceInstrumentationOptions class. Evaluating connection details is not specific to spans - it will also be used for DB metrics.

This PR is similar to what is done in #2026. I will deal with the merge conflicts on #2026.

There's a whole bunch that I don't like about the tests for this instrumentation. A lot of copy and paste for .NET vs. .NET Framework tests and inconsistent test cases covering them. This PR does not attempt to address improving tests. I'll do this in a follow on PR before stabilization.

There's also a small bug fix where server.port was captured as a string instead of an int.

@alanwest alanwest requested a review from a team as a code owner October 21, 2024 23:33
@github-actions github-actions bot added the comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient label Oct 21, 2024
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.36%. Comparing base (71655ce) to head (df3190e).
Report is 545 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2233       +/-   ##
===========================================
+ Coverage   73.91%   91.36%   +17.44%     
===========================================
  Files         267        8      -259     
  Lines        9615      301     -9314     
===========================================
- Hits         7107      275     -6832     
+ Misses       2508       26     -2482     
Flag Coverage Δ
unittests-Instrumentation.SqlClient 91.36% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...qlClient/Implementation/SqlActivitySourceHelper.cs 100.00% <100.00%> (ø)
...ient/Implementation/SqlClientDiagnosticListener.cs 87.35% <100.00%> (ø)
...n.SqlClient/Implementation/SqlConnectionDetails.cs 100.00% <100.00%> (ø)
...ent/Implementation/SqlEventSourceListener.netfx.cs 88.23% <100.00%> (ø)
....SqlClient/SqlClientTraceInstrumentationOptions.cs 100.00% <ø> (ø)

... and 267 files with indirect coverage changes

/// <see>
/// <a href="https://docs.microsoft.com/previous-versions/sql/sql-server-2016/ms189307(v=sql.130)"/>
/// </see>
private static readonly Regex NamedPipeRegex = new("pipe\\\\MSSQL\\$(.*?)\\\\", RegexOptions.Compiled);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a RegEx source generator available now. Doesn't have to be part of this PR, but we should probably move to that on targets where it is available. Reason being is I assume it gives best perf across the board but especially when AoT is in play and compilation is not available (assuming RegEx falls back to interpreter when dynamic code isn't available).

Some reasons listed here why it should be used:
https://learn.microsoft.com/dotnet/standard/base-types/regular-expression-source-generators#when-to-use-it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alanwest alanwest merged commit e54b226 into open-telemetry:main Oct 22, 2024
56 checks passed
@alanwest alanwest deleted the alanwest/refactor-sqlconnectiondetails branch October 22, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants