Monitor Falcon with OpenTelemetry
Falcon is a minimalist web framework for building RESTful APIs in Python. It is lightweight, fast, and designed to be easy to use.
By integrating OpenTelemetry into your Falcon application, you can capture and export telemetry data such as traces, metrics, and logs. You can use that data for monitoring, troubleshooting, and analyzing the behavior and performance of your application.
What is OpenTelemetry?
OpenTelemetry is an open-source observability framework that aims to standardize and simplify the collection, processing, and export of telemetry data from applications and systems.
OpenTelemetry supports multiple programming languages and platforms, making it suitable for a wide range of applications and environments.
OpenTelemetry enables developers to instrument their code and collect telemetry data, which can then be exported to various OpenTelemetry backends or observability platforms for analysis and visualization.
To instrument Falcon app, you need to install the corresponding OpenTelemetry Falcon instrumentation:
pip install opentelemetry-instrumentation-falcon
Use the following code to integrate OpenTelemetry to capture telemetry data from your Falcon application:
from falcon import API from opentelemetry.instrumentation.falcon import FalconInstrumentor FalconInstrumentor().instrument() app = falcon.API() class HelloWorldResource(object): def on_get(self, req, resp): resp.body = 'Hello World' app.add_route('/hello', HelloWorldResource())
You can exclude certain URLs from being tracked using environment variables:
# excludes requests such as `https://site/client/123/info` and `https://site/xyz/healthcheck` export OTEL_PYTHON_FALCON_EXCLUDED_URLS="client/.*/info,healthcheck"
You can also extract certain attributes from Falcon’s request object and use them as span attributes:
See documentation for more details.
You can specify request and response hooks:
# the hook is called right after a Span is created def request_hook(span, req): pass # the hook is called right before the span is finished def response_hook(span, req, resp): pass FalconInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)
What is Uptrace?
Uptrace is a distributed tracing tool that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.
Uptrace comes with an intuitive query builder, rich dashboards, alerting rules with notifications, and integrations for most languages and frameworks.
Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.
Next, instrument more operations to get a more detailed picture. Try to prioritize network calls, disk operations, database queries, error and logs.
You can also create your own instrumentations using OpenTelemetry Python Tracing API.