Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python-ecosystem/inference-orchestrator/src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ def create_app() -> FastAPI:
def run_http_server(host: str = "0.0.0.0", port: int = 8000):
"""Run the FastAPI application."""
app = create_app()

# Wrap with New Relic ASGI instrumentation when the agent is active.
# initialize() sets up import hooks but cannot wrap the top-level ASGI
# protocol when the app is passed as a Python object to uvicorn.run().
try:
import newrelic.agent
nr_app = newrelic.agent.application()
# application() returns a non-None sentinel even when uninitialised,
# but the settings object is only populated after initialize().
if nr_app and nr_app.settings:
app = newrelic.agent.ASGIApplicationWrapper(app)
logger.info("New Relic ASGI wrapper applied")
except Exception:
pass # NR not installed or not initialized — run without it

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

Expand Down
17 changes: 14 additions & 3 deletions python-ecosystem/inference-orchestrator/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
# ── New Relic APM — must be initialized before any other imports ─────────
import os as _os
_nr_config = _os.environ.get('NEW_RELIC_CONFIG_FILE')
if _nr_config and _os.path.exists(_nr_config):
import newrelic.agent
newrelic.agent.initialize(_nr_config)
print(f"[NR-BOOT] NEW_RELIC_CONFIG_FILE = {_nr_config!r}", flush=True)
if _nr_config:
_nr_exists = _os.path.exists(_nr_config)
print(f"[NR-BOOT] Config file exists: {_nr_exists}", flush=True)
if _nr_exists:
try:
import newrelic.agent
print(f"[NR-BOOT] newrelic.agent imported, version={newrelic.version}", flush=True)
newrelic.agent.initialize(_nr_config)
print("[NR-BOOT] newrelic.agent.initialize() completed successfully", flush=True)
except Exception as _nr_err:
print(f"[NR-BOOT] ERROR during initialization: {_nr_err}", flush=True)
else:
print("[NR-BOOT] Skipping — no config file env var set", flush=True)
# ─────────────────────────────────────────────────────────────────────────

import os
Expand Down