Creating an Extended Events session in Azure SQL Managed Instance (MI) requires some specific configurations, especially when it comes to setting up the event file target. Azure SQL MI does not support the traditional file paths like C:\Errors.xel
and instead expects a URL to an Azure Blob Storage. Here’s how you can set it up correctly:
Steps to Create an Extended Events Session with Azure Blob Storage as the Target:
- Create a Storage Account and Container:
- Ensure you have a storage account and a container within that account where the Extended Events files will be stored.
- Generate a Shared Access Signature (SAS) Token:
- Generate a SAS token with appropriate permissions (Read, Write, List, Delete) for the container.
- Create a Credential in SQL Managed Instance:
- Create a credential in your Azure SQL MI to use the SAS token.
CREATE CREDENTIAL [https://yourstorageaccount.blob.core.windows.net/yourcontainer]
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = 'your_sas_token';
- Create the Extended Events Session:
- Use T-SQL to create the Extended Events session with the correct URL format for the file target.
Example T-SQL Script:
-- Create the Extended Events session
CREATE EVENT SESSION [ErrorReportingSession] ON SERVER
ADD EVENT sqlserver.error_reported(
ACTION(sqlserver.sql_text, sqlserver.database_id, sqlserver.nt_username)
WHERE ([severity] >= 16))
ADD TARGET package0.event_file(
SET filename = 'https://yourstorageaccount.blob.core.windows.net/yourcontainer/Errors.xel',
max_file_size = 5, max_rollover_files = 2)
WITH (MAX_MEMORY = 4096 KB, EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY = 30 SECONDS, MAX_EVENT_SIZE = 0 KB, MEMORY_PARTITION_MODE = NONE, TRACK_CAUSALITY = ON, STARTUP_STATE = OFF);
-- Start the session
ALTER EVENT SESSION [ErrorReportingSession] ON SERVER STATE = START;
Explanation:
- Filename: The filename must be a valid URL starting with
https://
. This URL points to your Azure Blob Storage container where the event files will be stored. - SAS Token: The credential created with the SAS token allows the SQL Managed Instance to write to the specified blob storage.
Troubleshooting Common Issues:
- Invalid Characters in File Name:
- Ensure that the filename does not contain invalid characters. It should be a valid URL.
- Configuration Error During Initialization:
- Ensure the storage account and SQL MI are in the same region.
- Verify that the SAS token has the correct permissions.
- Ensure the credential is correctly created and matches the URL used in the Extended Events session.
- Credential Configuration:
- Double-check the credential's identity and secret. The identity should be
SHARED ACCESS SIGNATURE
, and the secret should be the SAS token itself.
- Double-check the credential's identity and secret. The identity should be
Example to Verify Configuration:
-- Verify Credential
SELECT * FROM sys.credentials
WHERE name = 'https://yourstorageaccount.blob.core.windows.net/yourcontainer';
-- Check Extended Events sessions
SELECT * FROM sys.server_event_sessions;
SELECT * FROM sys.dm_xe_sessions;
If you follow these steps and ensure the configuration is correct, you should be able to successfully create and start an Extended Events session in Azure SQL Managed Instance using Azure Blob Storage as the target. If you encounter any specific errors, examining the error messages and cross-referencing with the setup steps can help identify and resolve issues.