Issue with Log Filtering in ContainerLogV2 using Data Collection Rule

Masdieu, Melvin 25 Reputation points
2025-02-26T10:26:16.56+00:00

Hello,

I am experiencing an issue with the following configuration of my Data Collection Rule (DCR):

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "dataCollectionRules_name": {
            "defaultValue": "dcr-integration",
            "type": "String"
        },
        "logAnalyticsWorkspaceId": {
            "defaultValue": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-log-workspace",
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Insights/dataCollectionRules",
            "apiVersion": "2023-03-11",
            "name": "[parameters('dataCollectionRules_name')]",
            "location": "francecentral",
            "kind": "WorkspaceTransforms",
            "properties": {
                "dataSources": {},
                "destinations": {
                    "logAnalytics": [
                        {
                            "workspaceResourceId": "[parameters('logAnalyticsWorkspaceId')]",
                            "name": "log-destination"
                        }
                    ]
                },
                "dataFlows": [
                    {
                        "streams": [
                            "Microsoft-Table-ContainerLogV2"
                        ],
                        "destinations": [
                            "log-destination"
                        ],
                        "transformKql": "source\n| where tostring(LogMessage) !contains \"Picked up _JAVA_OPTIONS\"\n| where tostring(LogMessage) !contains \"Spring Boot\"\n"
                    }
                ]
            }
        }
    ]
}

With this configuration, I expect logs containing "Spring Boot" or "_JAVA_OPTIONS" to be filtered out and not appear in the ContainerLogV2 table. However, these logs are still being ingested.

I also tried modifying my DCR to use the Microsoft-ContainerLogV2 table instead, but this did not change anything.

My issue is simple: logs from my AKS cluster are being sent to ContainerLogV2, and I want to filter out specific messages so they are no longer collected.

Could you help me understand why these filters are not working and how I can correctly apply them?

Thank you in advance for your support.

Best regards, Melvin

Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. Suresh Estharakula 310 Reputation points Microsoft External Staff
    2025-03-06T18:05:23.9133333+00:00

    Hi Masdieu, Melvin,

    Good catch! Glad the issue is resolved for you finally. I will have this answer promoted by reposting it. As an Original Poster will not be able to accept your own answer. This is in the attempt to help others looking for a solution for a similar issue.

    {
        "properties": {
            "immutableId": "dcr-02d318a9feed4f47b40c926a112fe692",
            "dataSources": {
                "extensions": [
                    {
                        "streams": [
                            "Microsoft-Perf",
                            "Microsoft-InsightsMetrics",
                            "Microsoft-ContainerLog",
                            "Microsoft-ContainerLogV2",
                            "Microsoft-KubeEvents",
                            "Microsoft-KubePodInventory",
                            "Microsoft-ContainerInventory",
                            "Microsoft-ContainerNodeInventory",
                            "Microsoft-KubeNodeInventory",
                            "Microsoft-KubeServices",
                            "Microsoft-KubePVInventory"
                        ],
                        "extensionName": "ContainerInsights",
                        "extensionSettings": {
                            "dataCollectionSettings": {
                                "enableContainerLogV2": true,
                                "interval": "5m",
                                "namespaceFilteringMode": "Exclude",
                                "namespaces": [
                                    "kube-system",
                                    "gatekeeper-system",
                                    "keda",
                                    "calico-system",
                                    "tigera-operator",
                                    "snowsat-bot",
                                    "cert-manager"
                                ]
                            }
                        },
                        "inputDataSources": [],
                        "name": "ContainerInsightsExtension"
                    }
                ]
            },
            "destinations": {
                "logAnalytics": [
                    {
                        "workspaceResourceId": "/subscriptions/subscription_id/resourceGroups/snowsat-rg-cluster-production/providers/Microsoft.OperationalInsights/workspaces/snowsat-log-production",
                        "workspaceId": "xxx",
                        "name": "2074f46d40fc414d872f44d15c1c86e3"
                    }
                ]
            },
            "dataFlows": [
                {
                    "streams": [
                        "Microsoft-ContainerLogV2"
                    ],
                    "destinations": [
                        "2074f46d40fc414d872f44d15c1c86e3"
                    ],
                    "transformKql": "source | where LogMessage !has \"Picked up _JAVA_OPTIONS\" and LogMessage !has \"Spring Boot\""
                },
                {
                    "streams": [
                        "Microsoft-Perf",
                        "Microsoft-InsightsMetrics",
                        "Microsoft-ContainerLog",
                        "Microsoft-KubeEvents",
                        "Microsoft-KubePodInventory",
                        "Microsoft-ContainerInventory",
                        "Microsoft-ContainerNodeInventory",
                        "Microsoft-KubeNodeInventory",
                        "Microsoft-KubeServices",
                        "Microsoft-KubePVInventory"
                    ],
                    "destinations": [
                        "2074f46d40fc414d872f44d15c1c86e3"
                    ]
                }
            ],
            "provisioningState": "Succeeded"
        },
        "location": "francecentral",
        "name": "MSCI-francecentral-k8s-production",
        "apiVersion": "2022-06-01"
    }
    
    
    

    Thanks again for sharing the solution here. Have a good day!

    User's image

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Sina Salam 18,876 Reputation points
    2025-02-26T11:38:57.9366667+00:00

    Hello Masdieu, Melvin,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that your Data Collection Rule (DCR) is not filtering out specific log messages from ContainerLogV2 as expected.

    Logs are not filtered because transformKql applies after ingestion and the correct approach is to apply filtering at the dataSources level.

    To resolve this, and to ensures logs containing Spring Boot or _JAVA_OPTIONS are never collected you can do the followings:

    • Verify the correct log stream name. If the logs originate from ContainerInsights, confirm that the stream in the DCR should be Microsoft-ContainerLogV2 instead of Microsoft-Table-ContainerLogV2. - https://learn.microsoft.com/en-us/azure/azure-monitor/containers/container-insights-log-query something like this:
        ContainerLogV2
        | summarize count() by SourceSystem
      
    • Test the filter in Log Analytics before modifying the DCR.
        ContainerLogV2
        | where tostring(LogMessage) !contains "Picked up _JAVA_OPTIONS"
        | where tostring(LogMessage) !contains "Spring Boot"
      
      If logs still appear, check if LogMessage is a string field. If not, cast it explicitly:
        | extend LogMessage = tostring(LogMessage)
      
      https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/)
    • Move filtering logic to dataSources in the DCR. Instead of using transformKql inside dataFlows, apply log filtering at the dataSources level using streamDeclarations. Update your DCR to:
        "dataSources": {
            "extensions": [
                {
                    "name": "container-logs",
                    "streams": ["Microsoft-ContainerLogV2"],
                    "extensionName": "ContainerInsights",
                    "extensionParameters": {
                        "filtering": {
                            "filter": "tostring(LogMessage) !contains \"Picked up _JAVA_OPTIONS\" and tostring(LogMessage) !contains \"Spring Boot\""
                        }
                    }
                }
            ]
        }
      
    • Redeploy and verify log ingestion. - https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/data-collection-rule-azure-cli

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.


  2. Sina Salam 18,876 Reputation points
    2025-03-06T23:48:21.63+00:00

    Hello Masdieu, Melvin,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Issue: Customer logs from my AKS cluster are being sent to ContainerLogV2, and I want to filter out specific messages, so they are no longer collected.

    Error Message: No specific error - Customer have the configurations has explained in the problem statement in the question above. Expected the logs containing "Spring Boot" or "_JAVA_OPTIONS" to be filtered out and not appear in the ContainerLogV2 table. However, these logs are still being ingested. Customer also tried modifying DCR to use the Microsoft-ContainerLogV2 table instead, but noting was changed.

    Solution: Customer found a workaround solution below because the extension recommended or anything else could not work:

    {
        "properties": {
            "immutableId": "dcr-02d318a9feed4f47b40c926a112fe692",
            "dataSources": {
                "extensions": [
                    {
                        "streams": [
                            "Microsoft-Perf",
                            "Microsoft-InsightsMetrics",
                            "Microsoft-ContainerLog",
                            "Microsoft-ContainerLogV2",
                            "Microsoft-KubeEvents",
                            "Microsoft-KubePodInventory",
                            "Microsoft-ContainerInventory",
                            "Microsoft-ContainerNodeInventory",
                            "Microsoft-KubeNodeInventory",
                            "Microsoft-KubeServices",
                            "Microsoft-KubePVInventory"
                        ],
                        "extensionName": "ContainerInsights",
                        "extensionSettings": {
                            "dataCollectionSettings": {
                                "enableContainerLogV2": true,
                                "interval": "5m",
                                "namespaceFilteringMode": "Exclude",
                                "namespaces": [
                                    "kube-system",
                                    "gatekeeper-system",
                                    "keda",
                                    "calico-system",
                                    "tigera-operator",
                                    "snowsat-bot",
                                    "cert-manager"
                                ]
                            }
                        },
                        "inputDataSources": [],
                        "name": "ContainerInsightsExtension"
                    }
                ]
            },
            "destinations": {
                "logAnalytics": [
                    {
                        "workspaceResourceId": "/subscriptions/subscription_id/resourceGroups/snowsat-rg-cluster-production/providers/Microsoft.OperationalInsights/workspaces/snowsat-log-production",
                        "workspaceId": "xxx",
                        "name": "2074f46d40fc414d872f44d15c1c86e3"
                    }
                ]
            },
            "dataFlows": [
                {
                    "streams": [
                        "Microsoft-ContainerLogV2"
                    ],
                    "destinations": [
                        "2074f46d40fc414d872f44d15c1c86e3"
                    ],
                    "transformKql": "source | where LogMessage !has \"Picked up _JAVA_OPTIONS\" and LogMessage !has \"Spring Boot\""
                },
                {
                    "streams": [
                        "Microsoft-Perf",
                        "Microsoft-InsightsMetrics",
                        "Microsoft-ContainerLog",
                        "Microsoft-KubeEvents",
                        "Microsoft-KubePodInventory",
                        "Microsoft-ContainerInventory",
                        "Microsoft-ContainerNodeInventory",
                        "Microsoft-KubeNodeInventory",
                        "Microsoft-KubeServices",
                        "Microsoft-KubePVInventory"
                    ],
                    "destinations": [
                        "2074f46d40fc414d872f44d15c1c86e3"
                    ]
                }
            ],
            "provisioningState": "Succeeded"
        },
        "location": "francecentral",
        "name": "MSCI-francecentral-k8s-production",
        "apiVersion": "2022-06-01"
    }
    

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.