newrelic-python-agent icon indicating copy to clipboard operation
newrelic-python-agent copied to clipboard

NEW_RELIC_ENABLED env var does not disable serverless mode

Open rittneje opened this issue 1 year ago • 2 comments

Description

If we set NEW_RELIC_ENABLED=0 and NEW_RELIC_SERVERLESS_MODE_ENABLED=1, then the lambda function still emits the special NR_LAMBDA_MONITORING log at the end, which in turn triggers the log group subscription.

Expected Behavior

NEW_RELIC_ENABLED=0 should entirely disable the agent, regardless of NEW_RELIC_SERVERLESS_MODE_ENABLED.

Steps to Reproduce

Create a lambda function with the following env vars:

NEW_RELIC_ACCOUNT_ID=XXXXX
NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=1
NEW_RELIC_ENABLED=0
NEW_RELIC_SERVERLESS_MODE_ENABLED=1
NEW_RELIC_TRUSTED_ACCOUNT_KEY=XXXXX
import json

import newrelic.agent

newrelic.agent.initialize()

@newrelic.agent.lambda_handler()
def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Your Environment Python 3.12 with v9.9.0 of this library

Additional context

rittneje avatar May 31 '24 18:05 rittneje

https://new-relic.atlassian.net/browse/NR-276358

    warnings.warn((
        'The lambda_handler API has been deprecated. Please use the '
        'APIs provided in the newrelic-lambda package.'
    ), DeprecationWarning)

It sounds like you're using an API that's been marked deprecated for over 4 years, so that could be part of the issue. Have you tried this with our more current lambda offerings?

We typically direct people to use our Lambda Layer which can be installed easily with the Lambda CLI.

TimPansino avatar May 31 '24 19:05 TimPansino