baseplate.frameworks.pyramid¶
Pyramid is a mature web framework for Python that we build HTTP services with.
This module provides a configuration extension for Pyramid which integrates Baseplate’s facilities into the Pyramid WSGI request lifecycle.
An abbreviated example of it in use:
def make_app(app_config):
configurator = Configurator()
baseplate = Baseplate(app_config)
baseplate_config = BaseplateConfigurator(
baseplate,
trust_trace_headers=True,
)
configurator.include(baseplate_config.includeme)
return configurator.make_wsgi_app()
Warning
Because of how Baseplate instruments Pyramid, you should not make an exception view prevent Baseplate from seeing the unhandled error and reporting it appropriately.
-
class
baseplate.frameworks.pyramid.BaseplateConfigurator(baseplate, trust_trace_headers=None, edge_context_factory=None, header_trust_handler=None)[source]¶ Configuration extension to integrate Baseplate into Pyramid.
Parameters: - baseplate (
Baseplate) – The Baseplate instance for your application. - edge_context_factory (
Optional[EdgeRequestContextFactory]) – A configured factory for handling edge request context. - header_trust_handler (
Optional[HeaderTrustHandler]) – An object which will be used to verify whether baseplate should parse the request context headers, for example trace ids. See StaticTrustHandler for the default implementation.
- baseplate (
-
class
baseplate.frameworks.pyramid.HeaderTrustHandler[source]¶ Abstract class used by
BaseplateConfiguratorto validate headers.See
StaticTrustHandlerfor the default implementation.
-
class
baseplate.frameworks.pyramid.StaticTrustHandler(trust_headers=False)[source]¶ Default implementation for handling headers.
This class is created automatically by BaseplateConfigurator unless you supply your own HeaderTrustHandler
Parameters: trust_headers ( bool) – Whether or not to trust trace and edge context headers from inbound requests. This value will be returned by should_trust_trace_headers and should_trust_edge_context_payload.Warning
Do not set
trust_headerstoTrueunless you are sure your application is only accessible by trusted sources (usually backend-only services).
Events¶
Within its Pyramid integration, Baseplate will emit events at various stages of the request lifecycle that services can hook into.
-
class
baseplate.frameworks.pyramid.ServerSpanInitialized(request)[source]¶ Event that Baseplate fires after creating the ServerSpan for a Request.
This event will be emitted before the Request is passed along to it’s handler. Baseplate initializes the ServerSpan in response to a
pyramid.events.ContextFoundevent emitted by Pyramid so while we can guarantee what Baseplate has done when this event is emitted, we cannot guarantee that any other subscribers topyramid.events.ContextFoundhave been called or not.