Monitor Pyramid performance with OpenTelemetry
OpenTelemetry Pyramid is an implementation of the OpenTelemetry specification for Pyramid framework. It provides a middleware that can be used to automatically generate traces for incoming requests and outgoing responses.
Pyramid is a free, open-source web framework for building web applications in Python. It was previously known as Pylons and was later rebranded as Pyramid.
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 use OpenTelemetry with Pyramid, you need to install the
pip install opentelemetry-instrumentation-pyramid
Here's an example of how to configure Pyramid with OpenTelemetry using the Uptrace backend:
from opentelemetry.instrumentation.pyramid import PyramidInstrumentor import uptrace if __name__ == "__main__": uptrace.configure_opentelemetry( # Set dsn or UPTRACE_DSN env var. # dsn="", service_name="myservice", service_version="1.0.0", ) PyramidInstrumentor().instrument() with Configurator() as config: config.add_route("home", "/") config.scan() app = config.make_wsgi_app() print("listening on http://localhost:6543") server = make_server("0.0.0.0", 6543, app) server.serve_forever()
See the example on GitHub for more details.
What is Uptrace?
Uptrace is a Grafana alternative 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.
You can disable tracing on certain URLs by providing an environment variable with the list of URLs, for example, the following config will exclude URLs like
See documentation for details.
To capture HTTP request headers, set the environment variable to a comma delimited list of HTTP header names:
# list of headers export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST="content-type,custom_request_header" # regexp export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST="Accept.*,X-.*" # all headers export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
To capture HTTP response headers:
# list of headers export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE="content-type,custom_response_header" # regexp export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE="Content.*,X-.*" # all headers export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=".*"
You can also sanitize captured headers to prevent storing sensitive data:
See documentation for details.
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.