/// <summary> /// Trace before executing Sql command /// </summary> private void OnEventStart(EventWrittenEventArgs sqlEventData) { if (sqlEventData.Payload.Count != 4) { return; } // Skip EF request if (SqlRequestUtil.IsTraceable()) { SqlRequestUtil.ProcessEventData(sqlEventData); try { var currentSubsegment = _recorder.GetEntity() as Subsegment; int id = Convert.ToInt32(sqlEventData.Payload[0], CultureInfo.InvariantCulture); if (currentSubsegment != null) { CurrentSqlEvents.TryAdd(id, currentSubsegment); } } catch (EntityNotAvailableException e) { AWSXRayRecorder.Instance.TraceContext.HandleEntityMissing(AWSXRayRecorder.Instance, e, "Subsegment is not available in trace context."); } } }
private void OnEventStart(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) { // Skip processing EntityFramework Core request if (SqlRequestUtil.IsTraceable() && CurrentDbCommands.TryAdd(dbcommand, null)) { SqlRequestUtil.BeginSubsegment(dbcommand); SqlRequestUtil.ProcessCommand(dbcommand); } } }