EventManager#
- class safir.metrics.EventManager(topic, logger=None)#
- Bases: - object- Interface for a client for publishing application metrics events. - This interface is implemented by the fully-functional - KafkaEventManagerand the disabled- NoopEventManager. The latter is used when events publishing is disabled so that the rest of the application code doesn’t need to change.- Parameters:
- topic ( - str) – Kafka topic to which events will be published.
- logger ( - BoundLogger|- None, default:- None) – Logger to use. The- safir.metricslogger will be used if none is provided.
 
 - topic#
- Kafka topic to which events will be published. 
 - logger#
- Logger that subclasses should use. This should not be used outside of subclasses of this class. 
 - Methods Summary - aclose()- Shut down any internal state or managed clients. - build_publisher_for_model(model)- Implementation-specific construction of the event publisher. - create_publisher(name, payload_model)- Create an - EventPublisherfor a type of event.- Initialize any internal state or managed clients. - Methods Documentation - abstract async build_publisher_for_model(model)#
- Implementation-specific construction of the event publisher. - This class must be overridden by child classes to do the implementation-specific work of constructing an appropriate child instance of - EventPublisher.- Parameters:
- model ( - type[- TypeVar(- P, bound=- EventPayload)]) – Enriched and configured model representing the event that will be published.
- Returns:
- An appropriate event publisher implementation instance. 
- Return type:
 
 - async create_publisher(name, payload_model)#
- Create an - EventPublisherfor a type of event.- The schema is registered with the schema manager when this method is called. - Parameters:
- name ( - str) – Name of the event. This will be used as the name of the Avro schema and record and the name of the event in the event storage backend.
- payload_model ( - type[- TypeVar(- P, bound=- EventPayload)]) – A type derived from- EventPayload. This defines the type of models that will be passed into the- publishmethod of the resulting publisher. The events as published will include the information in this model plus the fields of- EventMetadata.
 
- Returns:
- A publisher for a type of event matching the - payload_model.
- Return type:
- Raises:
- DuplicateEventError – Raised if a publisher with the same name was already registered. 
- EventManagerUnintializedError – Raised if the - initializemethod was not been called before calling this method.
- KafkaTopicError – Raised if the topic for publishing events doesn’t exist or we don’t have access to it. 
 
 
 - async initialize()#
- Initialize any internal state or managed clients. - This method must be called before calling - create_publisher.- Return type: