Skip to content

Conversation

@martincostello
Copy link
Member

Fixes #2241

Changes

Add support for db.query.parameter.<key> for SqlClient and EFCore via new opt-in SetDbQueryParameters option.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added comp:instrumentation.entityframeworkcore Things related to OpenTelemetry.Instrumentation.EntityFrameworkCore comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient labels Aug 20, 2025
@codecov
Copy link

codecov bot commented Aug 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.78%. Comparing base (7cfcb51) to head (26a3f01).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 87.65% <100.00%> (+0.29%) ⬆️
unittests-Exporter.Geneva 53.66% <ø> (+0.33%) ⬆️
unittests-Exporter.InfluxDB 95.14% <ø> (ø)
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <ø> (ø)
unittests-Extensions 90.65% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Instrumentation.AWS 83.80% <ø> (ø)
unittests-Instrumentation.AspNet 74.93% <ø> (-0.25%) ⬇️
unittests-Instrumentation.AspNetCore 70.76% <ø> (ø)
unittests-Instrumentation.Cassandra 23.52% <ø> (ø)
unittests-Instrumentation.ConfluentKafka 14.10% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.12% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 81.06% <100.00%> (+0.23%) ⬆️
unittests-Instrumentation.EventCounters 76.36% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.42% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 79.61% <ø> (ø)
unittests-Instrumentation.Hangfire 84.61% <ø> (ø)
unittests-Instrumentation.Http 74.18% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 34.54% <ø> (ø)
unittests-Instrumentation.SqlClient 87.24% <100.00%> (+0.08%) ⬆️
unittests-Instrumentation.StackExchangeRedis 70.81% <ø> (ø)
unittests-Instrumentation.Wcf 78.95% <ø> (ø)
unittests-OpAmp.Client 61.08% <ø> (ø)
unittests-PersistentStorage 65.21% <ø> (-0.67%) ⬇️
unittests-Resources.AWS 75.00% <ø> (ø)
unittests-Resources.Azure 85.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 73.91% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 88.25% <ø> (ø)

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

Files with missing lines Coverage Δ
...eworkCore/EntityFrameworkInstrumentationOptions.cs 100.00% <100.00%> (ø)
...mplementation/EntityFrameworkDiagnosticListener.cs 85.79% <100.00%> (+0.15%) ⬆️
...ient/Implementation/SqlClientDiagnosticListener.cs 88.75% <100.00%> (+0.14%) ⬆️
....SqlClient/SqlClientTraceInstrumentationOptions.cs 100.00% <100.00%> (ø)
src/Shared/SqlParameterProcessor.cs 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@martincostello martincostello marked this pull request as ready for review August 20, 2025 17:03
Copilot AI review requested due to automatic review settings August 20, 2025 17:03
@martincostello martincostello requested a review from a team as a code owner August 20, 2025 17:03
Copy link
Contributor

Copilot AI left a 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 SqlParameterProcessor to extract and set query parameter attributes from database commands
  • Adds SetDbQueryParameters option 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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@martincostello
Copy link
Member Author

martincostello commented Aug 20, 2025

Well that's new - if you accept any code fix suggestions from Copilot, the CLA check fails 😅

@Kielek
Copy link
Member

Kielek commented Aug 20, 2025

Well that's new - if you accept any code fix suggestions from Copilot, the CLA check fails 😅

Hopefully, it is temporary: open-telemetry/community#2920

/// contain any sensitive data.</b>
/// </para>
/// <para>
/// <b>SetDbQueryParameters is only supported on .NET and .NET Core runtimes.</b>
Copy link
Member

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+

Copy link
Member Author

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".

Copy link
Member

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)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.entityframeworkcore Things related to OpenTelemetry.Instrumentation.EntityFrameworkCore comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sql] Support db.query.parameter.<key> (not required for stable release)

3 participants