From e7ddb122c3486564c20629db80457fd17f6c213f Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Thu, 12 Jun 2025 16:40:18 -0700 Subject: [PATCH 1/8] Add dashbase context propagation via `SET CONTEXT_INFO` for SQL Server --- .../sql-server-context-info-propagation.yaml | 22 +++++++++++++ docs/database/sql-server.md | 33 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .chloggen/sql-server-context-info-propagation.yaml diff --git a/.chloggen/sql-server-context-info-propagation.yaml b/.chloggen/sql-server-context-info-propagation.yaml new file mode 100644 index 0000000000..8f050f0648 --- /dev/null +++ b/.chloggen/sql-server-context-info-propagation.yaml @@ -0,0 +1,22 @@ +# Use this changelog template to create an entry for release notes. +# +# If your change doesn't affect end users you should instead start +# your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db) +component: db + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add dashbase context propagation via `SET CONTEXT_INFO` for SQL Server + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +# The values here must be integers. +issues: [2162] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index c10011b0b5..d0edb18792 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -9,6 +9,8 @@ linkTitle: SQL Server - [Spans](#spans) +- [Database Context Propagation](#database-context-propagation) + - [SET CONTEXT_INFO](#set-context_info) - [Metrics](#metrics) @@ -152,6 +154,37 @@ and SHOULD be provided **at span creation time** (if provided at all): +## Database Context Propagation + +**Status**: [Development][DocumentStatus] + +### SET CONTEXT_INFO + +Instrumentations MAY make use of [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) to add text format of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that should be explicitly enabled by the user. + +`SET CONTEXT_INFO` must be executed on the same physical connection as the SQL statement (or reuse its transaction). + +Note that `SET CONTEXT_INFO` requires binary input according to its syntax: `SET CONTEXT_INFO { binary_str | @binary_var }` and has a maximum size of 128 bytes. + +Example: + +For a query `SELECT * FROM songs` where `traceparent` is `00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01`: + +Run the following command on the same physical connection as the SQL statement: + +```sql +-- The binary conversion may be done by the application or the driver. +DECLARE @BinVar varbinary(55); +SET @BinVar = CAST('00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' AS varbinary(55)); +SET CONTEXT_INFO @BinVar; +``` + +Then run the query: + +```sql +SELECT * FROM songs; +``` + ## Metrics Microsoft SQL Server client instrumentations SHOULD collect metrics according to the general From fa7f40fce9635423b2709b94c35730ec1aa7b641 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Mon, 16 Jun 2025 09:15:56 -0700 Subject: [PATCH 2/8] Update .chloggen/sql-server-context-info-propagation.yaml Co-authored-by: Armin Ruech <7052238+arminru@users.noreply.github.com> --- .chloggen/sql-server-context-info-propagation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/sql-server-context-info-propagation.yaml b/.chloggen/sql-server-context-info-propagation.yaml index 8f050f0648..9d2a7e8e1c 100644 --- a/.chloggen/sql-server-context-info-propagation.yaml +++ b/.chloggen/sql-server-context-info-propagation.yaml @@ -10,7 +10,7 @@ change_type: enhancement component: db # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Add dashbase context propagation via `SET CONTEXT_INFO` for SQL Server +note: Add database context propagation via `SET CONTEXT_INFO` for SQL Server # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. # The values here must be integers. From df6fff6fd07b9820fe4d06b5d45ca736d4f9aa81 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Tue, 24 Jun 2025 14:51:01 -0700 Subject: [PATCH 3/8] Capitalize normative words --- docs/database/sql-server.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index d0edb18792..326e088a8d 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -160,9 +160,9 @@ and SHOULD be provided **at span creation time** (if provided at all): ### SET CONTEXT_INFO -Instrumentations MAY make use of [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) to add text format of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that should be explicitly enabled by the user. +Instrumentations MAY make use of [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) to add text format of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that SHOULD be explicitly enabled by the user. -`SET CONTEXT_INFO` must be executed on the same physical connection as the SQL statement (or reuse its transaction). +`SET CONTEXT_INFO` MUST be executed on the same physical connection as the SQL statement (or reuse its transaction). Note that `SET CONTEXT_INFO` requires binary input according to its syntax: `SET CONTEXT_INFO { binary_str | @binary_var }` and has a maximum size of 128 bytes. From 1d6fad65ea6c378c23df1eaa482701010838cc58 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Tue, 24 Jun 2025 14:57:53 -0700 Subject: [PATCH 4/8] Rename naming of context variable to traceparent --- docs/database/sql-server.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index 326e088a8d..b97df04f58 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -174,9 +174,9 @@ Run the following command on the same physical connection as the SQL statement: ```sql -- The binary conversion may be done by the application or the driver. -DECLARE @BinVar varbinary(55); -SET @BinVar = CAST('00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' AS varbinary(55)); -SET CONTEXT_INFO @BinVar; +DECLARE @traceparent varbinary(55); +SET @traceparent = CAST('00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' AS varbinary(55)); +SET CONTEXT_INFO @traceparent; ``` Then run the query: From df042fedabcfe031d279ca6bf761c8df6382e2a5 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Wed, 25 Jun 2025 23:54:55 -0700 Subject: [PATCH 5/8] Update docs/database/sql-server.md Co-authored-by: Liudmila Molkova --- docs/database/sql-server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index b97df04f58..42f21d5044 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -154,7 +154,7 @@ and SHOULD be provided **at span creation time** (if provided at all): -## Database Context Propagation +## Context propagation **Status**: [Development][DocumentStatus] From 15fcd8e962a549f5c38fd171ec3c6accb5936a28 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Wed, 25 Jun 2025 23:55:34 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Liudmila Molkova --- docs/database/sql-server.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index 42f21d5044..c615b42f9b 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -160,9 +160,9 @@ and SHOULD be provided **at span creation time** (if provided at all): ### SET CONTEXT_INFO -Instrumentations MAY make use of [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) to add text format of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that SHOULD be explicitly enabled by the user. +Instrumentations MAY propagate context using [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) by setting a string representation of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that SHOULD be explicitly enabled by the user. -`SET CONTEXT_INFO` MUST be executed on the same physical connection as the SQL statement (or reuse its transaction). +Instrumentations that propagate context MUST execute `SET CONTEXT_INFO` on the same physical connection as the SQL statement (or reuse its transaction). Note that `SET CONTEXT_INFO` requires binary input according to its syntax: `SET CONTEXT_INFO { binary_str | @binary_var }` and has a maximum size of 128 bytes. From e8aec4ec61309efb78a58ad75c72e27e6da58b1e Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Thu, 26 Jun 2025 09:53:19 -0700 Subject: [PATCH 7/8] Fix markdown lint --- docs/database/sql-server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index c615b42f9b..a05edd6481 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -9,7 +9,7 @@ linkTitle: SQL Server - [Spans](#spans) -- [Database Context Propagation](#database-context-propagation) +- [Context propagation](#context-propagation) - [SET CONTEXT_INFO](#set-context_info) - [Metrics](#metrics) From 80c873f6004e70b431a4a921ef0d662996d54395 Mon Sep 17 00:00:00 2001 From: Sam Xie Date: Sun, 29 Jun 2025 23:12:47 -0700 Subject: [PATCH 8/8] Update docs/database/sql-server.md Co-authored-by: Liudmila Molkova --- docs/database/sql-server.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/database/sql-server.md b/docs/database/sql-server.md index a05edd6481..f5a15c8ea1 100644 --- a/docs/database/sql-server.md +++ b/docs/database/sql-server.md @@ -160,7 +160,9 @@ and SHOULD be provided **at span creation time** (if provided at all): ### SET CONTEXT_INFO -Instrumentations MAY propagate context using [SET CONTEXT_INFO](https://learn.microsoft.com/en-us/sql/t-sql/statements/set-context-info-transact-sql?view=sql-server-ver16) by setting a string representation of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) before executing a query. This is an opt-in behavior that SHOULD be explicitly enabled by the user. +Instrumentations MAY propagate context using [SET CONTEXT_INFO](https://learn.microsoft.com/sql/t-sql/statements/set-context-info-transact-sql) by injecting fixed-length part of span context (trace-id, span-id, trace-flags, protocol version) before executing a query. For example, when using W3C Trace Context, only a string representation of [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header) SHOULD be injected. Context injection SHOULD NOT be enabled by default, but instrumentation MAY allow users to opt into it. + +Variable context parts (`tracestate`, `baggage`) SHOULD NOT be injected since `CONTEXT_INFO` value length is limited to 128 bytes. Instrumentations that propagate context MUST execute `SET CONTEXT_INFO` on the same physical connection as the SQL statement (or reuse its transaction).