@@ -114,22 +114,24 @@ impl Client {
114
114
let connection_info = connection. info ( ) ;
115
115
let request_id = crate :: cmap:: conn:: next_request_id ( ) ;
116
116
117
- let should_redact = REDACTED_COMMANDS . contains ( cmd. name . to_lowercase ( ) . as_str ( ) ) ;
118
-
119
- let command_body = if should_redact {
120
- Document :: new ( )
121
- } else {
122
- cmd. body . clone ( )
123
- } ;
124
- let command_started_event = CommandStartedEvent {
125
- command : command_body,
126
- db : cmd. target_db . clone ( ) ,
127
- command_name : cmd. name . clone ( ) ,
128
- request_id,
129
- connection : connection_info. clone ( ) ,
130
- } ;
131
-
132
- self . send_command_started_event ( command_started_event) ;
117
+ self . emit_command_event ( |handler| {
118
+ let should_redact = REDACTED_COMMANDS . contains ( cmd. name . to_lowercase ( ) . as_str ( ) ) ;
119
+
120
+ let command_body = if should_redact {
121
+ Document :: new ( )
122
+ } else {
123
+ cmd. body . clone ( )
124
+ } ;
125
+ let command_started_event = CommandStartedEvent {
126
+ command : command_body,
127
+ db : cmd. target_db . clone ( ) ,
128
+ command_name : cmd. name . clone ( ) ,
129
+ request_id,
130
+ connection : connection_info. clone ( ) ,
131
+ } ;
132
+
133
+ handler. handle_command_started_event ( command_started_event) ;
134
+ } ) ;
133
135
134
136
let start_time = PreciseTime :: now ( ) ;
135
137
@@ -148,31 +150,39 @@ impl Client {
148
150
149
151
match response_result {
150
152
Err ( error) => {
151
- let command_failed_event = CommandFailedEvent {
152
- duration,
153
- command_name : cmd. name ,
154
- failure : error. clone ( ) ,
155
- request_id,
156
- connection : connection_info,
157
- } ;
158
- self . send_command_failed_event ( command_failed_event) ;
153
+ self . emit_command_event ( |handler| {
154
+ let command_failed_event = CommandFailedEvent {
155
+ duration,
156
+ command_name : cmd. name ,
157
+ failure : error. clone ( ) ,
158
+ request_id,
159
+ connection : connection_info,
160
+ } ;
161
+
162
+ handler. handle_command_failed_event ( command_failed_event) ;
163
+ } ) ;
159
164
Err ( error)
160
165
}
161
166
Ok ( response) => {
162
- let reply = if should_redact {
163
- Document :: new ( )
164
- } else {
165
- response. raw_response . clone ( )
166
- } ;
167
-
168
- let command_succeeded_event = CommandSucceededEvent {
169
- duration,
170
- reply,
171
- command_name : cmd. name . clone ( ) ,
172
- request_id,
173
- connection : connection_info,
174
- } ;
175
- self . send_command_succeeded_event ( command_succeeded_event) ;
167
+ self . emit_command_event ( |handler| {
168
+ let should_redact =
169
+ REDACTED_COMMANDS . contains ( cmd. name . to_lowercase ( ) . as_str ( ) ) ;
170
+
171
+ let reply = if should_redact {
172
+ Document :: new ( )
173
+ } else {
174
+ response. raw_response . clone ( )
175
+ } ;
176
+
177
+ let command_succeeded_event = CommandSucceededEvent {
178
+ duration,
179
+ reply,
180
+ command_name : cmd. name . clone ( ) ,
181
+ request_id,
182
+ connection : connection_info,
183
+ } ;
184
+ handler. handle_command_succeeded_event ( command_succeeded_event) ;
185
+ } ) ;
176
186
op. handle_response ( response)
177
187
}
178
188
}
0 commit comments