From 1e61c7e57146f87813845454670420c4a17e37a1 Mon Sep 17 00:00:00 2001 From: Anton Krytskyi Date: Thu, 11 Dec 2025 16:10:56 +0200 Subject: [PATCH] add newrelic support --- poetry.lock | 4 ++-- pyproject.toml | 1 + tasks.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8103da5d..e8ec7ac2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.2.1 and should not be changed by hand. [[package]] name = "agent" @@ -4707,4 +4707,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.1" python-versions = "^3.13" -content-hash = "2f421e10ba9bc1825b7642e284c05c86f91e8de8a1817ff2a5c85797b8971a14" +content-hash = "379ad0031711c6dc5279f3543bd7a58e15a43762a437b57ecb86e117ab52cb86" diff --git a/pyproject.toml b/pyproject.toml index 75a6d5ce..783b8d6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ celery = "5.5.0" black = "^25.1.0" isort = "^6.0.1" ruff = "^0.12.7" +newrelic = "10.8.1" [tool.poetry.group.dev] diff --git a/tasks.py b/tasks.py index f4f7c2af..ecba8eb1 100644 --- a/tasks.py +++ b/tasks.py @@ -1,4 +1,5 @@ import os +import sys from invoke import task @@ -70,3 +71,28 @@ def celery(ctx, loglevel='INFO', hostname='%h', concurrency=None): if concurrency: command.extend(['--concurrency', concurrency]) app.worker_main(command) + + +@task +def newrelic_init(ctx, key=None, verbose=False): + if key is None: + sys.exit('No newrelic api key given. Please generate one and rerun this command ' + 'with `invoke newrelic_init --key=$key`') + + cmd_tmpl = 'newrelic-admin generate-config {} newrelic.ini' + cmd = cmd_tmpl.format(key) + if verbose: + print(cmd_tmpl.format('')) + ctx.run(cmd, pty=True) + + +@task +def newrelic_server(ctx, config='newrelic.ini', verbose=False): + if not os.path.exists(config): + sys.exit("Couldn't find config file '{}'. Check path or run `invoke newrelic_init` " + "to generate it.".format(config)) + + cmd = f'poetry run env NEW_RELIC_CONFIG_FILE={config} newrelic-admin run-program invoke server' + if verbose: + print(cmd) + ctx.run(cmd, pty=True)