Skip to content

SQL Server: recover DBM<>APM correlation comment for non-procedure statements - #24899

Open
pierreln-dd wants to merge 5 commits into
masterfrom
pierreln-dd/SDBM-2891-sqlserver-leading-comment-fix
Open

SQL Server: recover DBM<>APM correlation comment for non-procedure statements#24899
pierreln-dd wants to merge 5 commits into
masterfrom
pierreln-dd/SDBM-2891-sqlserver-leading-comment-fix

Conversation

@pierreln-dd

@pierreln-dd pierreln-dd commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug in the SQL Server check's activity and query metrics collection where a DBM<>APM correlation comment (for example, a sqlcommenter-style /*dddbs=...*/ tag) prepended to a query is silently dropped for ordinary non-stored-procedure statements, breaking the "Calling Service" correlation panel.

SQL Server's statement_start_offset/statement_end_offset DMV mechanics exclude the RPC parameter declaration and any leading comment from statement_text. The untouched batch text (row['text']) retains both, but the integration only re-obfuscated that text for stored-procedure context. This PR also inspects differing full text for ordinary statements and merges its comments. Procedure signatures, content, and names remain gated behind the existing procedure context.

The Activity and Query Metrics unit tests reproduce the observed RPC shape, (@P1 int)/*dddbs=...*/ SELECT ..., and assert that the correlation comment is recovered without adding procedure metadata.

Motivation

Confirmed via direct reproduction with a real SQL Server engine, both a raw ad-hoc query and the actual dd-trace-go v2 SDK, that this affects DBM<>APM correlation for SQL Server universally, not just OpenTelemetry-instrumented clients as originally reported. See SDBM-2891.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

…tements

SQL Server's statement_start_offset/statement_end_offset exclude a leading
comment (e.g. a sqlcommenter-style /*dddbs=...*/ tag) from statement_text,
so DBM<>APM correlation comments were silently dropped for ordinary
statements. The only place the comment could still be recovered from is
row['text'] (the untouched batch text), but that re-obfuscation only ran
when the statement had stored-procedure context. Run it for every row
instead, keeping procedure_signature/procedure_name assignment gated
behind has_proc_context as before.

SDBM-2891
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 18, 2026

Copy link
Copy Markdown

evalya-impact-summary

evalya impact analysis
Impact analysis: 0 selected, 0 skipped (of 0 test tasks)
Publish tasks:   1 (always emitted)
Diff (5 files):
  sqlserver/changelog.d/24899.fixed
  sqlserver/datadog_checks/sqlserver/activity.py
  sqlserver/datadog_checks/sqlserver/statements.py
  sqlserver/tests/test_activity.py
  sqlserver/tests/test_statements.py

Debug a specific task: evalya plan impact --path <path> --task <task>

Learn more about CI impact filtering

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Aug 18, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 91.78%
Overall Coverage: 90.84% (+2.26%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 00d3676 | Docs | View more details | Give us feedback!

Drop explanatory comment block, simplify changelog entry.
Address review feedback on #24899:
- Only re-obfuscate row['text'] when it can add something (proc context,
  or text actually differs from statement_text), avoiding a doubled
  obfuscator RPC for every row where the two are already identical.
- Extract the repeated "pull comments out of obfuscated metadata and
  merge" shape (full-text branch + tail-text branch) into _merge_comments,
  using dict.fromkeys instead of set for stable dd_comments ordering.
@dd-octo-sts

dd-octo-sts Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants