KafkaMetricsConfiguration#

pydantic model safir.metrics.KafkaMetricsConfiguration#

Metrics configuration when enabled, including Kafka configuration.

Parameters:
Config:
  • validate_by_name: bool = True

  • alias_generator: AliasGenerator = AliasGenerator(alias=None, validation_alias=<function to_camel at 0x77d375ee6610>, serialization_alias=None)

Fields:
field application: str [Required]#

The name of the application that is emitting these metrics

field backoff_interval: HumanTimedelta = datetime.timedelta(seconds=300)#

The amount of time to wait until further operations are attempted when the event manager is in an error state.

field enabled: <lambda>)] = True#

If set to false, no events will be sent and all calls to publish events will be no-ops.

Constraints:
  • func = <function KafkaMetricsConfiguration.<lambda> at 0x77d377c6f110>

field events: EventsConfiguration [Optional]#
field kafka: KafkaConnectionSettings [Optional]#
field raise_on_error: bool = False#

True if we should raise an exception whenever there is an error with the metrics system dependencies, like Kafka or the Schema Manager. False if we should just log an error instead. This should be False for most production apps so that issues with the metrics infrastructure don’t bring down the app.

field schema_manager: SchemaManagerSettings [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, ...]

make_manager(logger=None, *, kafka_broker=None, request_timeout_ms=1000, extra_broker_settings=None, extra_admin_client_settings=None)#

Make a KafkaEventManager.

The request timeout is set low by default so we don’t block the instrumented app for too long if kafka is unavailable.

Parameters:
  • logger (BoundLogger | None, default: None)

  • kafka_broker (KafkaBroker | None, default: None)

  • request_timeout_ms (int, default: 1000)

  • extra_broker_settings (dict[str, Any] | None, default: None)

  • extra_admin_client_settings (dict[str, Any] | None, default: None)

Return type:

KafkaEventManager

Overrides:

BaseMetricsConfiguration.make_manager