@@ -52,7 +52,7 @@ export class CommandStartedEvent {
5252 serverConnectionId : bigint | null
5353 ) {
5454 const cmd = extractCommand ( command ) ;
55- const commandName = extractCommandName ( cmd ) ;
55+ const commandName = extractCommandName ( command ) ;
5656 const { address, connectionId, serviceId } = extractConnectionDetails ( connection ) ;
5757
5858 // TODO: remove in major revision, this is not spec behavior
@@ -116,7 +116,7 @@ export class CommandSucceededEvent {
116116 serverConnectionId : bigint | null
117117 ) {
118118 const cmd = extractCommand ( command ) ;
119- const commandName = extractCommandName ( cmd ) ;
119+ const commandName = extractCommandName ( command ) ;
120120 const { address, connectionId, serviceId } = extractConnectionDetails ( connection ) ;
121121
122122 this . address = address ;
@@ -174,7 +174,7 @@ export class CommandFailedEvent {
174174 serverConnectionId : bigint | null
175175 ) {
176176 const cmd = extractCommand ( command ) ;
177- const commandName = extractCommandName ( cmd ) ;
177+ const commandName = extractCommandName ( command ) ;
178178 const { address, connectionId, serviceId } = extractConnectionDetails ( connection ) ;
179179
180180 this . address = address ;
@@ -213,7 +213,14 @@ export const SENSITIVE_COMMANDS = new Set([
213213const HELLO_COMMANDS = new Set ( [ 'hello' , LEGACY_HELLO_COMMAND , LEGACY_HELLO_COMMAND_CAMEL_CASE ] ) ;
214214
215215// helper methods
216- const extractCommandName = ( commandDoc : Document ) => Object . keys ( commandDoc ) [ 0 ] ;
216+ const extractCommandName = ( commandDoc : Document ) => {
217+ if ( commandDoc . query != null ) {
218+ if ( commandDoc . query . $query != null ) return Object . keys ( commandDoc . query . $query ) [ 0 ] ;
219+ return Object . keys ( commandDoc . query ) [ 0 ] ;
220+ }
221+ if ( commandDoc . command != null ) return Object . keys ( commandDoc . command ) [ 0 ] ;
222+ return Object . keys ( commandDoc ) [ 0 ] ;
223+ } ;
217224const namespace = ( command : OpQueryRequest ) => command . ns ;
218225const collectionName = ( command : OpQueryRequest ) => command . ns . split ( '.' ) [ 1 ] ;
219226const maybeRedact = ( commandName : string , commandDoc : Document , result : Error | Document ) =>
0 commit comments