Skip to content

[Instrumentation.EntityFrameworkCore] Add QueryTextSanitizer delegate - #4901

Draft
PetarJerinic wants to merge 8 commits into
open-telemetry:mainfrom
PetarJerinic:feature/efcore-query-text-sanitizer
Draft

[Instrumentation.EntityFrameworkCore] Add QueryTextSanitizer delegate#4901
PetarJerinic wants to merge 8 commits into
open-telemetry:mainfrom
PetarJerinic:feature/efcore-query-text-sanitizer

Conversation

@PetarJerinic

@PetarJerinic PetarJerinic commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #4348

Changes

Adds a QueryTextSanitizer delegate to EntityFrameworkInstrumentationOptions, following the shape discussed on the issue: a single delegate, while keeping the existing behavior where null disables sanitization at the caller's own risk.
On delegate exception, no query text is emitted, please confirm this is the preference.

Not covered

  • EF Core Cosmos does not reach this instrumentation. Cosmos emits a different set of events (ExecutingSqlQuery, ExecutingReadItem, ExecutedReadNext and others). Suggestion is to open a separate issue for it.
  • EF Core MongoDB is in the same position, and the suggestion is to open a separate issue as well.

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)

…. It allows callers to supply their own sanitization for query text captured as db.query.text and db.statement.
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-dotnet-contrib.

Important reminders:

  • Read our Contributing Guidelines.
  • Sign the CLA if you haven't already.
  • Follow the OpenTelemetry Generative AI policy: disclose any AI use in your contribution, and communicate (PR descriptions, review replies) in your own words rather than AI-generated text.
  • Give reviewers at least a few days before pinging them for feedback.
  • If you need help with general setup, development process, or contributor etiquette, ask in #opentelemetry-new-contributors.

@github-actions github-actions Bot added the comp:instrumentation.entityframeworkcore Things related to OpenTelemetry.Instrumentation.EntityFrameworkCore label Jul 26, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 26, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-08-20 15:21 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@PetarJerinic

Copy link
Copy Markdown
Contributor Author

@martincostello I created a draft PR based on the discussion in #4348. Please take a look when you get the chance.

…ueryTextSanitizerShouldNotSanitizeProvidersThatAreNotSqlLike to better represent non sanitized providers
@martincostello

Copy link
Copy Markdown
Member

Not covered

See #3370 (comment) for background on lack of support for CosmosDB.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Aug 10, 2026
…y-text-sanitizer

# Conflicts:
#	src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.81%. Comparing base (034bdf8) to head (2b9b479).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ation/EntityFrameworkInstrumentationEventSource.cs 40.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4901      +/-   ##
==========================================
- Coverage   77.88%   77.81%   -0.07%     
==========================================
  Files         473      475       +2     
  Lines       20205    20243      +38     
==========================================
+ Hits        15736    15753      +17     
- Misses       4469     4490      +21     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 89.92% <ø> (ø)
unittests-Exporter.Geneva 56.40% <ø> (-0.32%) ⬇️
unittests-Exporter.InfluxDB 97.96% <ø> (ø)
unittests-Exporter.OneCollector 95.60% <ø> (ø)
unittests-Extensions 95.74% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 86.27% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <ø> (ø)
unittests-Instrumentation.AWS 85.35% <ø> (ø)
unittests-Instrumentation.AspNet 79.01% <ø> (ø)
unittests-Instrumentation.AspNetCore 87.20% <ø> (ø)
unittests-Instrumentation.Cassandra 92.30% <ø> (ø)
unittests-Instrumentation.ConfluentKafka 83.53% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.36% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 82.47% <93.33%> (+1.44%) ⬆️
unittests-Instrumentation.EventCounters 75.45% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.12% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 78.09% <ø> (ø)
unittests-Instrumentation.Hangfire 88.88% <ø> (ø)
unittests-Instrumentation.Http 75.61% <ø> (ø)
unittests-Instrumentation.Kusto 92.42% <ø> (ø)
unittests-Instrumentation.Owin 89.02% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 77.77% <ø> (ø)
unittests-Instrumentation.Remoting 65.59% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 39.91% <ø> (ø)
unittests-Instrumentation.SqlClient 83.36% <ø> (ø)
unittests-Instrumentation.StackExchangeRedis 94.98% <ø> (ø)
unittests-Instrumentation.Wcf 82.64% <ø> (ø)
unittests-OpAmp.Client 86.78% <ø> (-0.09%) ⬇️
unittests-PersistentStorage 69.20% <ø> (ø)
unittests-Resources.AWS 72.78% <ø> (ø)
unittests-Resources.Azure 84.18% <ø> (ø)
unittests-Resources.Container 80.76% <ø> (ø)
unittests-Resources.Gcp 80.70% <ø> (ø)
unittests-Resources.Host 72.34% <ø> (ø)
unittests-Resources.OperatingSystem 77.16% <ø> (ø)
unittests-Resources.Process 90.90% <ø> (ø)
unittests-Resources.ProcessRuntime 80.76% <ø> (ø)
unittests-Sampler.AWS 96.05% <ø> (ø)

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

Files with missing lines Coverage Δ
....EntityFrameworkCore/DbQuerySanitizationContext.cs 100.00% <100.00%> (ø)
...eworkCore/EntityFrameworkInstrumentationOptions.cs 100.00% <100.00%> (ø)
...mplementation/EntityFrameworkDiagnosticListener.cs 86.97% <100.00%> (+1.18%) ⬆️
...EntityFrameworkCore/QueryTextSanitizationResult.cs 100.00% <100.00%> (ø)
src/Shared/DatabaseSemanticConventionHelper.cs 83.33% <ø> (ø)
...ation/EntityFrameworkInstrumentationEventSource.cs 17.85% <40.00%> (+4.81%) ⬆️

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

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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] Sanitize db.query.text / db.statement for NoSQL-like databases

2 participants