You need to make sure to order the events by event_sequence when doing analytics on the XEvent data. It has been proposed to me that you can use the causality tracking sequence as a sort target, which may work as long as you understand how the activity ids are associated with the parent and the sequence is produced.
- Values are generated when the event sequence is submitted to the target
- Values are always incremented
- The event_sequence is unique to the session
- The activity id is unique to the task with xfer reference to the parent task
You can sort
- The session by event_sequence
- Individual task by attach_activity_id.seq
- Use the attach_activity_id_xfer.seq to locate the tasks associated with it. However, the child task ordering within a parent sequence requires event_sequence
The sequence value associated with causality tracking is incremented when the event is recorded. There are two forms of activity ids.
- attach_activity_id is a local id associated with the worker. This is incremented using ++ as each event is produced.
- attach_activity_id_xfer is an activity id of the parent, usually associated with the task when the task begins execution (SOS_Task::Param::Execute)
The event_sequence uses InterlockedIncrement making the value unique to the events produced for the session. The sequence value is tracked as part of the action object associated with the session meaning you get different sequence values for different sessions.
If you look at 2 sessions, tracking the same events, the event_sequence values are uniquely, incrementing for each session.
Bob Dorr – Principal Software Engineer SQL Server