Package: lightrun
Lightrun for PythonLightrunis a developer-native observabity platform. It's a way to add logs, inspect the state of the current execution (in a familiar, debugger-like view), and extract any type of code-level metricon the fly- without redeploying, restarting or even stopping the running application.Check out ourdocsto learn more.Getting StartedTo get started with Lightrun you'll need three things:A Lightrun Account - you can get onehere.A Lightrun Plugin - you'll have instructions to download it once you create an account, but you can also check them outhere.A Lightrun Agent - which is this very PyPI package! It's the thing that actually does the magic.Once you've signed up for an account and downloaded the plugin, you can install the agent in your application.Installing the Lightrun Agent - DirectlyIn order to install the Lightrun Python Agent please follow these steps:Install the python agent by runningpython -m pip install lightrun.Add the following code tothe beginningof yourmainfunction:try:importlightrunlightrun.enable(company_key='<COMPANY_SECRET>')exceptImportErrorase:print("Error importing Lightrun: ",e)You will have a<COMPANY-SECRET>auto-generated for you during the onboarding process, right after signing up for an account.Run the application as you normally would, i.e.python app.py.You should see the application's agent popping up in the Lightrun Plugin's sidebar - you can now addlogs,snapshotsandmetricsto your application.Providing Credentials Via Program ArgumentsYou can optionally choose to provide the<COMPANY-SECRET>as program argument.
To do so, run your application in the following way:python-mlightrun--company_key='<COMAPNY-SECRET>'--app.pyNotice - The method above won't work well with applications based ongunicornor any other multiprocessing libraries, as the debugger won't attach to the spawned sub-processes. Please use the import method instead.Installing the Lightrun Agent - DjangoIn order to run a Django web server with the Lightrun agent please follow these steps:In the application folder, install the python agent by runningpython -m pip install lightrunAdd the following code to yourmanage.pyfile and run your Django application as you did normally before:try:ifos.environ.get('RUN_MAIN')or'--noreload'insys.argv:importlightrunlightrun.enable(company_key='<COMAPNY-SECRET>')exceptImportErrorase:print("Error importing Lightrun: ",e)Installing the Lightrun Agent - FlaskIn order to run a Flask web app with the Lightrun agent please follow these steps:In the application folder, install the python agent by runningpython -m pip install lightrunAdd the following code to your application's maininit.pyorapp.py(the import shouldn't be added to a specific routed method, but to the main file code instead):try:importlightrunlightrun.enable(company_key='<COMAPNY-SECRET>')exceptImportErrorase:print("Error importing Lightrun: ",e)# Example route@app.route("/")defhello_world():return'<p>Hello world!</p>'Installing the Lightrun Agent - Apache AirflowIn order to run Lightrun for Python with Apache Airflow you'll need to decide which step of the DAG you'd like to debug. Choose one (or more) steps and:Find a place in your system that has access to the same Python interpreter that is used by Airflow, and install the python agent by runningpython -m pip install lightrun.In an Airflow DAG file, add the following decorator above the operators you'd like to use Lightrun with:@lightrun_airflow_task()defoperator_name():# Operator codeDebugging Airflow Multi-step DAGs with Lightrun's Free TierPlease note that the Lightrun free tier limits usage to one agent per user.
In practice, note this means that eachoperatorcan be debugged individually, but you cannot debug multiple operators simultaneously.