Skip to content
4 changes: 2 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
matrix:
python-version: ["3.11"]
poetry-version: ["1.4"]
os: [ubuntu-20.04]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -30,7 +30,7 @@ jobs:
matrix:
python-version: ["3.11"]
poetry-version: ["1.4"]
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "2.9.5"
description = ""
authors = ["New Relic <serverless@newrelic.com>"]
license = "Apache 2.0"
package-mode= false

[tool.poetry.dependencies]
python = "^3.11"
Expand Down
15 changes: 15 additions & 0 deletions src/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

LAMBDA_LOG_GROUP_PREFIX = os.getenv("NR_LAMBDA_LOG_GROUP_PREFIX", "/aws/lambda")
VPC_LOG_GROUP_PREFIX = os.getenv("NR_VPC_LOG_GROUP_PREFIX", "/aws/vpc/flow-logs")
NEW_RELIC_FORMAT_LOGS = os.getenv("NEW_RELIC_FORMAT_LOGS", "false").lower() == "true"
Copy link

Choose a reason for hiding this comment

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

Why did we add this environment variable? Do we want to disable this by default?


LAMBDA_NR_MONITORING_PATTERN = re.compile(r'.*"NR_LAMBDA_MONITORING')
REPORT_PATTERN = re.compile("REPORT RequestId:")
Expand Down Expand Up @@ -174,6 +175,18 @@ def _format_error(e, text):
raise MaxRetriesException()


def format_agent_logs(event):
"""
Processes event payload for all formats.
"""
id, timestamp, message = event["id"], event["timestamp"], event["message"]
reconstructed_message = message.split("\t")
if len(reconstructed_message) == 4:
message = reconstructed_message[3]
event = {"id": id, "timestamp": timestamp, "message": message}
return event


def _filter_log_lines(log_entry):
"""
The EntryType.LAMBDA check guarantees that we'll be left with at least one log after filtering
Expand All @@ -182,6 +195,8 @@ def _filter_log_lines(log_entry):
for event in log_entry["logEvents"]:
message = event["message"]
if REPORT_PATTERN.match(message) or _is_lambda_message(message):
if NEW_RELIC_FORMAT_LOGS:
event = format_agent_logs(event)
final_log_events.append(event)

ret = log_entry.copy()
Expand Down
Loading