Skip to main content

Monitoring apps based on Falcon Web Framework with OpenTelemetry

· 6 min read
Ankit Anand
Ankit Nayan

Falcon is a minimalist Python web API framework for building robust applications and microservices. It also compliments many other Python frameworks by providing extra reliability, flexibility, and performance. Falcon based applications can be monitored using OpenTelemetry - an open-source standard to generate telemetry data.

Cover Image

What is OpenTelemetry Falcon?
OpenTelemetry Falcon instrumentation enables the generation of telemetry data from your applications based on the Falcon web framework. The telemetry data is then used to monitor the performance of the Falcon application. OpenTelemetry provides an open-source standard with a consistent collection mechanism and data format. OpenTelemetry gives you the freedom to choose monitoring backends.

OpenTelemetry is a set of tools, APIs, and SDKs used to instrument applications to create and manage telemetry data(Logs, metrics, and traces). It aims to make telemetry data(logs, metrics, and traces) a built-in feature of cloud-native software applications.

One of the biggest advantages of using OpenTelemetry is that it is vendor-agnostic. It can export data in multiple formats, which you can send to a backend of your choice.

In this article, we will use SigNoz as a backend. SigNoz is an open-source APM tool built natively for OpenTelemetry and can be used for both metrics and distributed tracing. We will visualize the data captured by OpenTelemetry using SigNoz.

Running Falcon based web application with OpenTelemetry​

Installing SigNoz​

First, you need to install SigNoz. We will use OpenTelemetry to instrument the sample Falcon application, and the data collected by OpenTelemetry will be sent to SigNoz for storage and visualization.

What is application instrumentation?
Instrumentation is the process of enabling your application to generate telemetry data (logs, metrics, and traces).

You can get started with SigNoz using just three commands at your terminal.

git clone -b main https://github.com/SigNoz/signoz.git
cd signoz/deploy/
./install.sh

The above instruction is for MacOS and linux distributions. For detailed instructions, you can visit our documentation.

Deployment Docs

If you have installed SigNoz on your local host, you can access the UI at: http://localhost:3301

The application list shown in the dashboard is from a sample app called HOT R.O.D that comes bundled with the SigNoz installation package.

SigNoz dashboard showing application list
SigNoz Dashboard

Instrumenting a sample Falcon application with OpenTelemetry​

Prerequisites for the sample app​

  1. Python 3.8 or newer
    Download the latest version of Python.

  2. Redis
    For Mac users

    brew install redis
    brew services start redis

    For Ubuntu users

    sudo apt install redis-server

    You can also read a detailed guide to installing Redis on Ubuntu.

Running sample Falcon based app with OpenTelemetry​

  1. Running sample Falcon based app
    We will be using the Falcon app at this Github repo.

    git clone https://github.com/SigNoz/python-falcon-template.git
    cd python-falcon-template
  2. Create a virtual python environment and activate it
    It’s a good practice to create virtual environments for running Python apps.

    virtualenv mypython
    source mypython/bin/activate

    You can read more about creating virtual environments in Python.

  3. Installing necessary OpenTelemetry and Python packages
    The base.txt file contains all the necessary OpenTelemetry and Python packages needed for instrumentation. In order to install those packages, run the following command:

    pip3 install -r requirements/base.txt

    Here’s a snapshot of packages in the base.txt file to run the Flacon application with OpenTelemetry.

    Python packages required for the application
  4. Install application-specific packages
    This step is required to install packages specific to the application. This command figures out which instrumentation packages the user might want to install and installs it for them:

    opentelemetry-bootstrap --action=install
  5. Configure environment variables to run app and send data to SigNoz
    Finally, you can run your Falcon app with OpenTelemetry and send data to SigNoz for monitoring. In the last step, you just need to configure a few environment variables for your OTLP exporters. Environment variables that need to be configured:

    • service.name - name of the service you’re monitoring, you can name it anything you want
    • OTEL_EXPORTER_OTLP_ENDPOINT - Here you have to specify the endpoint of the backend where OpenTelemetry will send the captured data to.

    After taking care of these environment variables, you only need to run your instrumented application. Accomplish all these by using the following command at your terminal.

    OTEL_RESOURCE_ATTRIBUTES=service.name=<service_name> OTEL_EXPORTER_OTLP_ENDPOINT="http://<IP of SigNoz>:4317" opentelemetry-instrument gunicorn src.app -b 0.0.0.0:8001

    Naming our service as falconApp and replacing Ip of SigNoz  with localhost, the final command becomes:

    OTEL_RESOURCE_ATTRIBUTES=service.name=flaconApp OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" opentelemetry-instrument gunicorn src.app -b 0.0.0.0:8001

    And congratulations! You have now instrumented your falcon application with OpenTelemetry.

  6. Checking the app and monitoring data with SigNoz
    Access an endpoint from the sample application here: http://localhost:8001/api/v1/test.

    You need to interact with the endpoint to generate some monitoring data. Refresh the endpoint about 10-20 times and check SigNoz dashboard.

    If you have installed SigNoz on your local machine, you can access the SigNoz dashboard at: http://localhost:3301

Falcon based application monitored on SigNoz dashboard
You will find the Falcon application in the list of applications monitored on SigNoz dashboard. The other applications are from a sample app that comes loaded with SigNoz.

Open-source tool to visualize telemetry data​

SigNoz makes it easy to visualize metrics and traces captured through OpenTelemetry instrumentation.

SigNoz comes with out of box RED metrics charts and visualization. RED metrics stands for:

  • Rate of requests
  • Error rate of requests
  • Duration taken by requests
SigNoz charts and metrics
Measure things like application latency, requests per sec, error percentage and see your top endpoints with SigNoz.

You can then choose a particular timestamp where latency is high to drill down to traces around that timestamp.

List of traces on SigNoz dashboard
View of traces at a particular timestamp

You can use flamegraphs to exactly identify the issue causing the latency.

Flamegraphs used to visualize spans of distributed tracing in SigNoz UI
View of traces at a particular timestamp

You can also build custom metrics dashboard for your infrastructure.

Custom metrics dashboard
You can also build a custom metrics dashboard for your infrastructure

Conclusion​

OpenTelemetry makes it very convenient to instrument your Falcon application. You can then use an open-source APM tool like SigNoz to analyze the performance of your app. SigNoz provides both metrics monitoring and distributed tracing so that you don't have to use multiple tools for your monitoring needs.

You can try out SigNoz by visiting its GitHub repo 👇 SigNoz GitHub repo

If you are someone who understands more from video, then you can watch the below video tutorial on the same with SigNoz.

 

YouTube's thumbnail image for the video.

 

If you have any questions or need any help in setting things up, join our slack community and ping us in #support channel.

SigNoz Slack community


If you want to read more about SigNoz 👇

Golang Aplication Monitoring with OpenTelemetry and SigNoz

OpenTelemetry collector - complete guide