Skip to content

Commit a7872e3

Browse files
author
Matt Whelan
authored
Merge pull request #29 from prodjito/master
Add NR_TAGS env var to allow users to specify tags in the format of k…
2 parents e4b6e7c + 0bf80f6 commit a7872e3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/function.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ def _get_license_key(license_key=None):
265265
return os.getenv("LICENSE_KEY", "")
266266

267267

268+
def _get_newrelic_tags(payload):
269+
"""
270+
This functions gets New Relic's tags from env vars and adds it to the payload
271+
A tag is a key value pair. Multiple tags can be specified.
272+
Key and value are colon delimited. Multiple key value pairs are semi-colon delimited.
273+
e.g. env:prod;team:myTeam
274+
"""
275+
nr_tags_str = os.getenv("NR_TAGS", "")
276+
if nr_tags_str:
277+
nr_tags = dict(
278+
item.split(":")
279+
for item in nr_tags_str.split(";")
280+
if not item.startswith(tuple(["aws:", "plugin:"]))
281+
)
282+
payload[0]["common"]["attributes"].update(nr_tags)
283+
284+
268285
def _debug_logging_enabled():
269286
"""
270287
Determines whether or not debug logging should be enabled based on the env var.
@@ -336,7 +353,7 @@ def _get_entry_type(log_entry):
336353

337354
def _get_infra_endpoint():
338355
"""
339-
Service url is determined by the lincese key's region.
356+
Service url is determined by the license key's region.
340357
Any other URL could be passed by using the NR_INFRA_ENDPOINT env var.
341358
"""
342359
if "NR_INFRA_ENDPOINT" in os.environ:
@@ -453,6 +470,8 @@ def _package_log_payload(data):
453470
}
454471
]
455472

473+
_get_newrelic_tags(packaged_payload)
474+
456475
return packaged_payload
457476

458477

0 commit comments

Comments
 (0)