Skip to content

Commit ef2fb53

Browse files
committed
Deprecate the NR_TAGS and NR_ENV_DELIMITER configuration options
The new `ADDITIONAL_ATTRIBUTES` provides a full replacement, so the logic now is to use what is configured in that variable, and only if that is unset fall back to parsing `NR_TAGS` and `NR_ENV_DELIMITER`. Note that `ADDITIONAL_ATTRIBUTES` is a JSON string, and doesn't contain the logic to not add `aws:`- and `plugin:`-prefixed properties: If those aren't wanted they shouldn't be provided.
1 parent 48b29d4 commit ef2fb53

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/handler.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ def _get_optional_env(key, default):
3838
"""
3939
return os.getenv(key, default) or default
4040

41+
42+
def _get_newrelic_tags(attributes=None):
43+
"""
44+
This functions gets New Relic's tags from env vars and adds it to the payload
45+
A tag is a key value pair. Multiple tags can be specified.
46+
Key and value are colon delimited. Multiple key value pairs are semi-colon delimited.
47+
e.g. env:prod;team:myTeam
48+
49+
Deprecated: Use the standard `ADDITIONAL_ATTRIBUTES` environment variable instead.
50+
"""
51+
if attributes:
52+
return attributes
53+
nr_tags_str = os.getenv("NR_TAGS", "")
54+
nr_delimiter = os.getenv("NR_ENV_DELIMITER", ";")
55+
if nr_tags_str:
56+
nr_tags = dict(
57+
item.split(":")
58+
for item in nr_tags_str.split(nr_delimiter)
59+
if not item.startswith(tuple(["aws:", "plugin:"]))
60+
)
61+
return nr_tags
62+
63+
4164
def _get_additional_attributes(attributes=None):
4265
"""
4366
This function gets Environment variable 'ADDITIONAL_ATTRIBUTES' and parses the same as a json object. Defaults
@@ -60,7 +83,7 @@ def _get_additional_attributes(attributes=None):
6083
"bytes or bytearray)"))
6184

6285

63-
additional_attributes = _get_additional_attributes()
86+
additional_attributes = _get_newrelic_tags(_get_additional_attributes())
6487
# Maximum number of retries
6588
MAX_RETRIES = 5
6689
# Initial backoff (in seconds) between retries
@@ -185,24 +208,6 @@ def _compress_payload(data):
185208
return payload
186209

187210

188-
def _get_newrelic_tags(payload):
189-
"""
190-
This functions gets New Relic's tags from env vars and adds it to the payload
191-
A tag is a key value pair. Multiple tags can be specified.
192-
Key and value are colon delimited. Multiple key value pairs are semi-colon delimited.
193-
e.g. env:prod;team:myTeam
194-
"""
195-
nr_tags_str = os.getenv("NR_TAGS", "")
196-
nr_delimiter = os.getenv("NR_ENV_DELIMITER", ";")
197-
if nr_tags_str:
198-
nr_tags = dict(
199-
item.split(":")
200-
for item in nr_tags_str.split(nr_delimiter)
201-
if not item.startswith(tuple(["aws:", "plugin:"]))
202-
)
203-
payload[0]["common"]["attributes"].update(nr_tags)
204-
205-
206211
def _package_log_payload(data):
207212
"""
208213
Packages up a MELT request for log messages
@@ -375,7 +380,7 @@ def lambda_handler(event, context):
375380
object_key = urllib.parse.unquote_plus(
376381
s3_event["object"]["key"], encoding="utf-8")
377382

378-
# Allow user to skip log file using regex pattern set in env variable: S3_IGNORE_PATTERN
383+
# Allow user to skip log file using regex pattern set in env variable: S3_IGNORE_PATTERN
379384
if _is_ignore_log_file(key):
380385
logger.debug(f"Ignore log file based on S3_IGNORE_PATTERN: {key}")
381386
return {'statusCode': 200, 'message': 'ignored this log'}

0 commit comments

Comments
 (0)