Skip to content

Conversation

@XSAM
Copy link
Owner

@XSAM XSAM commented Jul 7, 2025

This PR is a prototype to demonstrate SQL commenter with the text attributes propagator.

This is the instrumentation API to enable SQL commenter: https://github.com/XSAM/otelsql/pull/512/files#diff-086a37ef11c8fd9a2516991339db79c207741ac98dd89c8215d31a8bead2814fR94

This is an example of usage: https://github.com/XSAM/otelsql/pull/512/files#diff-65caf616dc77b09c44c1fc0eba33369464655b1318bdedb0051351b635ebf881R138-R141

Steps to run the example:

  • Go to example/sql-commenter folder
  • docker compose up -d This runs a sql server, otel collector, 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 (queries that are currently running)
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' /*service.name='otelsql-example',traceparent='00-13ca090ee3e5b732879841a494b4dd45-b5ad38f303f1f181-01'*/ SELECT * FROM sys.dm_exec_connections; WAITFOR DELAY '00:00:05' /*service.name='otelsql-example',traceparent='00-13ca090ee3e5b732879841a494b4dd45-b5ad38f303f1f181-01'*/

You could remove TraceContext propagator here, https://github.com/XSAM/otelsql/pull/512/files#diff-65caf616dc77b09c44c1fc0eba33369464655b1318bdedb0051351b635ebf881R140. Then, you will get a query like this

WAITFOR DELAY '00:00:05' /*service.name='otelsql-example'*/

@codecov
Copy link

codecov bot commented Jul 7, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.2%. Comparing base (925d512) to head (ab10fc6).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
attributes_propagator.go 0.0% 16 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #512     +/-   ##
=======================================
- Coverage   85.6%   84.2%   -1.4%     
=======================================
  Files         16      17      +1     
  Lines        925     945     +20     
=======================================
+ Hits         792     796      +4     
- Misses       107     123     +16     
  Partials      26      26             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@XSAM XSAM force-pushed the sql-commenter-poc branch from 4191345 to ab10fc6 Compare July 24, 2025 01:11
@XSAM XSAM changed the title [DO NOT MERGE] POC of sql commenter with service.name propagator [DO NOT MERGE] POC of sql commenter with text attributes propagator Jul 24, 2025
@XSAM XSAM closed this Sep 7, 2025
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.

2 participants