Skip to content

Fix duplicate trace injection for SQL Server and Oracle DBM full propagation mode #9224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public static AgentScope onEnter(
span.setTag(DBM_TRACE_INJECTED, true);
}
}
// For SQL Server and Oracle, trace context is propagated via
// context_info and v$session.action respectively.
// we should not also inject it into SQL comments to avoid duplication
final boolean injectTraceInComment = injectTraceContext && !isSqlServer && !isOracle;
sql =
SQLCommenter.inject(
sql,
Expand All @@ -131,7 +135,7 @@ public static AgentScope onEnter(
dbInfo.getHost(),
dbInfo.getDb(),
traceParent,
injectTraceContext,
injectTraceInComment,
appendComment);
}
DECORATE.onStatement(span, copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class SQLCommenterTest extends AgentTestRunner {
"SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/"
"SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-01" | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-01'*/"
"SELECT * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/"
"SELECT * FROM DUAL" | "SqlCommenter" | "Test" | "my-service" | "oracle" | "h" | "n" | "TestVersion" | false | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM DUAL /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/"
"SELECT * FROM sys.tables" | "SqlCommenter" | "Test" | "my-service" | "sqlserver"| "h" | "n" | "TestVersion" | false | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | "SELECT * FROM sys.tables /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/"
"SELECT /* customer-comment */ * FROM foo" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT /* customer-comment */ * FROM foo /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/"
"SELECT * from FOO -- test query" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | false | true | null | "SELECT * from FOO -- test query /*ddps='SqlCommenter',dddbs='my-service',ddh='h',dddb='n',dde='Test',ddpv='TestVersion'*/"
"" | "SqlCommenter" | "Test" | "my-service" | "mysql" | "h" | "n" | "TestVersion" | true | true | "00-00000000000000007fffffffffffffff-000000024cb016ea-00" | ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SQLServerInjectionForkedTest extends AgentTestRunner {
static query = "SELECT 1"
static serviceInjection = "ddps='my_service_name',dddbs='sqlserver',ddh='localhost',dddb='testdb'"

def "SQL Server no trace injection with full"() {
def "SQL Server no trace injection with full propagation mode"() {
setup:
def connection = new TestConnection(false)
def metadata = new TestDatabaseMetaData()
Expand All @@ -31,6 +31,9 @@ class SQLServerInjectionForkedTest extends AgentTestRunner {
statement.executeQuery(query)

then:
// Should only have service metadata, not traceparent, because SQL Server uses CONTEXT_INFO
assert statement.sql == "/*${serviceInjection}*/ ${query}"
// Verify that the SQL does NOT contain traceparent
assert !statement.sql.contains("traceparent")
}
}
Loading