When enabling extended events, use filters, filter more aggressively in the beginning (e.g. filter on a duration above 100ms, then drop it down if you are happy there is no negative impact). Additionally deploy the Extended Event Traces to your non-production environments first.
For the best results, measure the impact with the queries below.
The query below gives an indication of how much data is written in GB to the ringbuffer/eventfile/router etc.
NOTE: bytes_written field is not available in SQL 2016 and lower versions.
--Extended Event File/Ring Buffer Operational Stats (SQL2017, 2019)
;WITH t
AS
(
SELECT
s.name
, st.execution_count
, st.target_name
, execution_duration_s = CAST(st.execution_duration_ms/1000.0 AS DECIMAL(18,1))
, GB_written = CAST(st.bytes_written/POWER(1024.0,3) AS DECIMAL(18,3))
, target_data = CAST(st.target_data AS XML)
FROM sys.dm_xe_session_targets st
JOIN sys.dm_xe_sessions s
ON s.address = st.event_session_address
)
SELECT
name
, target_name
, execution_count
, execution_duration_s
, GB_written
, [file_name] = COALESCE(
xed.target_data.value('(@name)[1]', 'NVARCHAR(512)'), target_name)
FROM t
OUTER APPLY t.target_data.nodes('//EventFileTarget/File') AS xed (target_data)
Use the below query for SQL 2016 and lower versions
--Extended Event File/Ring Buffer Operational Stats (SQL 2012 to 2016)
;WITH t
AS
(
SELECT
s.name
, st.execution_count
, st.target_name
, execution_duration_s = CAST(st.execution_duration_ms/1000.0 AS DECIMAL(18,1))
, target_data = CAST(st.target_data AS XML)
FROM sys.dm_xe_session_targets st
JOIN sys.dm_xe_sessions s
ON s.address = st.event_session_address
)
SELECT
name
, target_name
, execution_count
, execution_duration_s
, [file_name] = COALESCE(
xed.target_data.value('(@name)[1]', 'NVARCHAR(512)'), target_name)
FROM t
OUTER APPLY t.target_data.nodes('//EventFileTarget/File') AS xed (target_data)
This query is useful to see if events are being dropped, this is more to measure the Extended Event's effectiveness. More reading here.
--Extended Event Operational Statistics
SELECT
s.name
, s.total_regular_buffers
, s.regular_buffer_size
, s.total_large_buffers
, s.large_buffer_size
, s.dropped_event_count
, s.dropped_buffer_count
, s.largest_event_dropped_size
FROM sys.dm_xe_sessions s