From 8c4d43fe454ef4e609e04948b05dda10184d4e9b Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Fri, 11 Apr 2025 14:38:23 -0700 Subject: [PATCH 1/3] Add db.stored_procedure.name attribute --- .../Implementation/SqlActivitySourceHelper.cs | 3 +-- .../Implementation/SqlClientDiagnosticListener.cs | 7 ++----- src/Shared/SemanticConventions.cs | 3 +-- .../SqlClientTests.cs | 4 +--- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs index b1ad4815ab..54b245c140 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlActivitySourceHelper.cs @@ -34,10 +34,9 @@ internal sealed class SqlActivitySourceHelper internal static readonly string[] SharedTagNames = [ SemanticConventions.AttributeDbSystem, - SemanticConventions.AttributeDbCollectionName, SemanticConventions.AttributeDbNamespace, + SemanticConventions.AttributeDbStoredProcedureName, SemanticConventions.AttributeDbResponseStatusCode, - SemanticConventions.AttributeDbOperationName, SemanticConventions.AttributeErrorType, SemanticConventions.AttributeServerPort, SemanticConventions.AttributeServerAddress, diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs index 0238960214..619a0189eb 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs @@ -115,9 +115,7 @@ public override void OnEventWritten(string name, object? payload) if (options.EmitNewAttributes) { - activity.SetTag(SemanticConventions.AttributeDbOperationName, "EXECUTE"); - activity.SetTag(SemanticConventions.AttributeDbCollectionName, commandText); - activity.SetTag(SemanticConventions.AttributeDbQueryText, commandText); + activity.SetTag(SemanticConventions.AttributeDbStoredProcedureName, commandText); } break; @@ -278,8 +276,7 @@ private void RecordDuration(Activity? activity, object? payload, bool hasError = { if (this.commandTextFetcher.TryFetch(command, out var commandText)) { - tags.Add(SemanticConventions.AttributeDbOperationName, "EXECUTE"); - tags.Add(SemanticConventions.AttributeDbCollectionName, commandText); + tags.Add(SemanticConventions.AttributeDbStoredProcedureName, commandText); } } } diff --git a/src/Shared/SemanticConventions.cs b/src/Shared/SemanticConventions.cs index 8be40f76f7..3daefa77ab 100644 --- a/src/Shared/SemanticConventions.cs +++ b/src/Shared/SemanticConventions.cs @@ -141,13 +141,12 @@ internal static class SemanticConventions // New database conventions as of commit: // https://github.com/open-telemetry/semantic-conventions/blob/25f74191d749645fdd5ec42ae661438cf2c1cf51/docs/database/database-spans.md#common-attributes public const string AttributeDbSystem = "db.system"; - public const string AttributeDbCollectionName = "db.collection.name"; public const string AttributeDbNamespace = "db.namespace"; - public const string AttributeDbOperationName = "db.operation.name"; public const string AttributeDbResponseStatusCode = "db.response.status_code"; public const string AttributeDbOperationBatchSize = "db.operation.batch.size"; public const string AttributeDbQuerySummary = "db.query.summary"; public const string AttributeDbQueryText = "db.query.text"; + public const string AttributeDbStoredProcedureName = "db.stored_procedure.name"; #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } diff --git a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs index 759cf81445..22d26da189 100644 --- a/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs +++ b/test/OpenTelemetry.Instrumentation.SqlClient.Tests/SqlClientTests.cs @@ -482,9 +482,7 @@ internal static void VerifyActivityData( if (emitNewAttributes) { - Assert.Equal("EXECUTE", activity.GetTagValue(SemanticConventions.AttributeDbOperationName)); - Assert.Equal(commandText, activity.GetTagValue(SemanticConventions.AttributeDbCollectionName)); - Assert.Equal(commandText, activity.GetTagValue(SemanticConventions.AttributeDbQueryText)); + Assert.Equal(commandText, activity.GetTagValue(SemanticConventions.AttributeDbStoredProcedureName)); } break; From ae1b39c20b0e512cb3f9de1a59844a68300ec1fe Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Fri, 11 Apr 2025 15:00:44 -0700 Subject: [PATCH 2/3] Update changelog --- src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md index bcb5979742..8bb4008604 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md @@ -6,6 +6,12 @@ connection's `DataSource` when used to populate the `server.address` attribute. ([#2674](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2674)) +* Updates have been made to adhere to recent changes in the new semantic + conventions. These affect you if you have opted in to the new conventions. + When `CommandType` is `StoredProcedure`, the `db.stored_procedure.name` has + been added and the `db.query.text`, `db.operation.name`, and + `db.collection.name` attributes have been removed. + ([#TBD](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/TBD)) ## 1.11.0-beta.2 From 71100ddf761bf0823837262368b37c1644fb406e Mon Sep 17 00:00:00 2001 From: Alan West <3676547+alanwest@users.noreply.github.com> Date: Fri, 11 Apr 2025 15:03:29 -0700 Subject: [PATCH 3/3] Update changelog --- src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md index 8bb4008604..c541c3ab8b 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md @@ -11,7 +11,7 @@ When `CommandType` is `StoredProcedure`, the `db.stored_procedure.name` has been added and the `db.query.text`, `db.operation.name`, and `db.collection.name` attributes have been removed. - ([#TBD](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/TBD)) + ([#2693](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2693)) ## 1.11.0-beta.2