Skip to content

Commit 31ce8e8

Browse files
add --apm flag to enable APM Lambda mode (#327)
* add --apm flag to enable APM Lambda mode
1 parent 1033534 commit 31ce8e8

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

newrelic_lambda_cli/cli/layers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def register(group):
8181
help="Permit upgrade of function layers to new version.",
8282
is_flag=True,
8383
)
84+
@click.option(
85+
"--apm",
86+
help="Enable APM Lambda mode",
87+
is_flag=True,
88+
)
8489
@click.option(
8590
"--enable-extension/--disable-extension",
8691
"-x",

newrelic_lambda_cli/layers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def _add_new_relic(input, config, nr_license_key):
118118
success(
119119
"Already installed on function '%s'. Pass --upgrade (or -u) to allow "
120120
"upgrade or reinstall to latest layer version."
121+
"Additionally pass --apm to enable APM Lambda mode."
121122
% config["Configuration"]["FunctionArn"]
122123
)
123124
return True
@@ -232,6 +233,13 @@ def _add_new_relic(input, config, nr_license_key):
232233
"CORECLR_PROFILER_PATH"
233234
] = "/opt/lib/newrelic-dotnet-agent/libNewRelicProfiler.so"
234235

236+
if input.apm:
237+
success(
238+
"Enabling APM Lambda mode for function '%s' "
239+
% config["Configuration"]["FunctionArn"]
240+
)
241+
update_kwargs["Environment"]["Variables"]["NEW_RELIC_APM_LAMBDA_MODE"] = "True"
242+
235243
return update_kwargs
236244

237245

newrelic_lambda_cli/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"excludes",
105105
"layer_arn",
106106
"upgrade",
107+
"apm",
107108
"enable_extension",
108109
"enable_extension_function_logs",
109110
"java_handler_method",

tests/test_layers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,34 @@ def test_add_new_relic(aws_credentials, mock_function_config):
235235
assert update_kwargs["Layers"][0] != get_arn_prefix("us-east-1")
236236

237237

238+
@mock_aws
239+
def test_add_new_relic_apm_lambda_mode(aws_credentials, mock_function_config):
240+
session = boto3.Session(region_name="us-east-1")
241+
242+
config = mock_function_config("python3.12")
243+
244+
assert config["Configuration"]["Handler"] == "original_handler"
245+
246+
update_kwargs = _add_new_relic(
247+
layer_install(
248+
session=session,
249+
aws_region="us-east-1",
250+
nr_account_id=12345,
251+
enable_extension=True,
252+
enable_extension_function_logs=True,
253+
apm=True,
254+
),
255+
config,
256+
nr_license_key=None,
257+
)
258+
259+
assert update_kwargs["FunctionName"] == config["Configuration"]["FunctionArn"]
260+
assert update_kwargs["Handler"] == "newrelic_lambda_wrapper.handler"
261+
assert (
262+
update_kwargs["Environment"]["Variables"]["NEW_RELIC_APM_LAMBDA_MODE"] == "True"
263+
)
264+
265+
238266
@mock_aws
239267
def test_add_new_relic_dotnet(aws_credentials, mock_function_config):
240268
session = boto3.Session(region_name="us-east-1")

0 commit comments

Comments
 (0)