You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add logic to connect to Azure Log Analytics (#2787)
## Why make this change?
Solves issue #2778
## What is this change?
This change adds logic to capture logs that DAB produces in order to
send them to the users' Azure Log Analytics tables. It does this by
creating a logger provider that is activated when the feature is enabled
and sends the logs that are produced to a custom log collector. This
custom log collector then flushes all of the saved logs periodically
every certain amount of time to Azure Log Analytics.
It is also important to note, that the name of one of the properties in
the feature was changed from `workspace-id` to `custom-table-name` as I
found that the feature did not need the `workspace-id` to connect to the
table, but it needed the name of custom log that is created as a
resource by the user.
Files Created:
- `AzureLogAnalyticsFlusherService` uploads the logs periodically to the
Azure Log Analytics Workspace Table.
- `AzureLogAnalyticsCustomLogCollector` it collects the logs from the
rest of the services and pushes them to
`AzureLogAnalyticsFlusherService`.
- `AzureLogAnalyticsLoggerProvider` creates the
`AzureLogAnalyticsLogger` to start the population of logs inside the
`AzureLogAnalyticsCustomLogCollector`.
- `AzureLogAnalyticsLog` is the base object that defines the structure
of the logs that will be sent to Azure Log Analytics.
## How was this tested?
- [ ] Integration Tests
- [X] Unit Tests
- [X] Manual Tests
For the manual testing, I had to create various resources inside of
Azure:
- Create Azure Log Analytics Workspace and creating a table inside of it
and decide on the `custom-table-name`.
- Create `DCE Endpoint` which is used the entry point for DAB to send
its logs
- Create DCR or Data Collection Rule and set rules on the structure of
the logs that it will receive, and set the workspace table and DCE
Endpoint to which it will connect.
- Create a VM that has a system assigned managed identity.
- Assign permission on DCR to allow VM to write telemetry data.
After creating all the necessary resources, you just need to run DAB
inside of the VM to have Azure Log Analytics logs sent.
You can follow the steps more in detail in the following link:
https://learn.microsoft.com/en-us/azure/azure-monitor/logs/tutorial-logs-ingestion-api?tabs=dce#create-data-collection-rule
## Sample Request(s)
<img width="1105" height="400" alt="image"
src="https://github.com/user-attachments/assets/6cd3a597-69e8-4777-8c6d-bc167b6fd424"
/>
[Option("azure-key-vault.retry-policy.network-timeout-seconds",Required=false,HelpText="Configure the network timeout for requests in seconds. Default: 60.")]
[Option("runtime.telemetry.azure-log-analytics.log-type",Required=false,HelpText="Configure Log Type for Azure Log Analytics to find table to send telemetry data")]
190
+
[Option("runtime.telemetry.azure-log-analytics.log-type",Required=false,HelpText="Configure Log Type for Azure Log Analytics to find table to send telemetry data. Default: DABLogs")]
191
191
publicstring?AzureLogAnalyticsLogType{get;}
192
192
193
-
[Option("runtime.telemetry.azure-log-analytics.flush-interval-seconds",Required=false,HelpText="Configure Flush Interval in seconds for Azure Log Analytics to specify the time interval to send the telemetry data")]
193
+
[Option("runtime.telemetry.azure-log-analytics.flush-interval-seconds",Required=false,HelpText="Configure Flush Interval in seconds for Azure Log Analytics to specify the time interval to send the telemetry data. Default: 5")]
[Option("runtime.telemetry.azure-log-analytics.auth.workspace-id",Required=false,HelpText="Configure Workspace ID for Azure Log Analytics used to find workspace to connect")]
197
-
publicstring?AzureLogAnalyticsWorkspaceId{get;}
196
+
[Option("runtime.telemetry.azure-log-analytics.auth.custom-table-name",Required=false,HelpText="Configure Custom Table Name for Azure Log Analytics used to find table to connect")]
[Option("runtime.telemetry.azure-log-analytics.auth.dcr-immutable-id",Required=false,HelpText="Configure DCR Immutable ID for Azure Log Analytics to find the data collection rule that defines how data is collected")]
_logger.LogInformation($"Updated configuration with runtime.telemetry.azure-log-analytics.flush-interval-seconds as '{options.AzureLogAnalyticsFlushIntervalSeconds}'");
_logger.LogInformation($"Updated configuration with runtime.telemetry.azure-log-analytics.auth.workspace-id as '{options.AzureLogAnalyticsWorkspaceId}'");
_logger.LogInformation($"Updated configuration with runtime.telemetry.azure-log-analytics.auth.custom-table-name as '{options.AzureLogAnalyticsCustomTableName}'");
0 commit comments