private void OnCommandStop(Exception exception) { if (exception != null) { SqlRequestUtil.ProcessException(exception); } SqlRequestUtil.EndSubsegment(); }
private void OnEventStop(object value) { var command = ((CommandExecutedEventData)value).Command; if (command is DbCommand dbCommand) { SqlRequestUtil.EndSubsegment(); } }
private void OnEventException(object value) { var exc = ((CommandErrorEventData)value).Exception; if (exc is Exception exception) { SqlRequestUtil.ProcessException(exception); SqlRequestUtil.EndSubsegment(); } }
private void OnEventStop(object value) { // This class serves for tracing Sql command from both System.Data.SqlClient and Microsoft.Data.SqlClient and using fetch property works // fot both of these two cases var command = AgentUtil.FetchPropertyUsingReflection(value, "Command"); if (command is DbCommand dbcommand) { if (CurrentDbCommands.TryRemove(dbcommand, out _)) { SqlRequestUtil.EndSubsegment(); } } }
/// <summary> /// Trace after executing Sql command /// </summary> private void OnEventStop(EventWrittenEventArgs sqlEventData) { if (sqlEventData.Payload.Count != 3) { return; } int id = Convert.ToInt32(sqlEventData.Payload[0], CultureInfo.InvariantCulture); int state = Convert.ToInt32(sqlEventData.Payload[1], CultureInfo.InvariantCulture); int exceptionNumber = Convert.ToInt32(sqlEventData.Payload[2], CultureInfo.InvariantCulture); if (CurrentSqlEvents.TryRemove(id, out var currentSubsegment)) { if ((state & 2) == 2) { currentSubsegment.HasFault = true; } SqlRequestUtil.EndSubsegment(currentSubsegment); } }