Skip to content

Conversation

@neong83
Copy link
Contributor

@neong83 neong83 commented Jan 15, 2020

Note: Please remember to review the contribution guidelines
if you have not yet done so.

What does this PR do?

Lambda metric will tries to get DD_KEY_API value from 3 different places when lambda_metric imports and set its value into api._api_key in Datadog library. However, I received an empty string as result when I tries to import lambda_metric that describe in doc

https://github.com/DataDog/datadog-lambda-layer-python#environment-variables from datadog import api api._api_key = "MY_API_KEY" 

This PR is intend to check on _api_key before setting it.

Motivation

What inspired you to submit this pull request?

allow user to overwrite API Key at runtime without side effect

Testing Guidelines

How did you test this pull request?

  • _api_key will preserve when Datadog.lambda_metric imports if we had previously set it in Datadog.api._api_key

Additional Notes

Anything else we should know when reviewing?

N/A

@neong83 neong83 requested a review from a team as a code owner January 15, 2020 03:26
@tianchu
Copy link
Collaborator

tianchu commented Jan 16, 2020

@neong83 do you override api key after importing datadog_lambda?

from datadog_lambda.metric import lambda_metric # Override DD API Key after importing datadog_lambda packages from datadog import api api._api_key = "MY_API_KEY"
@neong83
Copy link
Contributor Author

neong83 commented Jan 16, 2020

@tianchu I did have to override the api key by the way you posted in your comment.

The reason being I was able to set api key directly into datadog.api._api_key inside django.settings and datadog_lambda_wrapper will use it throughout the entire code base. But I would have to reset the key whenever I import lambda_metric from datadog_lambda.metric. It is causing unexpected behavior for developer and have to remember resetting it when this pattern is used.

It does fix the problem if I set the api key as an environment variable, but this is causing some unnecssary overhead of reloading / resetting the key every time lambda metric gets import.

Hope this answers your questions and concerns

@tianchu tianchu merged commit 61fcc84 into DataDog:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants