Skip to content

[DO NOT MERGE] POC of propagation for sql server via SET CONTEXT_INFO#508

Closed
XSAM wants to merge 2 commits intomainfrom
sqlserver-context-info-poc
Closed

[DO NOT MERGE] POC of propagation for sql server via SET CONTEXT_INFO#508
XSAM wants to merge 2 commits intomainfrom
sqlserver-context-info-poc

Conversation

@XSAM
Copy link
Copy Markdown
Owner

@XSAM XSAM commented Jun 16, 2025

This PR a prototype to demonstrate how SET CONTEXT_INFO can be used in the real world.

https://github.com/XSAM/otelsql/pull/508/files#diff-4f427d2b022907c552328e63f137561f6de92396d7a6e8f6c2ea1bcf0db52654R291 is the change for otelsql to make this happen.

Steps to run the example:

  • Go to example/sqlserver folder
  • docker compose up -d This runs a sql server, otel collector, jaeger and sql client.
  • docker compose up client to run a query from sql client. Meanwhile,
  • run this query against sql server database to fetch query samples
SELECT Substring(o.text, ( r.statement_start_offset / 2 ) + 1,
                 ( ( CASE r.statement_end_offset
                         WHEN -1 THEN Datalength(o.text)
                         ELSE r.statement_end_offset
                         END -
                     r.statement_start_offset ) / 2 ) + 1)          AS statement_text,
       o.text                                         AS text,
       Isnull(r.context_info, CONVERT(VARBINARY, '')) AS context_info
FROM   sys.dm_exec_requests r
           INNER JOIN sys.dm_exec_sessions s
                      ON r.session_id = s.session_id
           INNER JOIN sys.dm_exec_connections c
                      ON s.session_id = c.session_id
           CROSS apply sys.dm_exec_sql_text(r.plan_handle) AS o

Example results:

statement_text text context_info
WAITFOR DELAY '00:00:05' SELECT * FROM sys.dm_exec_connections; WAITFOR DELAY '00:00:05' 00-13df7cc8a541ad6de8b0d347e7618625-b0e43abf9390a766-01

From Jaeger
CleanShot 2025-06-16 at 15 44 57

You will see the trace_id and trace_id from CONTEXT_INFO is linked to an existing span on Jaeger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant