@@ -74,22 +74,43 @@ tap_out({#resource{name = QName, virtual_host = VHost},
7474-spec start (rabbit_types :vhost ()) -> 'ok' .
7575
7676start (VHost ) ->
77- _ = rabbit_log :info (" Enabling tracing for vhost '~s '~n " , [VHost ]),
78- update_config (fun (VHosts ) -> [VHost | VHosts -- [VHost ]] end ).
77+ case lists :member (VHost , vhosts_with_tracing_enabled ()) of
78+ true ->
79+ _ = rabbit_log :info (" Tracing is already enabled for vhost '~s '" , [VHost ]),
80+ ok ;
81+ false ->
82+ _ = rabbit_log :info (" Enabling tracing for vhost '~s '" , [VHost ]),
83+ update_config (fun (VHosts ) ->
84+ lists :usort ([VHost | VHosts ])
85+ end )
86+ end .
7987
8088-spec stop (rabbit_types :vhost ()) -> 'ok' .
8189
8290stop (VHost ) ->
83- _ = rabbit_log :info (" Disabling tracing for vhost '~s '~n " , [VHost ]),
84- update_config (fun (VHosts ) -> VHosts -- [VHost ] end ).
91+ case lists :member (VHost , vhosts_with_tracing_enabled ()) of
92+ true ->
93+ _ = rabbit_log :info (" Disabling tracing for vhost '~s '" , [VHost ]),
94+ update_config (fun (VHosts ) -> VHosts -- [VHost ] end );
95+ false ->
96+ _ = rabbit_log :info (" Tracing is already disabled for vhost '~s '" , [VHost ]),
97+ ok
98+ end .
8599
86100update_config (Fun ) ->
87- { ok , VHosts0 } = application : get_env ( rabbit , ? TRACE_VHOSTS ),
101+ VHosts0 = vhosts_with_tracing_enabled ( ),
88102 VHosts = Fun (VHosts0 ),
89103 application :set_env (rabbit , ? TRACE_VHOSTS , VHosts ),
90- rabbit_channel :refresh_config_local (),
104+ _ = rabbit_log :debug (" Will now refresh channel state after virtual host tracing changes" ),
105+
106+ {Time , _ } = timer :tc (fun rabbit_channel :refresh_config_local /0 ),
107+ _ = rabbit_log :debug (" Refreshed channel state in ~f s" , [Time / 1000000 ]),
108+
91109 ok .
92110
111+ vhosts_with_tracing_enabled () ->
112+ application :get_env (rabbit , ? TRACE_VHOSTS , []).
113+
93114% %----------------------------------------------------------------------------
94115
95116trace (# exchange {name = Name }, # basic_message {exchange_name = Name },
0 commit comments