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
22 changes: 22 additions & 0 deletions .chloggen/sql-server-context-info-propagation.yaml
Original file line number Diff line number Diff line change
@@ -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 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.
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:
35 changes: 35 additions & 0 deletions docs/database/sql-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ linkTitle: SQL Server
<!-- toc -->

- [Spans](#spans)
- [Context propagation](#context-propagation)
- [SET CONTEXT_INFO](#set-context_info)
- [Metrics](#metrics)

<!-- tocstop -->
Expand Down Expand Up @@ -152,6 +154,39 @@ and SHOULD be provided **at span creation time** (if provided at all):
<!-- END AUTOGENERATED TEXT -->
<!-- endsemconv -->

## Context propagation

**Status**: [Development][DocumentStatus]

### SET CONTEXT_INFO

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.

Comment thread
XSAM marked this conversation as resolved.
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).

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 @traceparent varbinary(55);
SET @traceparent = CAST('00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' AS varbinary(55));
SET CONTEXT_INFO @traceparent;
```

Then run the query:

```sql
SELECT * FROM songs;
```

## Metrics

Microsoft SQL Server client instrumentations SHOULD collect metrics according to the general
Expand Down
Loading