@@ -171,53 +171,6 @@ public void SqlClientAddsConnectionLevelAttributes(
171171 Assert . Equal ( expectedPort , tags . FirstOrDefault ( x => x . Key == SemanticConventions . AttributeServerPort ) . Value ) ;
172172 }
173173
174- [ Theory ]
175- [ MemberData ( nameof ( SqlTestData . SqlClientErrorsAreCollectedSuccessfullyCases ) , MemberType = typeof ( SqlTestData ) ) ]
176- public void SqlClientErrorsAreCollectedSuccessfully (
177- string beforeCommand ,
178- bool recordException = false )
179- {
180- var activities = new List < Activity > ( ) ;
181- var metrics = new List < Metric > ( ) ;
182-
183- using var traceProvider = Sdk . CreateTracerProviderBuilder ( )
184- . AddSqlClientInstrumentation ( options =>
185- {
186- options . RecordException = recordException ;
187- } )
188- . AddInMemoryExporter ( activities )
189- . Build ( ) ;
190-
191- using var meterProvider = Sdk . CreateMeterProviderBuilder ( )
192- . AddSqlClientInstrumentation ( )
193- . AddInMemoryExporter ( metrics )
194- . Build ( ) ;
195-
196- this . ExecuteCommand ( CommandType . StoredProcedure , "SP_GetOrders" , true , beforeCommand ) ;
197-
198- traceProvider . ForceFlush ( ) ;
199- meterProvider . ForceFlush ( ) ;
200-
201- Activity ? activity = null ;
202-
203- activity = Assert . Single ( activities ) ;
204- VerifyActivityData (
205- CommandType . StoredProcedure ,
206- "SP_GetOrders" ,
207- false ,
208- true ,
209- recordException ,
210- false ,
211- activity ) ;
212-
213- var dbClientOperationDurationMetrics = metrics
214- . Where ( metric => metric . Name == "db.client.operation.duration" )
215- . ToArray ( ) ;
216-
217- var metric = Assert . Single ( dbClientOperationDurationMetrics ) ;
218- VerifyDurationMetricData ( metric , activity ) ;
219- }
220-
221174 [ Theory ]
222175 [ ClassData ( typeof ( SqlClientTestCase ) ) ]
223176 public void SqlDataStartsActivityWithExpectedAttributes ( SqlClientTestCase testCase )
@@ -272,6 +225,49 @@ public void DbQueryTextCollectedWhenEnabled(bool captureTextCommandContent)
272225 }
273226 }
274227
228+ [ Theory ]
229+ [ InlineData ( true ) ]
230+ [ InlineData ( false ) ]
231+ public void ExceptionCapturedWhenRecordExceptionEnabled ( bool recordException )
232+ {
233+ var activities = new List < Activity > ( ) ;
234+
235+ using var traceProvider = Sdk . CreateTracerProviderBuilder ( )
236+ . AddSqlClientInstrumentation ( options =>
237+ {
238+ options . RecordException = recordException ;
239+ } )
240+ . AddInMemoryExporter ( activities )
241+ . Build ( ) ;
242+
243+ this . ExecuteCommand ( CommandType . StoredProcedure , "SP_GetOrders" , true , SqlClientDiagnosticListener . SqlDataBeforeExecuteCommand ) ;
244+ this . ExecuteCommand ( CommandType . StoredProcedure , "SP_GetOrders" , true , SqlClientDiagnosticListener . SqlMicrosoftBeforeExecuteCommand ) ;
245+
246+ traceProvider . ForceFlush ( ) ;
247+
248+ Assert . Equal ( 2 , activities . Count ) ;
249+
250+ Assert . Equal ( ActivityStatusCode . Error , activities [ 0 ] . Status ) ;
251+ Assert . Equal ( ActivityStatusCode . Error , activities [ 1 ] . Status ) ;
252+ Assert . NotNull ( activities [ 0 ] . StatusDescription ) ;
253+ Assert . NotNull ( activities [ 1 ] . StatusDescription ) ;
254+
255+ if ( recordException )
256+ {
257+ var events0 = activities [ 0 ] . Events . ToList ( ) ;
258+ var events1 = activities [ 1 ] . Events . ToList ( ) ;
259+ Assert . Single ( events0 ) ;
260+ Assert . Single ( events1 ) ;
261+ Assert . Equal ( SemanticConventions . AttributeExceptionEventName , events0 [ 0 ] . Name ) ;
262+ Assert . Equal ( SemanticConventions . AttributeExceptionEventName , events1 [ 0 ] . Name ) ;
263+ }
264+ else
265+ {
266+ Assert . Empty ( activities [ 0 ] . Events ) ;
267+ Assert . Empty ( activities [ 1 ] . Events ) ;
268+ }
269+ }
270+
275271 [ Theory ]
276272 [ InlineData ( true , false ) ]
277273 [ InlineData ( false , false ) ]
0 commit comments