newrelic / newrelic-dotnet-agent

The New Relic .NET language agent.
Apache License 2.0
95 stars 57 forks source link

Environment variables are not applied when running in a container #2622

Closed storey247 closed 3 days ago

storey247 commented 1 month ago

Description

When running the APM Agent in a container along with our application, setting environment variables such as NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES do not get applied.

We are running our container image in AWS ECS and we set the task definition with the env variable NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES set to be "422" but the errors are still reported by the agent into the NR application.

Expected Behavior

When the environment variable is set in the container runtime then the APM agent should take those settings into account

Steps to Reproduce

Your Environment

Additional context

For Maintainers Only or Hero Triaging this bug Suggested Priority (P1,P2,P3,P4,P5): Suggested T-Shirt size (S, M, L, XL, Unknown):

workato-integration[bot] commented 1 month ago

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

nr-ahemsath commented 1 month ago

Thank you for submitting this issue. In order to troubleshoot this, we might require you to send us agent log files and/or other details about your app and its environment, as well as your New Relic account. Public Github might not be the best place for this due to privacy concerns. Do you have the ability to open a case with New Relic support? If so, please do that and mention this Github issue in the case.

nr-ahemsath commented 1 month ago

@storey247 I attempted to reproduce the issue you described, and I did not see any problems. In my testing, the agent behaved as expected. See https://github.com/newrelic/newrelic-dotnet-examples/tree/main/ignore-errors for the containerized test app I used and the testing procedure I followed.

Can you try testing using that example and let me know what happens?

storey247 commented 1 month ago

Hi @nr-ahemsath thanks and yes we can confirm that this approach does indeed work.

The problem is we are using a multi stage dockerfile where we install the agent and its env vars/setup into a base image and upload the image into our ECR. Essentially lines 15-29 in your example. We did this in an attempt to simplify the necessity to have all the boilerplate in all our dockerfiles.

If we then use that base image, copy in our .NET binary set the env var for ignore error code and expose port we see the ignore error code not being honoured correctly.

nr-ahemsath commented 1 month ago

@storey247 When your application is running, can you check in the APM UI to see whether the env var is being picked up by the agent? If you go to Environment->Agent Initialization and look at the value of error_collector.ignore_status_codes, whatever code(s) you are setting via the env var should show up in the UI:

Screenshot 2024-08-02 112108

storey247 commented 2 weeks ago

Apologies, i forgot to cycle back round to this, i need to spin up some infrastructure to validate the question asked @nr-ahemsath please bear with me

nr-ahemsath commented 2 weeks ago

No problem @storey247, thanks for checking in.

chynesNR commented 3 days ago

Hi @storey247 -- since there isn't anything for us to do at the moment, I'm going to close this ticket, but please feel free to reopen it or file a new one if you still have questions. Thanks!