Installation
Add thesentry-options crate to your Cargo.toml:
Cargo.toml
Quick start
Functions
init()
Initialize global options using fallback chain:SENTRY_OPTIONS_DIR env var, then /etc/sentry-options if it exists, otherwise sentry-options/.
Returns
Ok(()) on success, or OptionsError::AlreadyInitialized if already initialized.options(namespace)
Get a namespace handle for accessing options.The namespace to access
Returns a handle for accessing options within the specified namespace.
init() has not been called.
Example
Options struct
Options store for reading configuration values.Options::new()
Load options using fallback chain:SENTRY_OPTIONS_DIR env var, then /etc/sentry-options if it exists, otherwise sentry-options/. Expects {dir}/schemas/ and {dir}/values/ subdirectories.
Returns a new
Options instance, or an OptionsError if initialization fails.Options::from_directory(base_dir)
Load options from a specific directory (useful for testing). Expects{base_dir}/schemas/ and {base_dir}/values/ subdirectories.
The base directory containing
schemas/ and values/ subdirectoriesReturns a new
Options instance, or an OptionsError if initialization fails.Options::get(namespace, key)
Get an option value, returning the schema default if not set.The namespace to query
The option key to retrieve
Returns the option value as
serde_json::Value, or an OptionsError if the namespace or option is unknown.Options::isset(namespace, key)
Check if an option has a value. Returnstrue if the option is defined and has a value, will return false if the option is defined and does not have a value.
If the namespace or option are not defined, an Err will be returned.
The namespace to query
The option key to check
Returns
true if the option has a value, false if using default, or an OptionsError if the namespace or option is unknown.NamespaceOptions struct
Handle for accessing options within a specific namespace.NamespaceOptions::get(key)
Get an option value, returning the schema default if not set.The option key to retrieve
Returns the option value as
serde_json::Value, or an OptionsError if the option is unknown.NamespaceOptions::isset(key)
Check if an option has a key defined, or if the default is being used.The option key to check
Returns
true if the option has a value, false if using default, or an OptionsError if the option is unknown.Error types
OptionsError
Enum representing all possible errors in the options system.Variants
Unknown namespace error. Contains the namespace name that was not found.
Unknown option error. Contains the namespace and option key that were not found.
Schema error. Wraps validation errors from schema loading or validation failures.
AlreadyInitialized
Options already initialized error. Raised when
init() is called more than once.Complete example
examples/rust/src/main.rs