11use crate :: { cdn:: CdnKind , storage:: StorageKind } ;
22use anyhow:: { anyhow, bail, Context , Result } ;
3- use std:: { env:: VarError , error:: Error , path:: PathBuf , str:: FromStr , time:: Duration } ;
3+ use serde:: ser:: { Serialize , SerializeStruct , Serializer } ;
4+ use std:: { env:: VarError , error:: Error , path:: PathBuf , str:: FromStr , sync:: Arc , time:: Duration } ;
45use tracing:: trace;
56use url:: Url ;
67
@@ -11,6 +12,10 @@ pub struct Config {
1112 pub registry_url : Option < String > ,
1213 pub registry_api_host : Url ,
1314
15+ // sentry config
16+ pub sentry_dsn : Option < sentry:: types:: Dsn > ,
17+ pub sentry_traces_sample_rate : Option < f32 > ,
18+
1419 // Database connection params
1520 pub ( crate ) database_url : String ,
1621 pub ( crate ) max_legacy_pool_size : u32 ,
@@ -148,6 +153,9 @@ impl Config {
148153 ) ?,
149154 prefix : prefix. clone ( ) ,
150155
156+ sentry_dsn : maybe_env ( "SENTRY_DSN" ) ?,
157+ sentry_traces_sample_rate : maybe_env ( "SENTRY_TRACES_SAMPLE_RATE" ) ?,
158+
151159 database_url : require_env ( "DOCSRS_DATABASE_URL" ) ?,
152160 max_legacy_pool_size : env ( "DOCSRS_MAX_LEGACY_POOL_SIZE" , 45 ) ?,
153161 max_pool_size : env ( "DOCSRS_MAX_POOL_SIZE" , 45 ) ?,
@@ -224,6 +232,25 @@ impl Config {
224232 }
225233}
226234
235+ /// A more public version of the config that will be automaticaly exposed to the
236+ /// Tera context.
237+ pub ( crate ) struct PublicConfig ( pub Arc < Config > ) ;
238+
239+ impl Serialize for PublicConfig {
240+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
241+ where
242+ S : Serializer ,
243+ {
244+ let mut state = serializer. serialize_struct ( "PublicConfig" , 2 ) ?;
245+ state. serialize_field ( "sentry_dsn" , & self . 0 . sentry_dsn ) ?;
246+ state. serialize_field (
247+ "sentry_traces_sample_rate" ,
248+ & self . 0 . sentry_traces_sample_rate ,
249+ ) ?;
250+ state. end ( )
251+ }
252+ }
253+
227254fn env < T > ( var : & str , default : T ) -> Result < T >
228255where
229256 T : FromStr ,
0 commit comments