newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
178 stars 102 forks source link

NEW_RELIC_ENABLED env var does not disable serverless mode #1156

Closed rittneje closed 2 months ago

rittneje commented 5 months ago

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

workato-integration[bot] commented 5 months ago

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

TimPansino commented 5 months ago
    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.