-
Notifications
You must be signed in to change notification settings - Fork 355
[SqlClient] [EFCore] Support query parameter attributes #3015
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3015 +/- ##
==========================================
+ Coverage 69.66% 69.78% +0.11%
==========================================
Files 413 414 +1
Lines 16229 16246 +17
==========================================
+ Hits 11306 11337 +31
+ Misses 4923 4909 -14 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
src/OpenTelemetry.Instrumentation.EntityFrameworkCore/.publicApi/PublicAPI.Unshipped.txt
Show resolved
Hide resolved
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.
Pull Request Overview
This PR adds support for capturing database query parameters as OpenTelemetry attributes in both SqlClient and Entity Framework Core instrumentations. The feature is opt-in through a new SetDbQueryParameters configuration option and adds parameters as db.query.parameter.<key> tags on database spans.
- Introduces
SqlParameterProcessorto extract and set query parameter attributes from database commands - Adds
SetDbQueryParametersoption to both SqlClient and Entity Framework Core instrumentation options - Refactors Docker platform detection logic into shared helper classes for better code organization
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Shared/SqlParameterProcessor.cs |
Core logic for extracting database parameters and adding them as activity tags |
src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs |
Adds SetDbQueryParameters option to SqlClient instrumentation |
src/OpenTelemetry.Instrumentation.EntityFrameworkCore/EntityFrameworkInstrumentationOptions.cs |
Adds SetDbQueryParameters option to EF Core instrumentation |
test/Shared/DockerHelper.cs |
Refactored Docker platform detection logic into reusable helper |
test/OpenTelemetry.Contrib.Shared.Tests/SqlParameterProcessorTests.cs |
Comprehensive unit tests for parameter processing functionality |
| Various test files | Updated to use refactored Docker helpers and added integration tests for parameter capture |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.EntityFrameworkCore/EntityFrameworkInstrumentationOptions.cs
Outdated
Show resolved
Hide resolved
|
Well that's new - if you accept any code fix suggestions from Copilot, the CLA check fails 😅 |
be0b7b3 to
230daaf
Compare
Hopefully, it is temporary: open-telemetry/community#2920 |
...etry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs
Outdated
Show resolved
Hide resolved
| /// contain any sensitive data.</b> | ||
| /// </para> | ||
| /// <para> | ||
| /// <b>SetDbQueryParameters is only supported on .NET and .NET Core runtimes.</b> |
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.
In general, .NET Core is no longer supported. We are testing only with .NEt8+
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 assumed this was present in the comment I copied from to cover netstandard2.0. If we don't want to use the old terminology anymore than I can either remove it from all the relevant properties, or reword it to say "not .NET Framework".
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.
It makes sense, it can be done for whole project/repo in the separate PR.
| } | ||
| #endif | ||
|
|
||
| if (options.SetDbQueryParameters) |
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.
Only if AllDataRequested and new convention.
Fixes #2241
Changes
Add support for
db.query.parameter.<key>for SqlClient and EFCore via new opt-inSetDbQueryParametersoption.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes