Skip to content

Commit 4f7df1e

Browse files
Ingestion-time transformation in workspace/App Insights
1 parent 9c64c0a commit 4f7df1e

5 files changed

Lines changed: 57 additions & 22 deletions

File tree

application/CohortManager/src/Functions/Shared/Common/Extensions/TelemetryExtension.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ public static class TelemetryExtension
99
{
1010
public static IHostBuilder AddTelemetry(this IHostBuilder hostBuilder)
1111
{
12-
return hostBuilder.ConfigureServices(_ =>
12+
return hostBuilder.ConfigureServices(sc =>
1313
{
14-
_.AddApplicationInsightsTelemetryWorkerService();
15-
_.ConfigureFunctionsApplicationInsights();
16-
_.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
14+
sc.AddApplicationInsightsTelemetryWorkerService();
15+
sc.ConfigureFunctionsApplicationInsights();
16+
sc.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
1717
{
1818
module.SetComponentCorrelationHttpHeaders = true;
1919
});
20-
_.AddApplicationInsightsTelemetryProcessor<HealthCheckFilterTelemetryProcessor>();
20+
sc.AddApplicationInsightsTelemetryProcessor<HealthCheckFilterTelemetryProcessor>();
2121
});
2222
}
2323

application/CohortManager/src/Functions/Shared/Common/HealthCheckTelemetryFilter.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ namespace Common;
44
using Microsoft.ApplicationInsights.DataContracts;
55
using Microsoft.ApplicationInsights.Extensibility;
66

7-
public class HealthCheckFilterTelemetryProcessor : ITelemetryProcessor
7+
/// <summary>
8+
/// Filters health check telemetry emitted by the worker process.
9+
/// Note: In the isolated worker model, RequestTelemetry for HTTP triggers is emitted
10+
/// by the host process and does not flow through this processor.
11+
/// Host-emitted request telemetry cannot be filtered here — see
12+
/// https://github.com/Azure/azure-functions-dotnet-worker/issues/2024
13+
/// Trace telemetry is filtered via host.json logLevel settings.
14+
/// </summary>
15+
public class HealthCheckFilterTelemetryProcessor : ITelemetryProcessor, ITelemetryInitializer
816
{
917
private readonly ITelemetryProcessor _next;
1018

@@ -25,14 +33,11 @@ public void Process(ITelemetry item)
2533

2634
private static bool IsHealthCheckTelemetry(ITelemetry item)
2735
{
36+
//request telemetry is emitted by the host process and does not flow through this processor,
37+
//so we won't see those here to filter on. We can only filter on dependency and trace telemetry emitted by the worker process.
38+
//this is confirmed by microsoft support in this GitHub issue https://github.com/Azure/azure-functions-dotnet-worker/issues/2024
2839
if (item is RequestTelemetry request)
2940
{
30-
if (request.Properties.TryGetValue("FullName", out var fullName) &&
31-
fullName.Equals("Functions.health", StringComparison.OrdinalIgnoreCase))
32-
{
33-
return true;
34-
}
35-
3641
return request.Name?.Equals("health", StringComparison.OrdinalIgnoreCase) == true ||
3742
request.Url?.AbsolutePath.Contains("/health", StringComparison.OrdinalIgnoreCase) == true;
3843
}
@@ -74,4 +79,9 @@ private static bool IsException(ITelemetry item)
7479

7580
return item is ExceptionTelemetry;
7681
}
82+
83+
public void Initialize(ITelemetry telemetry)
84+
{
85+
throw new NotImplementedException();
86+
}
7787
}

infrastructure/tf-audit/environments/integration.tfvars

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ app_insights = {
4040
}
4141

4242
law = {
43-
law_sku = "PerGB2018"
44-
retention_days = 30
45-
export_enabled = false
46-
export_table_names = ["Alert"]
43+
law_sku = "PerGB2018"
44+
retention_days = 30
45+
export_enabled = false
46+
export_table_names = ["Alert"]
47+
app_requests_transform_enabled = true
4748
}
4849

4950
storage_accounts = {
@@ -71,7 +72,7 @@ storage_accounts = {
7172
access_tier = "Cold"
7273
containers = {
7374
sql-backups-immutable = {
74-
container_name = "sql-backups-immutable"
75+
container_name = "sql-back-ups-immutable"
7576
container_access_type = "private"
7677
immutability_policy = {
7778
is_locked = false
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "azurerm_monitor_data_collection_rule" "app_requests_workspace_transform" {
2+
count = var.law.app_requests_transform_enabled ? 1 : 0
3+
4+
name = "${module.regions_config[local.primary_region].names.log-analytics-workspace}-apprequests-transform"
5+
resource_group_name = azurerm_resource_group.audit[local.primary_region].name
6+
location = local.primary_region
7+
kind = "WorkspaceTransforms"
8+
9+
destinations {
10+
log_analytics {
11+
workspace_resource_id = module.log_analytics_workspace_audit[local.primary_region].id
12+
name = "workspace"
13+
}
14+
}
15+
16+
data_flow {
17+
streams = ["Microsoft-Table-AppRequests"]
18+
destinations = ["workspace"]
19+
transform_kql = var.law.app_requests_transform_kql
20+
output_stream = "Microsoft-Table-AppRequests"
21+
}
22+
}

infrastructure/tf-audit/variables.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ variable "app_insights" {
7979
variable "law" {
8080
description = "Configuration of the Log Analytics Workspace"
8181
type = object({
82-
name = optional(string, "cohman")
83-
law_sku = optional(string, "PerGB2018")
84-
retention_days = optional(number, 30)
85-
export_enabled = optional(bool, false)
86-
export_table_names = optional(list(string), [])
82+
name = optional(string, "cohman")
83+
law_sku = optional(string, "PerGB2018")
84+
retention_days = optional(number, 30)
85+
export_enabled = optional(bool, false)
86+
export_table_names = optional(list(string), [])
87+
app_requests_transform_enabled = optional(bool, false)
88+
app_requests_transform_kql = optional(string, "source | where not(tolower(Name) == \"health\" and tostring(Url) endswith \"/api/health\" and tostring(Properties[\"Category\"]) == \"Host.Results\")")
8789
})
8890
}
8991

0 commit comments

Comments
 (0)