@@ -41,6 +41,39 @@ impl Cli {
4141 |token| gather_debug_props ( env:: args ( ) . collect :: < Vec < String > > ( ) , token) . command_line ,
4242 )
4343 }
44+
45+ pub fn command_name ( & self ) -> & str {
46+ match & self . command {
47+ Commands :: Quarantine ( ..) => "quarantine" ,
48+ Commands :: Test ( ..) => "test" ,
49+ Commands :: Upload ( ..) => "upload" ,
50+ Commands :: Validate ( ..) => "validate" ,
51+ }
52+ }
53+
54+ pub fn org_url_slug ( & self ) -> String {
55+ match & self . command {
56+ Commands :: Quarantine ( args) => args. org_url_slug ( ) ,
57+ Commands :: Test ( args) => args. org_url_slug ( ) ,
58+ Commands :: Upload ( args) => args. org_url_slug . clone ( ) ,
59+ Commands :: Validate ( ..) => String :: from ( "not used" ) ,
60+ }
61+ }
62+
63+ pub fn repo_root ( & self ) -> String {
64+ let explicit_root = match & self . command {
65+ Commands :: Quarantine ( args) => args. repo_root ( ) ,
66+ Commands :: Test ( args) => args. repo_root ( ) ,
67+ Commands :: Upload ( args) => args. repo_root . clone ( ) ,
68+ Commands :: Validate ( ..) => None ,
69+ } ;
70+ explicit_root
71+ . or ( std:: env:: current_dir ( )
72+ . iter ( )
73+ . flat_map ( |path_buf| path_buf. clone ( ) . into_os_string ( ) . into_string ( ) . into_iter ( ) )
74+ . next ( ) )
75+ . unwrap_or ( String :: from ( "not set" ) )
76+ }
4477}
4578
4679#[ derive( Debug , Subcommand ) ]
@@ -67,7 +100,12 @@ fn main() -> anyhow::Result<()> {
67100 . block_on ( async {
68101 let cli = Cli :: parse ( ) ;
69102 let log_level_filter = cli. verbose . log_level_filter ( ) ;
70- setup_logger ( log_level_filter) ?;
103+ setup_logger (
104+ log_level_filter,
105+ cli. command_name ( ) ,
106+ cli. org_url_slug ( ) ,
107+ cli. repo_root ( ) ,
108+ ) ?;
71109 tracing:: info!( "{}" , TITLE_CARD ) ;
72110 tracing:: info!(
73111 command = cli. debug_props( ) ,
@@ -119,19 +157,46 @@ fn to_trace_filter(filter: log::LevelFilter) -> tracing::Level {
119157 }
120158}
121159
122- fn setup_logger ( log_level_filter : LevelFilter ) -> anyhow:: Result < ( ) > {
123- // trunk-ignore(clippy/match_ref_pats)
124- let sentry_layer = sentry_tracing:: layer ( ) . event_filter ( |md| match md. level ( ) {
125- & tracing:: Level :: ERROR => sentry_tracing:: EventFilter :: Event ,
126- & tracing:: Level :: WARN => sentry_tracing:: EventFilter :: Breadcrumb ,
127- & tracing:: Level :: INFO => sentry_tracing:: EventFilter :: Breadcrumb ,
128- & tracing:: Level :: DEBUG => sentry_tracing:: EventFilter :: Breadcrumb ,
129- _ => sentry_tracing:: EventFilter :: Ignore ,
160+ fn setup_logger (
161+ log_level_filter : LevelFilter ,
162+ command_name : & str ,
163+ org_url_slug : String ,
164+ repo_root : String ,
165+ ) -> anyhow:: Result < ( ) > {
166+ let command_string = String :: from ( command_name) ;
167+ let sentry_layer = sentry_tracing:: layer ( ) . event_mapper ( move |event, context| {
168+ // trunk-ignore(clippy/match_ref_pats)
169+ match event. metadata ( ) . level ( ) {
170+ & tracing:: Level :: ERROR => {
171+ let mut event = sentry_tracing:: event_from_event ( event, context) ;
172+ event
173+ . tags
174+ . insert ( String :: from ( "command_name" ) , command_string. clone ( ) ) ;
175+ event
176+ . tags
177+ . insert ( String :: from ( "org_url_slug" ) , org_url_slug. clone ( ) ) ;
178+ event
179+ . tags
180+ . insert ( String :: from ( "repo_root" ) , repo_root. clone ( ) ) ;
181+ sentry_tracing:: EventMapping :: Event ( event)
182+ }
183+ & tracing:: Level :: WARN => sentry_tracing:: EventMapping :: Breadcrumb (
184+ sentry_tracing:: breadcrumb_from_event ( event, context) ,
185+ ) ,
186+ & tracing:: Level :: INFO => sentry_tracing:: EventMapping :: Breadcrumb (
187+ sentry_tracing:: breadcrumb_from_event ( event, context) ,
188+ ) ,
189+ & tracing:: Level :: DEBUG => sentry_tracing:: EventMapping :: Breadcrumb (
190+ sentry_tracing:: breadcrumb_from_event ( event, context) ,
191+ ) ,
192+ _ => sentry_tracing:: EventMapping :: Ignore ,
193+ }
130194 } ) ;
131195
132196 let console_layer = tracing_subscriber:: fmt:: Layer :: new ( )
133197 . without_time ( )
134198 . with_target ( false )
199+ . with_level ( false )
135200 . with_writer ( std:: io:: stdout. with_max_level ( to_trace_filter ( log_level_filter) ) )
136201 . with_filter ( FilterFn :: new ( |metadata| {
137202 !metadata
0 commit comments