Skip to content

Commit abe21ba

Browse files
[EFCore] [SqlClient] Remove SetDbStatementFor* options (#3072)
1 parent b324796 commit abe21ba

File tree

18 files changed

+157
-398
lines changed

18 files changed

+157
-398
lines changed

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/.publicApi/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentation
44
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.Filter.set -> void
55
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbQueryParameters.get -> bool
66
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbQueryParameters.set -> void
7-
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbStatementForStoredProcedure.get -> bool
8-
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbStatementForStoredProcedure.set -> void
9-
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbStatementForText.get -> bool
10-
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.SetDbStatementForText.set -> void
117
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.EnrichWithIDbCommand.get -> System.Action<System.Diagnostics.Activity!, System.Data.IDbCommand!>?
128
OpenTelemetry.Instrumentation.EntityFrameworkCore.EntityFrameworkInstrumentationOptions.EnrichWithIDbCommand.set -> void
139
OpenTelemetry.Trace.TracerProviderBuilderExtensions

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
* Add the `db.query.summary` attribute and use it for the trace span name when opted
2222
into using the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable.
2323
([#3022](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3022))
24-
* The `db.statement` and `db.query.text` attributes added when `SetDbStatementForText`
25-
is `true` are now sanitized when using specific SQL-like EFCore providers.
24+
* The `db.statement` and `db.query.text` attributes are now sanitized when using
25+
specific SQL-like EFCore providers.
2626
([#3022](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3022))
27+
* **Breaking change**: The `SetDbStatementForStoredProcedure` and
28+
`SetDbStatementForText` properties have been removed. Behaviors related to this
29+
option are now always enabled.
30+
([#3072](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3072))
2731

2832
## 1.12.0-beta.2
2933

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/EntityFrameworkInstrumentationOptions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ internal EntityFrameworkInstrumentationOptions(IConfiguration configuration)
2828
this.EmitNewAttributes = databaseSemanticConvention.HasFlag(DatabaseSemanticConvention.New);
2929
}
3030

31-
/// <summary>
32-
/// Gets or sets a value indicating whether or not the <see cref="EntityFrameworkInstrumentation"/> should add the names of <see cref="CommandType.StoredProcedure"/> commands as the <see cref="Trace.SemanticConventions.AttributeDbStatement"/> tag. Default value: True.
33-
/// </summary>
34-
public bool SetDbStatementForStoredProcedure { get; set; } = true;
35-
36-
/// <summary>
37-
/// Gets or sets a value indicating whether or not the <see cref="EntityFrameworkInstrumentation"/> should add the text of <see cref="CommandType.Text"/> commands as the <see cref="Trace.SemanticConventions.AttributeDbStatement"/> tag. Default value: False.
38-
/// </summary>
39-
public bool SetDbStatementForText { get; set; }
40-
4131
/// <summary>
4232
/// Gets or sets an action to enrich an Activity from the db command.
4333
/// </summary>

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,32 +165,24 @@ public override void OnEventWritten(string name, object? payload)
165165
switch (commandType)
166166
{
167167
case CommandType.StoredProcedure:
168-
if (this.options.SetDbStatementForStoredProcedure)
169-
{
170-
DatabaseSemanticConventionHelper.ApplyConventionsForStoredProcedure(
171-
activity,
172-
commandText,
173-
this.options.EmitOldAttributes,
174-
this.options.EmitNewAttributes);
175-
}
176-
168+
DatabaseSemanticConventionHelper.ApplyConventionsForStoredProcedure(
169+
activity,
170+
commandText,
171+
this.options.EmitOldAttributes,
172+
this.options.EmitNewAttributes);
177173
break;
178174

179175
case CommandType.Text:
180-
if (this.options.SetDbStatementForText)
181-
{
182-
// Only SQL-like providers support sanitization as we are not
183-
// able to sanitize arbitrary commands for other query dialects.
184-
bool sanitizeQuery = IsSqlLikeProvider(providerName);
185-
186-
DatabaseSemanticConventionHelper.ApplyConventionsForQueryText(
187-
activity,
188-
commandText,
189-
this.options.EmitOldAttributes,
190-
this.options.EmitNewAttributes,
191-
sanitizeQuery);
192-
}
193-
176+
// Only SQL-like providers support sanitization as we are not
177+
// able to sanitize arbitrary commands for other query dialects.
178+
bool sanitizeQuery = IsSqlLikeProvider(providerName);
179+
180+
DatabaseSemanticConventionHelper.ApplyConventionsForQueryText(
181+
activity,
182+
commandText,
183+
this.options.EmitOldAttributes,
184+
this.options.EmitNewAttributes,
185+
sanitizeQuery);
194186
break;
195187

196188
case CommandType.TableDirect:

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,6 @@ services.AddOpenTelemetry()
141141
.AddConsoleExporter());
142142
```
143143

144-
### SetDbStatementForText
145-
146-
`SetDbStatementForText` controls whether the `db.statement` attribute is
147-
emitted. The behavior of `SetDbStatementForText` depends on the runtime used,
148-
see below for more details.
149-
150-
Query text may contain sensitive data, so when `SetDbStatementForText` is
151-
enabled the raw query text is sanitized by automatically replacing literal
152-
values with a `?` character.
153-
154-
> [!NOTE]
155-
> Query sanitization is only supported for the following SQL-like providers:
156-
>
157-
> * Firebird
158-
> * GCP Spanner
159-
> * IBM DB2
160-
> * Microsoft SQL Server
161-
> * MySQL
162-
> * Oracle
163-
> * PostgreSQL
164-
> * SQLite
165-
> * Teradata
166-
167144
### SetDbQueryParameters
168145

169146
`SetDbQueryParameters` controls whether `db.query.parameter.<key>` attributes
@@ -183,7 +160,7 @@ following configuration.
183160
```csharp
184161
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
185162
.AddEntityFrameworkCoreInstrumentation(
186-
options => options.SetDbStatementForText = true)
163+
options => options.SetDbQueryParameters = true)
187164
.AddConsoleExporter()
188165
.Build();
189166
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable

src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Rec
88
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.set -> void
99
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SetDbQueryParameters.get -> bool
1010
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SetDbQueryParameters.set -> void
11-
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SetDbStatementForText.get -> bool
12-
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SetDbStatementForText.set -> void
1311
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SqlClientTraceInstrumentationOptions() -> void
1412
OpenTelemetry.Metrics.SqlClientMeterProviderBuilderExtensions
1513
OpenTelemetry.Trace.TracerProviderBuilderExtensions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable

src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
listener.
1111
([#3041](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3041))
1212

13+
* **Breaking change**: The `SetDbStatementForText` property has been removed.
14+
Behaviors related to this option are now always enabled.
15+
([#3072](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3072))
16+
1317
## 1.12.0-beta.2
1418

1519
Released 2025-Jul-15

src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,11 @@ public override void OnEventWritten(string name, object? payload)
162162
break;
163163

164164
case CommandType.Text:
165-
if (options.SetDbStatementForText)
166-
{
167-
DatabaseSemanticConventionHelper.ApplyConventionsForQueryText(
168-
activity,
169-
commandText,
170-
options.EmitOldAttributes,
171-
options.EmitNewAttributes);
172-
}
173-
165+
DatabaseSemanticConventionHelper.ApplyConventionsForQueryText(
166+
activity,
167+
commandText,
168+
options.EmitOldAttributes,
169+
options.EmitNewAttributes);
174170
break;
175171

176172
case CommandType.TableDirect:

0 commit comments

Comments
 (0)