diff options
| -rw-r--r-- | src/rabbit_reader.erl | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 8b6d640dec..4e6ef103b0 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -134,7 +134,7 @@ peer_cert_validity, auth_mechanism, ssl_protocol, ssl_key_exchange, ssl_cipher, ssl_hash, protocol, user, vhost, timeout, frame_max, channel_max, client_properties, connected_at, - node, user_who_performed_action]). + node, user_who_performed_action, connection_user_provided_name]). -define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]). @@ -394,10 +394,17 @@ start_connection(Parent, HelperSup, Deb, Sock) -> Properties -> Properties end, + ConnectionUserProvidedName = case get(connection_user_provided_name) of + undefined -> + ''; + ConnectionName -> + ConnectionName + end, rabbit_event:notify(connection_closed, [{name, Name}, {pid, self()}, {node, node()}, - {client_properties, ClientProperties}]) + {client_properties, ClientProperties}, + {connection_user_provided_name, ConnectionUserProvidedName}]) end, done. @@ -1140,6 +1147,7 @@ handle_method0(#'connection.start_ok'{mechanism = Mechanism, % adding client properties to process dictionary to send them later % in the connection_closed event put(client_properties, ClientProperties), + put(connection_user_provided_name, user_provided_connection_name(Connection2)), auth_phase(Response, State); handle_method0(#'connection.secure_ok'{response = Response}, @@ -1469,6 +1477,13 @@ ic(client_properties, #connection{client_properties = CP}) -> CP; ic(auth_mechanism, #connection{auth_mechanism = none}) -> none; ic(auth_mechanism, #connection{auth_mechanism = {Name, _Mod}}) -> Name; ic(connected_at, #connection{connected_at = T}) -> T; +ic(connection_user_provided_name, C) -> + case user_provided_connection_name(C) of + undefined -> + ''; + ConnectionUserProvidedName -> + ConnectionUserProvidedName + end; ic(Item, #connection{}) -> throw({bad_argument, Item}). socket_info(Get, Select, #v1{sock = Sock}) -> @@ -1671,16 +1686,23 @@ control_throttle(State = #v1{connection_state = CS, _ -> State1 end. -augment_connection_log_name(#connection{client_properties = ClientProperties, - name = Name} = Connection) -> - case rabbit_misc:table_lookup(ClientProperties, <<"connection_name">>) of - {longstr, UserSpecifiedName} -> +augment_connection_log_name(#connection{name = Name} = Connection) -> + case user_provided_connection_name(Connection) of + undefined -> + Connection; + UserSpecifiedName -> LogName = <<Name/binary, " - ", UserSpecifiedName/binary>>, rabbit_log_connection:info("Connection ~p (~s) has a client-provided name: ~s~n", [self(), Name, UserSpecifiedName]), ?store_proc_name(LogName), - Connection#connection{log_name = LogName}; + Connection#connection{log_name = LogName} + end. + +user_provided_connection_name(#connection{client_properties = ClientProperties}) -> + case rabbit_misc:table_lookup(ClientProperties, <<"connection_name">>) of + {longstr, UserSpecifiedName} -> + UserSpecifiedName; _ -> - Connection + undefined end. dynamic_connection_name(Default) -> |
