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

feature: Add .NET 8+ support for System.Data.Odbc #2948

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

nr-ahemsath
Copy link
Member

@nr-ahemsath nr-ahemsath commented Jan 14, 2025

Description

This PR adds datastore instrumentation for System.Data.Odbc, which is Microsoft's implementation of ODBC access for modern .NET. This resolves #2922.

Note that the instrumentation is less complete than for ODBC operations in .NET Framework applications. In particular, the following things that are instrumented in .NET Framework are not instrumented for .NET 8+:

  • Connect/ConnectAsync calls
  • Database read iteration calls (note that these aren't enabled by default for .NET Framework either due to performance concerns)
  • SQL explain plans

Author Checklist

  • Unit tests, Integration tests, and Unbounded tests completed
  • Performance testing completed with satisfactory results (if required) N/A

Reviewer Checklist

  • Perform code review
  • Pull request was adequately tested (new/existing tests, performance tests)

@nr-ahemsath nr-ahemsath requested a review from a team as a code owner January 14, 2025 17:36
@nr-ahemsath nr-ahemsath marked this pull request as draft January 14, 2025 18:34
Also fix bug where server/hostname string with port included (e.g. "myservername:1234") wasn't handled correctly
@nr-ahemsath nr-ahemsath marked this pull request as ready for review January 14, 2025 21:29
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 74.28571% with 27 lines in your changes missing coverage. Please review.

Project coverage is 81.78%. Comparing base (ee0dd2b) to head (235bbb3).

Files with missing lines Patch % Lines
...ing/ConnectionString/OdbcConnectionStringParser.cs 68.57% 11 Missing and 11 partials ⚠️
...Relic.Agent.Extensions/Parsing/SqlWrapperHelper.cs 85.71% 2 Missing and 1 partial ⚠️
...g/ConnectionString/IbmDb2ConnectionStringParser.cs 66.66% 0 Missing and 1 partial ⚠️
...ng/ConnectionString/MySqlConnectionStringParser.cs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2948      +/-   ##
==========================================
- Coverage   81.80%   81.78%   -0.02%     
==========================================
  Files         470      471       +1     
  Lines       29949    30035      +86     
  Branches     3327     3349      +22     
==========================================
+ Hits        24499    24564      +65     
- Misses       4658     4670      +12     
- Partials      792      801       +9     
Flag Coverage Δ
Agent 82.73% <74.28%> (-0.03%) ⬇️
Profiler 73.13% <ø> (ø)

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

Files with missing lines Coverage Δ
...gent/Core/Attributes/AttributeDefinitionService.cs 95.71% <ø> (ø)
...Relic.Agent.Extensions/Helpers/StringSeparators.cs 100.00% <100.00%> (ø)
...arsing/ConnectionString/IConnectionStringParser.cs 100.00% <100.00%> (+10.52%) ⬆️
...ng/ConnectionString/MsSqlConnectionStringParser.cs 69.49% <100.00%> (ø)
...g/ConnectionString/OracleConnectionStringParser.cs 78.48% <ø> (ø)
...ConnectionString/PostgresConnectionStringParser.cs 63.15% <ø> (ø)
...String/StackExchangeRedisConnectionStringParser.cs 83.33% <ø> (ø)
...ic.Agent.Extensions/Providers/Wrapper/Constants.cs 91.42% <ø> (ø)
...g/ConnectionString/IbmDb2ConnectionStringParser.cs 69.23% <66.66%> (ø)
...ng/ConnectionString/MySqlConnectionStringParser.cs 88.46% <0.00%> (ø)
... and 2 more

... and 1 file with indirect coverage changes

if (host == null) return null;

// Example of want we would need to process: win-database.pdx.vm.datanerd.us,1433\SQLEXPRESS
try
Copy link
Member

Choose a reason for hiding this comment

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

This try/catch block seems unnecessary. Looks like the code is already handling all the edge cases that are possible.

portPathOrId = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;
if (portPathOrId == null) return null;

try
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here. I'm not seeing any execution path where an exception could be thrown.

var endOfValue = portPathOrId.Contains(StringSeparators.BackslashChar)
? portPathOrId.IndexOf(StringSeparators.BackslashChar)
: portPathOrId.Length;
return (startOfValue > 0) ? portPathOrId.Substring(startOfValue, endOfValue - startOfValue) : null;
Copy link
Member

Choose a reason for hiding this comment

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

The ternary here (and on line 74 above) isn't necessary -- startOfValue will always be > 0.

var instanceName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;
if (instanceName == null) return null;

try
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary try/catch here also

{
var startOfValue = instanceName.IndexOf(StringSeparators.BackslashChar) + 1;
var endOfValue = instanceName.Length;
return (startOfValue > 0) ? instanceName.Substring(startOfValue, endOfValue - startOfValue) : null;
Copy link
Member

Choose a reason for hiding this comment

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

Ternary here is also unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update ODBC Support to include .NET Core+ and capturing ODBC connection details.
5 participants