swagger_zipkin Package

swagger_zipkin Package

decorate_client Module

class swagger_zipkin.decorate_client.OperationDecorator(operation, func)

Bases: object

A helper to preserve attributes of swaggerpy.client.Operation and bravado.client.CallableOperation while decorating their __call__() methods

Parameters:
  • operation (swaggerpy.client.Operation or bravado.client.CallableOperation) – callable operation, e.g., attributes of swaggerpy.client.Resource or bravado_core.resource.Resource
  • func (callable) – a callable which accepts *args, **kwargs
swagger_zipkin.decorate_client.decorate_client(api_client, func, name)

A helper for decorating bravado.client.SwaggerClient. bravado.client.SwaggerClient can be extended by creating a class which wraps all calls to it. This helper is used in a __getattr__() to check if the attr exists on the api_client. If the attr does not exist raise AttributeError, if it exists and is not callable return it, and if it is callable return a partial function calling func with name.

Example usage:

class SomeClientDecorator(object):

    def __init__(self, api_client, ...):
        self.api_client = api_client

    # First arg should be suffiently unique to not conflict with any of
    # the kwargs
    def wrap_call(self, client_call_name, *args, **kwargs):
        ...

    def __getattr__(self, name):
        return decorate_client(self.api_client, self.wrap_call, name)
Parameters:
  • api_client (bravado.client.SwaggerClient) – the client which is being decorated
  • func (callable) – a callable which accepts name, *args, **kwargs
  • name (string) – the attribute being accessed
Returns:

the attribute from the api_client or a partial of func

Raises:

AttributeError

zipkin_decorator Module

class swagger_zipkin.zipkin_decorator.ZipkinClientDecorator(client)

Bases: object

A wrapper to swagger client (swagger-py or bravado) to pass on zipkin headers to the service call.

Even though client is initialised once, all the calls made will have independent spans.

Parameters:client (swaggerpy.client.SwaggerClient or bravado.client.SwaggerClient.) – Swagger Client
class swagger_zipkin.zipkin_decorator.ZipkinResourceDecorator(resource)

Bases: object

A wrapper to the swagger resource.

Parameters:resource (swaggerpy.client.Resource or bravado_core.resource.Resource) – A resource object. eg. client.pet, client.store.
with_headers(call_name, *args, **kwargs)