@@ -71,8 +71,6 @@ public void SqlClient_NamedOptions()
7171 public void SqlClientCallsAreCollectedSuccessfully (
7272 string beforeCommand ,
7373 CommandType commandType ,
74- string commandText ,
75- bool captureTextCommandContent ,
7674 bool emitOldAttributes = true ,
7775 bool emitNewAttributes = false )
7876 {
@@ -82,7 +80,7 @@ public void SqlClientCallsAreCollectedSuccessfully(
8280 using var traceProvider = Sdk . CreateTracerProviderBuilder ( )
8381 . AddSqlClientInstrumentation ( options =>
8482 {
85- options . SetDbStatementForText = captureTextCommandContent ;
83+ options . SetDbStatementForText = true ;
8684 options . EmitOldAttributes = emitOldAttributes ;
8785 options . EmitNewAttributes = emitNewAttributes ;
8886 } )
@@ -94,6 +92,10 @@ public void SqlClientCallsAreCollectedSuccessfully(
9492 . AddInMemoryExporter ( metrics )
9593 . Build ( ) ;
9694
95+ var commandText = commandType == CommandType . Text
96+ ? "select * from sys.databases"
97+ : "SP_GetOrders" ;
98+
9799 this . ExecuteCommand ( commandType , commandText , false , beforeCommand ) ;
98100
99101 traceProvider . ForceFlush ( ) ;
@@ -105,7 +107,7 @@ public void SqlClientCallsAreCollectedSuccessfully(
105107 VerifyActivityData (
106108 commandType ,
107109 commandText ,
108- captureTextCommandContent ,
110+ true ,
109111 false ,
110112 false ,
111113 false ,
@@ -230,6 +232,46 @@ public void MicrosoftDataStartsActivityWithExpectedAttributes(SqlClientTestCase
230232 this . RunSqlClientTestCase ( testCase , SqlClientDiagnosticListener . SqlMicrosoftBeforeExecuteCommand , SqlClientDiagnosticListener . SqlMicrosoftAfterExecuteCommand ) ;
231233 }
232234
235+ [ Theory ]
236+ [ InlineData ( true ) ]
237+ [ InlineData ( false ) ]
238+ public void DbQueryTextCollectedWhenEnabled ( bool captureTextCommandContent )
239+ {
240+ var activities = new List < Activity > ( ) ;
241+
242+ using var tracerProvider = Sdk . CreateTracerProviderBuilder ( )
243+ . AddSqlClientInstrumentation ( options =>
244+ {
245+ options . SetDbStatementForText = captureTextCommandContent ;
246+ options . EmitOldAttributes = true ;
247+ options . EmitNewAttributes = true ;
248+ } )
249+ . AddInMemoryExporter ( activities )
250+ . Build ( ) ;
251+
252+ var commandText = "select * from sys.databases" ;
253+ this . ExecuteCommand ( CommandType . Text , commandText , false , SqlClientDiagnosticListener . SqlDataBeforeExecuteCommand ) ;
254+ this . ExecuteCommand ( CommandType . Text , commandText , false , SqlClientDiagnosticListener . SqlMicrosoftBeforeExecuteCommand ) ;
255+
256+ tracerProvider . ForceFlush ( ) ;
257+ Assert . Equal ( 2 , activities . Count ) ;
258+
259+ if ( captureTextCommandContent )
260+ {
261+ Assert . Equal ( commandText , activities [ 0 ] . GetTagValue ( SemanticConventions . AttributeDbStatement ) ) ;
262+ Assert . Equal ( commandText , activities [ 0 ] . GetTagValue ( SemanticConventions . AttributeDbQueryText ) ) ;
263+ Assert . Equal ( commandText , activities [ 1 ] . GetTagValue ( SemanticConventions . AttributeDbStatement ) ) ;
264+ Assert . Equal ( commandText , activities [ 1 ] . GetTagValue ( SemanticConventions . AttributeDbQueryText ) ) ;
265+ }
266+ else
267+ {
268+ Assert . Null ( activities [ 0 ] . GetTagValue ( SemanticConventions . AttributeDbStatement ) ) ;
269+ Assert . Null ( activities [ 0 ] . GetTagValue ( SemanticConventions . AttributeDbQueryText ) ) ;
270+ Assert . Null ( activities [ 1 ] . GetTagValue ( SemanticConventions . AttributeDbStatement ) ) ;
271+ Assert . Null ( activities [ 1 ] . GetTagValue ( SemanticConventions . AttributeDbQueryText ) ) ;
272+ }
273+ }
274+
233275 [ Theory ]
234276 [ InlineData ( true , false ) ]
235277 [ InlineData ( false , false ) ]
0 commit comments