Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Last active October 28, 2020 21:36
Show Gist options
  • Save a-recknagel/188330ad877b310f883e3d9bf4cd8379 to your computer and use it in GitHub Desktop.
Save a-recknagel/188330ad877b310f883e3d9bf4cd8379 to your computer and use it in GitHub Desktop.
fastapi + newrelic mcve with late license_key plugging bug
#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!"
[newrelic]
app_name = HelloWorld
monitor_mode = true
fastapi==0.60.2
newrelic==5.22.0.151
uvicorn==0.12.2
@a-recknagel
Copy link
Author

a-recknagel commented Oct 28, 2020

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