Last active
October 28, 2020 21:36
-
-
Save a-recknagel/188330ad877b310f883e3d9bf4cd8379 to your computer and use it in GitHub Desktop.
fastapi + newrelic mcve with late license_key plugging bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import os | |
#os.environ["NEW_RELIC_LICENSE_KEY"] = "some_valid_key" | |
import sys | |
import logging | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
import newrelic.agent | |
newrelic.agent.initialize("newrelic.ini") | |
newrelic.agent.global_settings().license_key = "some_valid_key" | |
newrelic.agent.register_application() | |
import fastapi | |
app = fastapi.FastAPI() | |
@app.get("/") | |
async def health(): | |
return "hello world!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[newrelic] | |
app_name = HelloWorld | |
monitor_mode = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fastapi==0.60.2 | |
newrelic==5.22.0.151 | |
uvicorn==0.12.2 |
Found the solution: If using an EU based license key, you need to set the host together with the license:
newrelic.agent.initialize("newrelic.ini")
newrelic.agent.global_settings().license_key = "some_valid_key"
newrelic.agent.global_settings().host = newrelic.core.config.default_host("some_valid_key") # EU-only
newrelic.agent.register_application()
Cheers to a-feld for debugging it for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set up virtual env, activate it, install dependencies, and run server:
$ python -m venv venv $ source venv/bin/activate (venv)$ pip install -r requirements.txt (venv)$ uvicorn app:app
Should result in
Using os.environ to plug in the license on the other hand: