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
@@ -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<System.Diagnostics.Activity!, string!, object!>?
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.SqlClient.SqlClientTraceInstrumentationOptions.Filter.get -> System.Func<object!, bool>?
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 0 additions & 23 deletions src/OpenTelemetry.Instrumentation.SqlClient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,6 @@ internal SqlClientTraceInstrumentationOptions(IConfiguration configuration)
/// </remarks>
public bool SetDbStatementForText { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not the <see
/// cref="SqlClientInstrumentation"/> should parse the DataSource on a
/// SqlConnection into server name, instance name, and/or port
/// connection-level attribute tags. Default value: <see
/// langword="true"/>.
/// </summary>
/// <remarks>
/// <para>
/// <b>EnableConnectionLevelAttributes is supported on all runtimes.</b>
/// </para>
/// <para>
/// If enabled, SqlConnection DataSource will be parsed and the server name will be sent as the
/// <see cref="SemanticConventions.AttributeServerAddress"/> tag,
/// the instance name will be sent as the <see cref="SemanticConventions.AttributeDbMsSqlInstanceName"/> tag,
/// and the port will be sent as the <see cref="SemanticConventions.AttributeServerPort"/> tag if it is not 1433 (the default port).
/// </para>
/// </remarks>
public bool EnableConnectionLevelAttributes { get; set; } = true;

/// <summary>
/// Gets or sets an action to enrich an <see cref="Activity"/> with the
/// raw <c>SqlCommand</c> object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -216,7 +212,6 @@ public void SqlClientAddsConnectionLevelAttributes(
{
var options = new SqlClientTraceInstrumentationOptions()
{
EnableConnectionLevelAttributes = enableConnectionLevelAttributes,
EmitOldAttributes = emitOldAttributes,
EmitNewAttributes = emitNewAttributes,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static IEnumerable<object[]> 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
Expand All @@ -56,7 +55,6 @@ where emitOldAttributes && emitNewAttributes
captureText,
isFailure,
sqlExceptionNumber,
enableConnectionLevelAttributes,
emitOldAttributes,
emitNewAttributes,
tracingEnabled,
Expand Down Expand Up @@ -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,
Expand All @@ -139,7 +136,6 @@ public void EventSourceFakeTests(
.AddSqlClientInstrumentation(options =>
{
options.SetDbStatementForText = captureText;
options.EnableConnectionLevelAttributes = enableConnectionLevelAttributes;
options.EmitOldAttributes = emitOldAttributes;
options.EmitNewAttributes = emitNewAttributes;
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading