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 a wrapper for a TProcessor
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.Processor(handler)
return baseplateify_processor(processor, baseplate)
-
baseplate.integration.thrift.
baseplateify_processor
(processor, logger, baseplate, edge_context_factory=None)¶ Wrap a Thrift Processor with Baseplate’s span lifecycle.
Parameters: - processor (thrift.Thrift.TProcessor) – The service’s processor to wrap.
- 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=None, edge_context_factory=None, header_trust_handler=None)¶ Config extension to integrate Baseplate into Pyramid.
Parameters: - baseplate (baseplate.core.Baseplate) – The Baseplate instance for your application.
- edge_context_factory (baseplate.core.EdgeRequestContextFactory) – A configured factory for handling edge request context.
- header_trust_handler (baseplate.integration.pyramid.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.
-
class
baseplate.integration.pyramid.
HeaderTrustHandler
¶ Abstract class used by
BaseplateConfigurator
to validate headers.See
StaticTrustHandler
for the default implementation.-
should_trust_trace_headers
(request)¶ Return whether baseplate should parse the trace headers from the inbound request.
Parameters: pyramid.util.Request (request) – The request Returns bool: Whether baseplate should parse the trace headers from the inbound request.
-
should_trust_edge_context_payload
(request)¶ Return whether baseplate should trust the edge context headers from the inbound request.
Parameters: pyramid.util.Request (request) – The request Returns bool: Whether baseplate should trust the inbound edge context headers
-
-
class
baseplate.integration.pyramid.
StaticTrustHandler
(trust_headers=False)¶ 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_headers
toTrue
unless you are sure your application is only accessible by trusted sources (usually backend-only services).-
should_trust_trace_headers
(request)¶ Return whether baseplate should parse the trace headers from the inbound request.
Parameters: pyramid.util.Request (request) – The request Returns bool: Whether baseplate should parse the trace headers from the inbound request.
-
should_trust_edge_context_payload
(request)¶ Return whether baseplate should trust the edge context headers from the inbound request.
Parameters: pyramid.util.Request (request) – The request Returns bool: Whether baseplate should trust the inbound edge context headers
-
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.