@@ -71,8 +71,6 @@ public void SqlClient_NamedOptions()
71
71
public void SqlClientCallsAreCollectedSuccessfully (
72
72
string beforeCommand ,
73
73
CommandType commandType ,
74
- string commandText ,
75
- bool captureTextCommandContent ,
76
74
bool emitOldAttributes = true ,
77
75
bool emitNewAttributes = false )
78
76
{
@@ -82,7 +80,7 @@ public void SqlClientCallsAreCollectedSuccessfully(
82
80
using var traceProvider = Sdk . CreateTracerProviderBuilder ( )
83
81
. AddSqlClientInstrumentation ( options =>
84
82
{
85
- options . SetDbStatementForText = captureTextCommandContent ;
83
+ options . SetDbStatementForText = true ;
86
84
options . EmitOldAttributes = emitOldAttributes ;
87
85
options . EmitNewAttributes = emitNewAttributes ;
88
86
} )
@@ -94,6 +92,10 @@ public void SqlClientCallsAreCollectedSuccessfully(
94
92
. AddInMemoryExporter ( metrics )
95
93
. Build ( ) ;
96
94
95
+ var commandText = commandType == CommandType . Text
96
+ ? "select * from sys.databases"
97
+ : "SP_GetOrders" ;
98
+
97
99
this . ExecuteCommand ( commandType , commandText , false , beforeCommand ) ;
98
100
99
101
traceProvider . ForceFlush ( ) ;
@@ -105,7 +107,7 @@ public void SqlClientCallsAreCollectedSuccessfully(
105
107
VerifyActivityData (
106
108
commandType ,
107
109
commandText ,
108
- captureTextCommandContent ,
110
+ true ,
109
111
false ,
110
112
false ,
111
113
false ,
@@ -230,6 +232,46 @@ public void MicrosoftDataStartsActivityWithExpectedAttributes(SqlClientTestCase
230
232
this . RunSqlClientTestCase ( testCase , SqlClientDiagnosticListener . SqlMicrosoftBeforeExecuteCommand , SqlClientDiagnosticListener . SqlMicrosoftAfterExecuteCommand ) ;
231
233
}
232
234
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
+
233
275
[ Theory ]
234
276
[ InlineData ( true , false ) ]
235
277
[ InlineData ( false , false ) ]
0 commit comments