nameko_chassis¶
- nameko_chassis.debug.debug_runner(runner)[source]¶
Dump debug information about service state to standard output.
Call this method from within nameko backdoor which exposes a
runnerlocal variable.If rich is available, the output will be way prettier than you’d expect :)
- nameko_chassis.debug.debug_state_rich(state: ServiceState) None[source]¶
Pretty-print service state using rich.
- nameko_chassis.debug.debug_state_simple(state: ServiceState) None[source]¶
Print service state to stdout with some rudimentary formatting.
- class nameko_chassis.dependencies.ContainerProvider(*args, **kwargs)[source]¶
Allows access to
ServiceContainerrunning current worker.
- class nameko_chassis.dependencies.ServiceDiscoveryProvider(*args, **kwargs)[source]¶
- get_dependency(worker_ctx: WorkerContext) ServiceDiscovery[source]¶
Called before worker execution. A DependencyProvider should return an object to be injected into the worker instance by the container.
- nameko_chassis.dependencies.setup_sentry_sdk(**kwargs) None[source]¶
Initialize Sentry integration. Call it once per service container.
All keywords arguments are forwarded to
sentry_sdk.init()(with some defaults).
- class nameko_chassis.discovery.ServiceDiscovery(client: Client)[source]¶
Provides introspection for nameko services defined on the RabbitMQ cluster.
- nameko_chassis.health.is_service_responsive(service_proxy: Client, fail_gracefully=False, timeout: float = 5, method_name: str = 'say_hello') bool[source]¶
A poor man’s circuit breaker for nameko service proxies.
True circuit breaker would wrap each and every RPC method and monitor it’s error rate and duration. This implementation only checks if the service responds within
timeoutseconds. By default, it raises an exception if service is unreachable. However iffail_gracefullyisTrue, function returns normally and it is up to the caller to implement some sort of fallback mechanism.- Parameters:
service_proxy – nameko service proxy provided by
RPCProxyfail_gracefully – if
True, don’t raiseServiceTimeouttimeout – timeout in seconds
method_name – which method to call to check if service is healthy
- Raises:
ServiceTimeout: if service is unresponsive and
fail_gracefullyis False- Returns:
Trueif service is responsive
- class nameko_chassis.service.Service[source]¶
Base class for nameko services.
- set_log_level(logger_name: str, level: int) str[source]¶
Temporarily override log level in a running service.
Useful for example for debugging a live service instance, where your default log level is INFO or higher to avoid clutter in logs. This RPC allows you to change log level while the application is running.
For example:
>>> n.rpc.my_service.set_log_level("some.module", logging.DEBUG)
Now your logs will include debug messages from
some.moduleeven if your static log configuration (dictConfig etc.) silenced them.Caveat #1: Updating log level in this manner will only affect loggers acquired after this RPC call. So your code must call
logging.get_logger()as late as possible. This unfortunately means that library code may or may not be affected - depends on how the library acquires its loggers.Caveat #2: If your service runs in multiple replicas behind a load balancer, you must call this RPC method at least as many times as there are replicas to ensure that each replica will have its log level changed.
- class nameko_chassis.service.ServiceState(version: str, service_name: str, uptime: float, entrypoints: List[str], dependencies: List[str], running_workers: int, max_workers: int, worker_states: List[WorkerState])[source]¶
Introspection result for an entire service, including running workers.
- classmethod from_container(container: ServiceContainer) ServiceState[source]¶
Introspects a service container and its workers to build ServiceState.