diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/PublicAPI.Unshipped.txt index 2d3a76d224..3cd16fd49a 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/PublicAPI.Unshipped.txt +++ b/src/OpenTelemetry.Instrumentation.SqlClient/.publicApi/PublicAPI.Unshipped.txt @@ -1,7 +1,5 @@ #nullable enable OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions -OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.EnableConnectionLevelAttributes.get -> bool -OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.EnableConnectionLevelAttributes.set -> void OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.get -> System.Action? OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.set -> void OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.get -> System.Func? diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md index b5181622f8..16f15d141d 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* **Breaking change** The `EnableConnectionLevelAttributes` option has been removed. + ([#2414](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2414)) + ## 1.10.0-beta.1 Released 2024-Dec-09 diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs index a176f338d7..a332be18b7 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs @@ -51,7 +51,7 @@ public static TagList GetTagListFromConnectionInfo(string? dataSource, string? d { SemanticConventions.AttributeDbSystem, MicrosoftSqlServerDatabaseSystemName }, }; - if (options.EnableConnectionLevelAttributes && dataSource != null) + if (dataSource != null) { var connectionDetails = SqlConnectionDetails.ParseFromDataSource(dataSource); diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/README.md b/src/OpenTelemetry.Instrumentation.SqlClient/README.md index 6d2fa60f8e..96d36f896b 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/README.md +++ b/src/OpenTelemetry.Instrumentation.SqlClient/README.md @@ -191,29 +191,6 @@ command names will ever be captured. When using the `Microsoft.Data.SqlClient` NuGet package (v1.1+) stored procedure command names, full query text, and other command text will be captured. -### EnableConnectionLevelAttributes - -> [!NOTE] -> EnableConnectionLevelAttributes is supported on all runtimes. - -By default, `EnabledConnectionLevelAttributes` is enabled. -When `EnabledConnectionLevelAttributes` is enabled, -the [`DataSource`](https://docs.microsoft.com/dotnet/api/system.data.common.dbconnection.datasource) -will be parsed and the server name or IP address will be sent as -the `server.address` attribute, the instance name will be sent as -the `db.mssql.instance_name` attribute, and the port will be sent as the -`server.port` attribute if it is not 1433 (the default port). - -The following example shows how to use `EnableConnectionLevelAttributes`. - -```csharp -using var tracerProvider = Sdk.CreateTracerProviderBuilder() - .AddSqlClientInstrumentation( - options => options.EnableConnectionLevelAttributes = true) - .AddConsoleExporter() - .Build(); -``` - ### Enrich > [!NOTE] diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs index 1aa0078e2f..06bee628eb 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientTraceInstrumentationOptions.cs @@ -63,26 +63,6 @@ internal SqlClientTraceInstrumentationOptions(IConfiguration configuration) /// public bool SetDbStatementForText { get; set; } - /// - /// Gets or sets a value indicating whether or not the should parse the DataSource on a - /// SqlConnection into server name, instance name, and/or port - /// connection-level attribute tags. Default value: . - /// - /// - /// - /// EnableConnectionLevelAttributes is supported on all runtimes. - /// - /// - /// If enabled, SqlConnection DataSource will be parsed and the server name will be sent as the - /// tag, - /// the instance name will be sent as the tag, - /// and the port will be sent as the tag if it is not 1433 (the default port). - /// - /// - public bool EnableConnectionLevelAttributes { get; set; } = true; - /// /// Gets or sets an action to enrich an with the /// raw SqlCommand object. diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index a253ef350d..c31cd18c40 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -185,27 +185,23 @@ public void SqlClientCallsAreCollectedSuccessfully( } [Theory] - [InlineData(true, "localhost", "localhost", null, null, null)] - [InlineData(true, "127.0.0.1,1433", null, "127.0.0.1", null, null)] - [InlineData(true, "127.0.0.1,1434", null, "127.0.0.1", null, 1434)] - [InlineData(true, "127.0.0.1\\instanceName, 1818", null, "127.0.0.1", "instanceName", 1818)] - [InlineData(false, "localhost", null, null, null, null)] + [InlineData("localhost", "localhost", null, null, null)] + [InlineData("127.0.0.1,1433", null, "127.0.0.1", null, null)] + [InlineData("127.0.0.1,1434", null, "127.0.0.1", null, 1434)] + [InlineData("127.0.0.1\\instanceName, 1818", null, "127.0.0.1", "instanceName", 1818)] // Test cases when EmitOldAttributes = false and EmitNewAttributes = true (i.e., OTEL_SEMCONV_STABILITY_OPT_IN=database) - [InlineData(true, "localhost", "localhost", null, null, null, false, true)] - [InlineData(true, "127.0.0.1,1433", null, "127.0.0.1", null, null, false, true)] - [InlineData(true, "127.0.0.1,1434", null, "127.0.0.1", null, 1434, false, true)] - [InlineData(true, "127.0.0.1\\instanceName, 1818", null, "127.0.0.1", null, 1818, false, true)] - [InlineData(false, "localhost", null, null, null, null, false, true)] + [InlineData("localhost", "localhost", null, null, null, false, true)] + [InlineData("127.0.0.1,1433", null, "127.0.0.1", null, null, false, true)] + [InlineData("127.0.0.1,1434", null, "127.0.0.1", null, 1434, false, true)] + [InlineData("127.0.0.1\\instanceName, 1818", null, "127.0.0.1", null, 1818, false, true)] // Test cases when EmitOldAttributes = true and EmitNewAttributes = true (i.e., OTEL_SEMCONV_STABILITY_OPT_IN=database/dup) - [InlineData(true, "localhost", "localhost", null, null, null, true, true)] - [InlineData(true, "127.0.0.1,1433", null, "127.0.0.1", null, null, true, true)] - [InlineData(true, "127.0.0.1,1434", null, "127.0.0.1", null, 1434, true, true)] - [InlineData(true, "127.0.0.1\\instanceName, 1818", null, "127.0.0.1", "instanceName", 1818, true, true)] - [InlineData(false, "localhost", null, null, null, null, true, true)] + [InlineData("localhost", "localhost", null, null, null, true, true)] + [InlineData("127.0.0.1,1433", null, "127.0.0.1", null, null, true, true)] + [InlineData("127.0.0.1,1434", null, "127.0.0.1", null, 1434, true, true)] + [InlineData("127.0.0.1\\instanceName, 1818", null, "127.0.0.1", "instanceName", 1818, true, true)] public void SqlClientAddsConnectionLevelAttributes( - bool enableConnectionLevelAttributes, string dataSource, string? expectedServerHostName, string? expectedServerIpAddress, @@ -216,7 +212,6 @@ public void SqlClientAddsConnectionLevelAttributes( { var options = new SqlClientTraceInstrumentationOptions() { - EnableConnectionLevelAttributes = enableConnectionLevelAttributes, EmitOldAttributes = emitOldAttributes, EmitNewAttributes = emitNewAttributes, }; diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs index 891395edd8..023b5bd67d 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlEventSourceTests.netfx.cs @@ -37,7 +37,6 @@ public static IEnumerable EventSourceFakeTestCases() from commandType in new[] { CommandType.StoredProcedure, CommandType.Text } from isFailure in bools from captureText in bools - from enableConnectionLevelAttributes in bools from emitOldAttributes in bools from emitNewAttributes in bools from tracingEnabled in bools @@ -56,7 +55,6 @@ where emitOldAttributes && emitNewAttributes captureText, isFailure, sqlExceptionNumber, - enableConnectionLevelAttributes, emitOldAttributes, emitNewAttributes, tracingEnabled, @@ -120,7 +118,6 @@ public void EventSourceFakeTests( bool captureText, bool isFailure = false, int sqlExceptionNumber = 0, - bool enableConnectionLevelAttributes = false, bool emitOldAttributes = true, bool emitNewAttributes = false, bool tracingEnabled = true, @@ -139,7 +136,6 @@ public void EventSourceFakeTests( .AddSqlClientInstrumentation(options => { options.SetDbStatementForText = captureText; - options.EnableConnectionLevelAttributes = enableConnectionLevelAttributes; options.EmitOldAttributes = emitOldAttributes; options.EmitNewAttributes = emitNewAttributes; }); @@ -187,7 +183,7 @@ public void EventSourceFakeTests( if (tracingEnabled) { activity = Assert.Single(activities); - VerifyActivityData(commandText, captureText, isFailure, dataSource, activity, enableConnectionLevelAttributes, emitOldAttributes, emitNewAttributes); + VerifyActivityData(commandText, captureText, isFailure, dataSource, activity, emitOldAttributes, emitNewAttributes); } var dbClientOperationDurationMetrics = metrics @@ -308,11 +304,10 @@ private static void VerifyActivityData( bool isFailure, string dataSource, Activity activity, - bool enableConnectionLevelAttributes = false, bool emitOldAttributes = true, bool emitNewAttributes = false) { - if (emitNewAttributes && enableConnectionLevelAttributes) + if (emitNewAttributes) { Assert.Equal("instanceName.master", activity.DisplayName); } @@ -324,32 +319,29 @@ private static void VerifyActivityData( Assert.Equal(ActivityKind.Client, activity.Kind); Assert.Equal(SqlActivitySourceHelper.MicrosoftSqlServerDatabaseSystemName, activity.GetTagValue(SemanticConventions.AttributeDbSystem)); - if (enableConnectionLevelAttributes) - { - var connectionDetails = SqlConnectionDetails.ParseFromDataSource(dataSource); + var connectionDetails = SqlConnectionDetails.ParseFromDataSource(dataSource); - if (!string.IsNullOrEmpty(connectionDetails.ServerHostName)) - { - Assert.Equal(connectionDetails.ServerHostName, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); - } - else - { - Assert.Equal(connectionDetails.ServerIpAddress, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); - } + if (!string.IsNullOrEmpty(connectionDetails.ServerHostName)) + { + Assert.Equal(connectionDetails.ServerHostName, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); + } + else + { + Assert.Equal(connectionDetails.ServerIpAddress, activity.GetTagValue(SemanticConventions.AttributeServerAddress)); + } - if (emitOldAttributes && !string.IsNullOrEmpty(connectionDetails.InstanceName)) - { - Assert.Equal(connectionDetails.InstanceName, activity.GetTagValue(SemanticConventions.AttributeDbMsSqlInstanceName)); - } - else - { - Assert.Null(activity.GetTagValue(SemanticConventions.AttributeDbMsSqlInstanceName)); - } + if (emitOldAttributes && !string.IsNullOrEmpty(connectionDetails.InstanceName)) + { + Assert.Equal(connectionDetails.InstanceName, activity.GetTagValue(SemanticConventions.AttributeDbMsSqlInstanceName)); + } + else + { + Assert.Null(activity.GetTagValue(SemanticConventions.AttributeDbMsSqlInstanceName)); + } - if (connectionDetails.Port.HasValue) - { - Assert.Equal(connectionDetails.Port, activity.GetTagValue(SemanticConventions.AttributeServerPort)); - } + if (connectionDetails.Port.HasValue) + { + Assert.Equal(connectionDetails.Port, activity.GetTagValue(SemanticConventions.AttributeServerPort)); } if (emitOldAttributes) @@ -359,7 +351,7 @@ private static void VerifyActivityData( if (emitNewAttributes) { - Assert.Equal(!enableConnectionLevelAttributes ? "master" : "instanceName.master", activity.GetTagValue(SemanticConventions.AttributeDbNamespace)); + Assert.Equal("instanceName.master", activity.GetTagValue(SemanticConventions.AttributeDbNamespace)); } if (captureText)