baseplate.integration
¶
Helpers for integration with various application frameworks.
This package contains modules which integrate Baseplate with common application frameworks.
See one of the submodules below for your framework of choice.
Thrift¶
Thrift integration for Baseplate.
This module provides an implementation of TProcessorEventHandler
which integrates Baseplate’s facilities into the Thrift request lifecycle.
An abbreviated example of it in use:
def make_processor(app_config):
baseplate = Baseplate()
handler = MyHandler()
processor = my_thrift.MyService.ContextProcessor(handler)
event_handler = BaseplateProcessorEventHandler(logger, baseplate)
processor.setEventHandler(event_handler)
return processor
-
class
baseplate.integration.thrift.
BaseplateProcessorEventHandler
(logger, baseplate, edge_context_factory=None)¶ Processor event handler for Baseplate.
Parameters: - logger (logging.Logger) – The logger to use for error and debug logging.
- baseplate (baseplate.core.Baseplate) – The baseplate instance for your application.
- edge_context_factory (baseplate.core.EdgeRequestContextFactory) – A configured factory for handling edge request context.
Pyramid¶
Pyramid integration for Baseplate.
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()
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.integration.pyramid.
BaseplateConfigurator
(baseplate, trust_trace_headers=False, edge_context_factory=None)¶ Config extension to integrate Baseplate into Pyramid.
Parameters: - baseplate (baseplate.core.Baseplate) – The Baseplate instance for your application.
- trust_trace_headers (bool) – Should this application trust trace
headers from the client? If
True
, trace headers in inbound requests will be used for the server span. IfFalse
, new random trace IDs will be generated for each request. - edge_context_factory (baseplate.core.EdgeRequestContextFactory) – A configured factory for handling edge request context.
Warning
Do not set
trust_trace_headers
toTrue
unless 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.integration.pyramid.
ServerSpanInitialized
(request)¶ 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.ContextFound
event 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.ContextFound
have been called or not.