BaseMetricsConfiguration#

pydantic model safir.metrics.BaseMetricsConfiguration#

Metrics configuration, including the required Kafka configuration.

Currently, this only configures events, but if additional types of metrics are added in the future, that configuration will be added here.

This is the recommended configuration approach if you don’t need to use Kafka, the schema manager, or the schema registry in any other parts of your application. Applications that also use Kafka directly should instead create a EventManager with externally-managed Kafka clients.

Parameters:
Config:
  • validate_by_name: bool = True

Fields:
field application: str [Required]#

The name of the application that is emitting these metrics

field events: EventsConfiguration [Optional]#
classmethod settings_cached()#

Return the cached default settings instance for this settings class.

The instance is constructed on first use and reused afterwards. Subclasses are cached separately, so caching a class does not affect its parents or children.

Return type:

Self

classmethod settings_clear_cache()#

Remove the cached default settings instance for this settings class, if any.

Only the cache entry for this exact class is removed. Subclasses keep their own cached instances and must be cleared individually.

A settings_cached() call already in flight may still return the instance it was building, so clearing does not retroactively invalidate references other threads hold.

Return type:

None

classmethod settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)#

Define the sources and their order for loading the settings values.

Args:

settings_cls: The Settings class. init_settings: The InitSettingsSource instance. env_settings: The EnvSettingsSource instance. dotenv_settings: The DotEnvSettingsSource instance. file_secret_settings: The SecretsSettingsSource instance.

Returns:

A tuple containing the sources and their order for loading the settings values.

Parameters:
  • settings_cls (type[BaseSettings])

  • init_settings (PydanticBaseSettingsSource)

  • env_settings (PydanticBaseSettingsSource)

  • dotenv_settings (PydanticBaseSettingsSource)

  • file_secret_settings (PydanticBaseSettingsSource)

Return type:

tuple[PydanticBaseSettingsSource, ...]

abstractmethod make_manager(logger=None, *, kafka_broker=None)#

Construct an EventManager.

Parameters:
  • logger (BoundLogger | None, default: None) – Logger to use for internal logging. If not given, the safir.metrics logger will be used.

  • kafka_broker (KafkaBroker | None, default: None) – Kafka broker to use. If not given, a new Kafka broker will be created and automatically closed when the event manager is closed. If a broker is provided, closing the event manager will have no effect on it and the caller is responsible for starting and closing it.

Returns:

An event manager appropriate to the configuration.

Return type:

EventManager