1
- import type { Document , ObjectId } from '../bson' ;
1
+ import { type Document , type ObjectId } from '../bson' ;
2
2
import {
3
3
COMMAND_FAILED ,
4
4
COMMAND_STARTED ,
@@ -22,7 +22,14 @@ export class CommandStartedEvent {
22
22
commandName : string ;
23
23
command : Document ;
24
24
address : string ;
25
+ /** Driver generated connection id */
25
26
connectionId ?: string | number ;
27
+ /**
28
+ * Server generated connection id
29
+ * Distinct from the connection id and is returned by the hello or legacy hello response as "connectionId"
30
+ * from the server on 4.2+.
31
+ */
32
+ serverConnectionId : bigint | null ;
26
33
serviceId ?: ObjectId ;
27
34
/** @internal */
28
35
name = COMMAND_STARTED ;
@@ -34,7 +41,11 @@ export class CommandStartedEvent {
34
41
* @param pool - the pool that originated the command
35
42
* @param command - the command
36
43
*/
37
- constructor ( connection : Connection , command : WriteProtocolMessageType ) {
44
+ constructor (
45
+ connection : Connection ,
46
+ command : WriteProtocolMessageType ,
47
+ serverConnectionId : bigint | null
48
+ ) {
38
49
const cmd = extractCommand ( command ) ;
39
50
const commandName = extractCommandName ( cmd ) ;
40
51
const { address, connectionId, serviceId } = extractConnectionDetails ( connection ) ;
@@ -52,6 +63,7 @@ export class CommandStartedEvent {
52
63
this . databaseName = command . databaseName ;
53
64
this . commandName = commandName ;
54
65
this . command = maybeRedact ( commandName , cmd , cmd ) ;
66
+ this . serverConnectionId = serverConnectionId ;
55
67
}
56
68
57
69
/* @internal */
@@ -67,7 +79,13 @@ export class CommandStartedEvent {
67
79
*/
68
80
export class CommandSucceededEvent {
69
81
address : string ;
82
+ /** Driver generated connection id */
70
83
connectionId ?: string | number ;
84
+ /**
85
+ * Server generated connection id
86
+ * Distinct from the connection id and is returned by the hello or legacy hello response as "connectionId" from the server on 4.2+.
87
+ */
88
+ serverConnectionId : bigint | null ;
71
89
requestId : number ;
72
90
duration : number ;
73
91
commandName : string ;
@@ -89,7 +107,8 @@ export class CommandSucceededEvent {
89
107
connection : Connection ,
90
108
command : WriteProtocolMessageType ,
91
109
reply : Document | undefined ,
92
- started : number
110
+ started : number ,
111
+ serverConnectionId : bigint | null
93
112
) {
94
113
const cmd = extractCommand ( command ) ;
95
114
const commandName = extractCommandName ( cmd ) ;
@@ -102,6 +121,7 @@ export class CommandSucceededEvent {
102
121
this . commandName = commandName ;
103
122
this . duration = calculateDurationInMs ( started ) ;
104
123
this . reply = maybeRedact ( commandName , cmd , extractReply ( command , reply ) ) ;
124
+ this . serverConnectionId = serverConnectionId ;
105
125
}
106
126
107
127
/* @internal */
@@ -117,7 +137,13 @@ export class CommandSucceededEvent {
117
137
*/
118
138
export class CommandFailedEvent {
119
139
address : string ;
140
+ /** Driver generated connection id */
120
141
connectionId ?: string | number ;
142
+ /**
143
+ * Server generated connection id
144
+ * Distinct from the connection id and is returned by the hello or legacy hello response as "connectionId" from the server on 4.2+.
145
+ */
146
+ serverConnectionId : bigint | null ;
121
147
requestId : number ;
122
148
duration : number ;
123
149
commandName : string ;
@@ -139,7 +165,8 @@ export class CommandFailedEvent {
139
165
connection : Connection ,
140
166
command : WriteProtocolMessageType ,
141
167
error : Error | Document ,
142
- started : number
168
+ started : number ,
169
+ serverConnectionId : bigint | null
143
170
) {
144
171
const cmd = extractCommand ( command ) ;
145
172
const commandName = extractCommandName ( cmd ) ;
@@ -153,6 +180,7 @@ export class CommandFailedEvent {
153
180
this . commandName = commandName ;
154
181
this . duration = calculateDurationInMs ( started ) ;
155
182
this . failure = maybeRedact ( commandName , cmd , error ) as Error ;
183
+ this . serverConnectionId = serverConnectionId ;
156
184
}
157
185
158
186
/* @internal */
0 commit comments