-
Couldn't load subscription status.
- Fork 395
refactor(aws)!: AWSX-1703 Change matching of regex. Previously done against JSON, now only log message #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Parent:
AWS Forwarder v5
ViBiOh
merged 2 commits into
aws-forwarder-v5-preparation
from
vibioh/AWSX-1703_regex_matcher
Sep 30, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Unless explicitly stated otherwise all files in this repository are licensed | ||
| # under the Apache License Version 2.0. | ||
| # This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| # Copyright 2021 Datadog, Inc. | ||
|
|
||
|
|
||
| import logging | ||
| import os | ||
| import re | ||
|
|
||
| from logs.exceptions import ScrubbingException | ||
| from logs.helpers import compileRegex | ||
|
|
||
| logger = logging.getLogger() | ||
| logger.setLevel(logging.getLevelName(os.environ.get("DD_LOG_LEVEL", "INFO").upper())) | ||
|
|
||
|
|
||
| class DatadogMatcher(object): | ||
| def __init__(self, include_pattern=None, exclude_pattern=None): | ||
| self._include_regex = None | ||
| self._exclude_regex = None | ||
|
|
||
| if include_pattern is not None: | ||
| logger.debug(f"Applying include pattern: {include_pattern}") | ||
| self._include_regex = compileRegex("INCLUDE_AT_MATCH", include_pattern) | ||
|
|
||
| if exclude_pattern is not None: | ||
| logger.debug(f"Applying exclude pattern: {exclude_pattern}") | ||
| self._exclude_regex = compileRegex("EXCLUDE_AT_MATCH", exclude_pattern) | ||
|
|
||
| def match(self, log): | ||
| try: | ||
| if self._exclude_regex is not None and re.search( | ||
| self._exclude_regex, str(log) | ||
| ): | ||
| logger.debug("Exclude pattern matched, excluding log event") | ||
| return False | ||
|
|
||
| if self._include_regex is not None and not re.search( | ||
| self._include_regex, str(log) | ||
| ): | ||
| logger.debug("Include pattern did not match, excluding log event") | ||
| return False | ||
|
|
||
| return True | ||
|
|
||
| except ScrubbingException: | ||
| raise Exception("could not filter the payload") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should properly catch the exception raised by the matcher here and maybe log a warn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous behavior was to catch the exception and raise a new one. I think it's better to crash in this case. Otherwise Lambda will "succeed" but with bad filtering which is hidding a problem.