@@ -67,12 +67,13 @@ const SUBSCRIBER_INSTALL_PATTERNS: &[&str] = &[
6767] ;
6868
6969const SUBSCRIBER_INSTALL_ALLOWLIST : & [ & str ] = & [
70- // Legacy local logging entrypoint. This is tracked until the unified logging bootstrap replaces it .
70+ // Deprecated compatibility wrapper. It must not grow new runtime behavior, but existing callers still compile .
7171 "rocketmq-common/src/log.rs" ,
72- // Current OpenTelemetry trace/log layer installation sites. Task 1 makes their install status explicit .
72+ // Legacy observability entrypoint retained for source compatibility while production entries use logging.rs .
7373 "rocketmq-observability/src/init.rs" ,
7474 // Unified logging and telemetry bootstrap owns the new production subscriber installation path.
7575 "rocketmq-observability/src/logging.rs" ,
76+ // Trace-only compatibility helper retained for callers that have not migrated to install_global yet.
7677 "rocketmq-observability/src/trace.rs" ,
7778] ;
7879
@@ -151,10 +152,7 @@ fn subscriber_installation_sites_are_tracked() {
151152
152153 let source =
153154 fs:: read_to_string ( & file) . unwrap_or_else ( |error| panic ! ( "failed to read {}: {error}" , file. display( ) ) ) ;
154- if SUBSCRIBER_INSTALL_PATTERNS
155- . iter ( )
156- . any ( |pattern| source. contains ( pattern) )
157- {
155+ if has_subscriber_installation ( & source) {
158156 unexpected_files. insert ( relative_path) ;
159157 }
160158 }
@@ -166,6 +164,43 @@ fn subscriber_installation_sites_are_tracked() {
166164 ) ;
167165}
168166
167+ #[ test]
168+ fn subscriber_installation_detector_catches_direct_fmt_init ( ) {
169+ let source = r#"
170+ fn main() {
171+ tracing_subscriber::fmt().with_max_level(tracing::Level::INFO).init();
172+ }
173+ "# ;
174+
175+ assert ! ( has_subscriber_installation( source) ) ;
176+ }
177+
178+ #[ test]
179+ fn subscriber_installation_detector_catches_imported_init_extension ( ) {
180+ let source = r#"
181+ use tracing_subscriber::fmt;
182+ use tracing_subscriber::util::SubscriberInitExt;
183+
184+ fn install() {
185+ fmt().with_target(true).try_init().expect("subscriber installs");
186+ }
187+ "# ;
188+
189+ assert ! ( has_subscriber_installation( source) ) ;
190+ }
191+
192+ #[ test]
193+ fn subscriber_installation_detector_ignores_unrelated_init_methods ( ) {
194+ let source = r#"
195+ fn install_store(store: &mut Store) {
196+ store.init();
197+ let _ = ratatui::try_init();
198+ }
199+ "# ;
200+
201+ assert ! ( !has_subscriber_installation( source) ) ;
202+ }
203+
169204#[ test]
170205fn metric_name_constants_are_declared_only_in_canonical_or_legacy_files ( ) {
171206 let workspace_root = workspace_root ( ) ;
@@ -244,6 +279,41 @@ fn has_metric_constant_definition(source: &str) -> bool {
244279 } )
245280}
246281
282+ fn has_subscriber_installation ( source : & str ) -> bool {
283+ if SUBSCRIBER_INSTALL_PATTERNS
284+ . iter ( )
285+ . any ( |pattern| source. contains ( pattern) )
286+ {
287+ return true ;
288+ }
289+
290+ if source. contains ( "set_global_default(" )
291+ && ( source. contains ( "tracing::subscriber" ) || source. contains ( "tracing_subscriber" ) )
292+ {
293+ return true ;
294+ }
295+
296+ source
297+ . split ( ';' )
298+ . any ( |statement| subscriber_init_statement_installs_global_subscriber ( source, statement) )
299+ }
300+
301+ fn subscriber_init_statement_installs_global_subscriber ( source : & str , statement : & str ) -> bool {
302+ let invokes_init = statement. contains ( ".init(" ) || statement. contains ( ".try_init(" ) ;
303+ if !invokes_init {
304+ return false ;
305+ }
306+
307+ if statement. contains ( "tracing_subscriber::" ) {
308+ return true ;
309+ }
310+
311+ source. contains ( "tracing_subscriber" )
312+ && ( statement. contains ( "fmt()" )
313+ || statement. contains ( "registry()" )
314+ || ( source. contains ( "SubscriberInitExt" ) && statement. contains ( ".with(" ) ) )
315+ }
316+
247317fn path_set ( paths : & [ & str ] ) -> BTreeSet < String > {
248318 paths. iter ( ) . map ( |path| ( * path) . to_string ( ) ) . collect ( )
249319}
0 commit comments