Skip to content

Commit 5165967

Browse files
authored
Merge pull request #165 from rostilos/1.5.5-rc
feat: Improve New Relic ASGI instrumentation handling with enhanced e…
2 parents 2492b73 + a7cb946 commit 5165967

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

  • python-ecosystem/inference-orchestrator/src/api

python-ecosystem/inference-orchestrator/src/api/app.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,16 @@ def run_http_server(host: str = "0.0.0.0", port: int = 8000):
8181
"""Run the FastAPI application."""
8282
app = create_app()
8383

84-
# Wrap with New Relic ASGI instrumentation when the agent is active.
85-
# initialize() sets up import hooks but cannot wrap the top-level ASGI
86-
# protocol when the app is passed as a Python object to uvicorn.run().
87-
try:
88-
import newrelic.agent
89-
nr_app = newrelic.agent.application()
90-
# application() returns a non-None sentinel even when uninitialised,
91-
# but the settings object is only populated after initialize().
92-
if nr_app and nr_app.settings:
84+
# Wrap with New Relic ASGI instrumentation.
85+
# initialize() in main.py registers the agent asynchronously — settings/active
86+
# aren't populated yet at this point, so we gate on the env var instead.
87+
if os.environ.get('NEW_RELIC_CONFIG_FILE'):
88+
try:
89+
import newrelic.agent
9390
app = newrelic.agent.ASGIApplicationWrapper(app)
9491
logger.info("New Relic ASGI wrapper applied")
95-
except Exception:
96-
pass # NR not installed or not initialized — run without it
92+
except Exception as e:
93+
logger.warning(f"New Relic ASGI wrapper failed: {e}")
9794

9895
import uvicorn
9996
uvicorn.run(app, host=host, port=port, log_level="info", timeout_keep_alive=300)

0 commit comments

Comments
 (0)