Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#nullable enable
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity!, string!, object!>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.get -> System.Func<object!, bool>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.set -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#nullable enable
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity!, string!, object!>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.get -> System.Func<object!, bool>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.set -> void
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#nullable enable
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity!, string!, object!>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.get -> System.Func<object!, bool>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.SqlClientTraceInstrumentationOptions() -> void
OpenTelemetry.Metrics.SqlClientMeterProviderBuilderExtensions
OpenTelemetry.Trace.TracerProviderBuilderExtensions
Expand Down
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
Behaviors related to this option are now always enabled.
([#3072](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3072))

* **Breaking change**: The `Enrich`, `Filter` and `RecordException` properties have
been removed for .NET Framework where they were non-functional.
([#3079](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/3079))

## 1.12.0-beta.2

Released 2025-Jul-15
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

Choose a reason for hiding this comment

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

@rajkumar-rangaraj, @alanwest, what is your opinion here?
Can we ignore this? .NET Standard target has broader API than .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.

I'm fine with removing it. @alanwest Your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I'm unclear on what's being proposed. Are you asking whether we should remove Filter, Enrich, RecordException from the netstandard build as well?

Copy link
Member

Choose a reason for hiding this comment

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

Only from .net framework, but it leads to warnings muted in this file.
Methods removed int his PR are noop in .net fx

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 think this is only needed until the next version ships to NuGet, then it can be deleted as the baseline in NuGet.org will match.

Copy link
Member

Choose a reason for hiding this comment

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

Methods removed int his PR are noop in .net fx

Then yes it sounds like it's safe to keep the APIs in the netstandard build.

<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.get_Enrich</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.get_Filter</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.get_RecordException</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.set_Enrich(System.Action{System.Diagnostics.Activity,System.String,System.Object})</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.set_Filter(System.Func{System.Object,System.Boolean})</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.set_RecordException(System.Boolean)</Target>
<Left>lib/netstandard2.0/OpenTelemetry.Instrumentation.SqlClient.dll</Left>
<Right>lib/net462/OpenTelemetry.Instrumentation.SqlClient.dll</Right>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ public override void OnEventWritten(string name, object? payload)
{
try
{
#if !NETFRAMEWORK
if (options.Filter?.Invoke(command) == false)
{
SqlClientInstrumentationEventSource.Log.CommandIsFilteredOut(activity.OperationName);
activity.IsAllDataRequested = false;
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
return;
}
#endif
}
catch (Exception ex)
{
Expand Down Expand Up @@ -175,6 +177,7 @@ public override void OnEventWritten(string name, object? payload)
}
}

#if !NETFRAMEWORK
try
{
options.Enrich?.Invoke(activity, "OnCustom", command);
Expand All @@ -183,6 +186,7 @@ public override void OnEventWritten(string name, object? payload)
{
SqlClientInstrumentationEventSource.Log.EnrichmentException(ex);
}
#endif
}
}

Expand Down Expand Up @@ -261,10 +265,12 @@ public override void OnEventWritten(string name, object? payload)

activity.SetStatus(ActivityStatusCode.Error, exception.Message);

#if !NETFRAMEWORK
if (options.RecordException)
{
activity.AddException(exception);
}
#endif
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#if !NETFRAMEWORK
using System.Diagnostics;
#endif
using Microsoft.Extensions.Configuration;
#if NET
using OpenTelemetry.Instrumentation.SqlClient.Implementation;
Expand Down Expand Up @@ -56,6 +58,7 @@ internal SqlClientTraceInstrumentationOptions(IConfiguration configuration)
#endif
}

#if !NETFRAMEWORK
/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with the
/// raw <c>SqlCommand</c> object.
Expand Down Expand Up @@ -106,6 +109,7 @@ internal SqlClientTraceInstrumentationOptions(IConfiguration configuration)
/// href="https://github.com/open-telemetry/semantic-conventions/blob/main/docs/exceptions/exceptions-spans.md"/>.</para>
/// </remarks>
public bool RecordException { get; set; }
#endif

#if !NETFRAMEWORK
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public void SuccessfulCommandTest(
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.SetSampler(sampler)
.AddInMemoryExporter(activities)
.AddSqlClientInstrumentation(options => options.RecordException = recordException)
.AddSqlClientInstrumentation(options =>
{
#if NET
options.RecordException = recordException;
#endif
})
.Build();

using var sqlConnection = new SqlConnection(this.GetConnectionString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ public void SpansAndMetricsGeneratedOnlyWhenEnabled(bool tracesEnabled, bool met
if (tracesEnabled)
{
tracerProviderBuilder
.AddSqlClientInstrumentation(options => options.RecordException = true)
.AddSqlClientInstrumentation(options =>
{
#if NET
options.RecordException = true;
#endif
})
.AddInMemoryExporter(activities);
}

Expand Down Expand Up @@ -337,7 +342,9 @@ private void RunSqlClientTestCase(
.SetSampler(sampler)
.AddSqlClientInstrumentation(options =>
{
#if NET
options.RecordException = true;
#endif
options.EmitOldAttributes = emitOldAttributes;
options.EmitNewAttributes = emitNewAttributes;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System.Data;
using System.Diagnostics;
#if NET
using Microsoft.Data.SqlClient;
#endif
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Internal;
Expand Down Expand Up @@ -238,7 +240,6 @@ public void ShouldAssignSetDatabaseQueryParametersFromEnvironmentVariable(string
var options = new SqlClientTraceInstrumentationOptions(configuration);
Assert.Equal(expected, options.SetDbQueryParameters);
}
#endif

private static void ActivityEnrichment(Activity activity, string method, object obj)
{
Expand Down Expand Up @@ -274,4 +275,5 @@ private Activity[] RunCommandWithFilter(

return [.. activities];
}
#endif
}
Loading