OpenTelemetry Falcon Instrumentation

0.62b0 · active · verified Fri Apr 10

OpenTelemetry Falcon instrumentation provides automatic tracing for HTTP requests in Falcon web applications. It captures request flow, uses Falcon resource and method names as span names, and records errors. Currently at version 0.62b0, this library is part of the broader opentelemetry-python-contrib project, which often releases beta versions in sync with the core OpenTelemetry Python SDK's release cadence, indicating active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instrument a basic Falcon application using `FalconInstrumentor`. Ensure the OpenTelemetry SDK is configured and `FalconInstrumentor().instrument()` is called before creating your `falcon.App()` instance. This example uses a `ConsoleSpanExporter` for immediate feedback to the console.

import falcon
from opentelemetry.instrumentation.falcon import FalconInstrumentor
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor

# Configure OpenTelemetry SDK
resource = Resource.create({"service.name": "my-falcon-app"})
provider = TracerProvider(resource=resource)
span_processor = SimpleSpanProcessor(ConsoleSpanExporter())
provider.add_span_processor(span_processor)
trace.set_tracer_provider(provider)

# Instrument Falcon BEFORE creating the app instance
FalconInstrumentor().instrument()

class HelloResource:
    def on_get(self, req, resp):
        resp.status = falcon.HTTP_200
        resp.media = {'message': 'Hello World'}

app = falcon.App()
app.add_route('/hello', HelloResource())

# To run this app (e.g., using Gunicorn):
# gunicorn -b 127.0.0.1:8000 your_module_name:app
# Then access http://127.0.0.1:8000/hello

view raw JSON →