{"id":3200,"library":"opentelemetry-instrumentation-pyramid","title":"OpenTelemetry Pyramid Instrumentation","description":"The `opentelemetry-instrumentation-pyramid` library provides automatic tracing for Pyramid web applications, capturing HTTP requests, view execution, and template rendering with minimal setup. It is part of the OpenTelemetry Python Contrib project, currently at version 0.62b0, and receives monthly updates as part of the broader OpenTelemetry Python Contrib release cadence.","status":"active","version":"0.62b0","language":"en","source_language":"en","source_url":"https://github.com/open-telemetry/opentelemetry-python-contrib","tags":["opentelemetry","observability","tracing","pyramid","web framework","instrumentation"],"install":[{"cmd":"pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-pyramid","lang":"bash","label":"Full setup with OTLP exporter"}],"dependencies":[{"reason":"Required Python version","package":"python","optional":false},{"reason":"Instrumented web framework","package":"pyramid","optional":false},{"reason":"OpenTelemetry API dependency","package":"opentelemetry-api","optional":false},{"reason":"OpenTelemetry SDK dependency","package":"opentelemetry-sdk","optional":false},{"reason":"Common exporter for OTLP traces (optional, other exporters can be used)","package":"opentelemetry-exporter-otlp","optional":true}],"imports":[{"symbol":"PyramidInstrumentor","correct":"from opentelemetry.instrumentation.pyramid import PyramidInstrumentor"}],"quickstart":{"code":"import os\nfrom wsgiref.simple_server import make_server\nfrom pyramid.config import Configurator\nfrom pyramid.response import Response\n\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource, SERVICE_NAME\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter\n\nfrom opentelemetry.instrumentation.pyramid import PyramidInstrumentor\n\n# Configure OpenTelemetry SDK\nresource = Resource.create({\n    SERVICE_NAME: os.environ.get('OTEL_SERVICE_NAME', 'my-pyramid-app'),\n})\n\ntracer_provider = TracerProvider(resource=resource)\n\n# Use OTLP exporter for production, ConsoleSpanExporter for debugging\n# For OTLP, ensure an OTLP collector is running or set OTEL_EXPORTER_OTLP_ENDPOINT\n# otlp_exporter = OTLPSpanExporter(endpoint=os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT', 'localhost:4317'))\n# tracer_provider.add_span_processor(BatchSpanProcessor(otlp_exporter))\n\ntracer_provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter())) # for stdout output\ntrace.set_tracer_provider(tracer_provider)\n\n# Instrument Pyramid (before creating the app)\nPyramidInstrumentor().instrument()\n\n# Define a simple Pyramid view\ndef hello_world(request):\n    return Response('Hello, OpenTelemetry Pyramid!')\n\ndef create_app():\n    with Configurator() as config:\n        config.add_route('hello', '/')\n        config.add_view(hello_world, route_name='hello')\n        app = config.make_wsgi_app()\n    return app\n\n# Run the application\nif __name__ == '__main__':\n    app = create_app()\n    print(\"Serving Pyramid app on http://localhost:6543\")\n    server = make_server('0.0.0.0', 6543, app)\n    server.serve_forever()\n","lang":"python","description":"This quickstart demonstrates how to set up OpenTelemetry for a basic Pyramid application. It initializes the OpenTelemetry SDK with a `TracerProvider` and a `ConsoleSpanExporter` (for local testing), then instruments the Pyramid application using `PyramidInstrumentor().instrument()` before the WSGI app is created. Replace `ConsoleSpanExporter` with `OTLPSpanExporter` for production use, ensuring an OTLP collector is configured."},"warnings":[{"fix":"Monitor releases for stability announcements (e.g., 1.0.0 stable). Consider using OpenTelemetry Python SDK components that are stable (tracing API and SDK) and understand the risks of beta instrumentations.","message":"This library, along with other `opentelemetry-python-contrib` instrumentations, is currently in beta. It should not generally be used in production environments where API stability guarantees are required, as breaking changes may occur without major version bumps.","severity":"breaking","affected_versions":"0.1.0b0 - Current (0.62b0)"},{"fix":"Ensure `trace.set_tracer_provider()` and `PyramidInstrumentor().instrument()` are called at the very beginning of your application's entry point, before `pyramid.config.Configurator()` is used or the WSGI application is created.","message":"The OpenTelemetry SDK (including `TracerProvider`) and instrumentation must be initialized *before* the Pyramid application (or any instrumented code) starts. Incorrect initialization order can lead to missing telemetry data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Modify your `pyramid.tweens` setting to include `opentelemetry.instrumentation.pyramid.trace_tween_factory` alongside any other custom tweens, for example: `config.add_tween('opentelemetry.instrumentation.pyramid.trace_tween_factory')`.","message":"If you are using `PyramidInstrumentor().instrument_config(config)` for a specific `Configurator` and also explicitly setting `pyramid.tweens` for your application, you must manually add `opentelemetry.instrumentation.pyramid.trace_tween_factory` to your tweens list.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure that `pyramid` and its required version are installed in your environment before attempting to import and instrument it with `PyramidInstrumentor`.","message":"As of `opentelemetry-python-contrib` version 1.32.0/0.53b0, dependency checks for instrumented libraries are performed within the `Instrumentor.instrument()` method. If the `pyramid` package is not installed or its version does not meet the instrumentation's requirements, calling `instrument()` can result in an `ImportError` or other crashes.","severity":"gotcha","affected_versions":">=1.32.0/0.53b0 of opentelemetry-python-contrib"},{"fix":"Set the environment variable `OTEL_PYTHON_PYRAMID_EXCLUDED_URLS` to a comma-delimited string of regexes matching the URLs you wish to exclude (e.g., `export OTEL_PYTHON_PYRAMID_EXCLUDED_URLS=\"/healthz,/metrics\"`).","message":"To exclude specific URLs from being traced (e.g., health checks, sensitive paths), you can set the environment variable `OTEL_PYTHON_PYRAMID_EXCLUDED_URLS` or the more general `OTEL_PYTHON_EXCLUDED_URLS`. Without this, all HTTP requests to your Pyramid application will generate spans, potentially increasing noise or exposing sensitive information.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}