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.
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.
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.
Instrumenting a sample Falcon application with OpenTelemetry​
Prerequisites for the sample app​
Python 3.8 or newer
Download the latest version of Python.Redis
For Mac usersbrew install redis
brew services start redisFor 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​
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-templateCreate 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/activateYou can read more about creating virtual environments in Python.
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.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
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 wantOTEL_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 replacingIp of SigNoz
 withlocalhost
, 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.
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
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
You can then choose a particular timestamp where latency is high to drill down to traces around that timestamp.
You can use flamegraphs to exactly identify the issue causing the latency.
You can also build 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 👇
If you are someone who understands more from video, then you can watch the below video tutorial on the same with SigNoz.
Â
Â
If you have any questions or need any help in setting things up, join our slack community and ping us in #support
channel.
If you want to read more about SigNoz 👇