Skip to content

Use query XML for windows events logs - #2201

Merged
jefchien merged 2 commits into
mainfrom
add-windows-events-query-xml
Jul 15, 2026
Merged

Use query XML for windows events logs#2201
jefchien merged 2 commits into
mainfrom
add-windows-events-query-xml

Conversation

@jefchien

Copy link
Copy Markdown
Contributor

Description of the issue

Follow up to #2193. The original PR used OTTL based filtering for event IDs and levels, which didn't work if the format of the event log was XML.

Description of changes

Dependent on the cherry-pick in amazon-contributing/opentelemetry-collector-contrib#598 that adds query XML support to the receiver. This leverages that functionality to be more in-line with the logs/logs_collected/windows_events.

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

Built and tested on Windows instance using eventcreate to generate events. The filtering works and now works when sending the logs in XML.

{
    "resource": {
        "attributes": {
            "cloud.resource_id": "arn:aws:ec2:us-east-1:<accountID>:instance/<instanceID>",
            "service.name": "unknown_service",
            "deployment.environment.name": "aws_ec2:default",
            "cloud.provider": "aws",
            "cloud.platform": "aws_ec2",
            "cloud.region": "us-east-1",
            "cloud.account.id": "<accountID>",
            "cloud.availability_zone": "us-east-1b",
            "host.id": "<instanceID>",
            "host.image.id": "ami-0e3c2921641a4a215",
            "host.type": "t3.large",
            "host.name": "<hostname>"
        },
        "schemaUrl": "https://opentelemetry.io/schemas/1.6.1"
    },
    "scope": {
        "attributes": {
            "cloudwatch.source": "cloudwatch-agent",
            "cloudwatch.solution": "otel-windows-events"
        }
    },
    "timeUnixNano": 1784047348750830600,
    "observedTimeUnixNano": 1784047349298379600,
    "severityNumber": 17,
    "severityText": "ERROR",
    "body": "<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='CWAgentTest'/><EventID Qualifiers='0'>777</EventID><Version>0</Version><Level>2</Level><Task>0</Task><Opcode>0</Opcode><Keywords>0x80000000000000</Keywords><TimeCreated SystemTime='2026-07-14T16:42:28.7508306Z'/><EventRecordID>24923</EventRecordID><Correlation/><Execution ProcessID='4916' ThreadID='0'/><Channel>Application</Channel><Computer>EC2AMAZ-OO6QGF9</Computer><Security UserID='S-1-5-18'/></System><EventData><Data>XML test: ERROR id=777 should appear in error-only only (not warning-and-id-777)</Data></EventData><RenderingInfo Culture='en-US'><Message>XML test: ERROR id=777 should appear in error-only only (not warning-and-id-777)</Message><Level>Error</Level><Task>None</Task><Opcode>Info</Opcode><Keywords><Keyword>Classic</Keyword></Keywords></RenderingInfo></Event>",
    "traceId": "",
    "spanId": ""
}

Requirements

Before commiting your code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint

Integration Tests

To run integration tests against this PR, add the ready for testing label.

@jefchien
jefchien requested a review from a team as a code owner July 14, 2026 16:52
@jefchien
jefchien force-pushed the add-windows-events-query-xml branch from 7c7b0f9 to 222646a Compare July 14, 2026 16:54
@jefchien jefchien added the ready for testing Indicates this PR is ready for integration tests to run label Jul 14, 2026
}

func (e eventEntry) receiverHash() string {
return hash.HashName(fmt.Sprintf("%s\x00%s\x00%v\x00%v", e.channel, e.format, e.eventLevels, e.eventIDs))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might wanna sort the levels and then hash

sky333999
sky333999 previously approved these changes Jul 14, 2026
@jefchien
jefchien merged commit 141c230 into main Jul 15, 2026
405 of 407 checks passed
@jefchien
jefchien deleted the add-windows-events-query-xml branch July 15, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for testing Indicates this PR is ready for integration tests to run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants