Skip to content

Commit f039277

Browse files
committed
add events
1 parent d952737 commit f039277

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

packages/compass-connections/src/stores/connections-store-redux.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,11 @@ const connectWithOptions = (
15811581
mongoLogId(1_001_000_004),
15821582
'Connection UI',
15831583
'Initiating connection attempt',
1584-
{ isAutoconnectAttempt }
1584+
{
1585+
isAutoconnectAttempt,
1586+
clusterName: connectionInfo.atlasMetadata?.clusterName,
1587+
connectionId: connectionInfo.id,
1588+
}
15851589
);
15861590

15871591
// Connection form allows to start connecting with invalid connection
@@ -1821,6 +1825,16 @@ const connectWithOptions = (
18211825
connectionInfo
18221826
);
18231827

1828+
log.info(
1829+
mongoLogId(1_001_000_006),
1830+
'Compass Connection Attempt Succeeded',
1831+
'Connection attempt succeeded',
1832+
{
1833+
clusterName: connectionInfo.atlasMetadata?.clusterName,
1834+
connectionId: connectionInfo.id,
1835+
}
1836+
);
1837+
18241838
connectionProgress.openConnectionSucceededToast(connectionInfo);
18251839

18261840
// Emit before changing state because some plugins rely on this

packages/data-service/src/data-service.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import type {
5353
ClientEncryptionCreateDataKeyProviderOptions,
5454
SearchIndexDescription,
5555
ReadPreferenceMode,
56+
CommandStartedEvent,
57+
ConnectionCreatedEvent,
5658
} from 'mongodb';
5759
import { ReadPreference } from 'mongodb';
5860
import ConnectionStringUrl from 'mongodb-connection-string-url';
@@ -1605,6 +1607,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
16051607
this._isConnecting = true;
16061608

16071609
this._logger.info(mongoLogId(1_001_000_014), 'Connecting Started', {
1610+
clusterName: this._connectionOptions.lookup?.().clusterName,
16081611
connectionId: this._id,
16091612
url: redactConnectionString(this._connectionOptions.connectionString),
16101613
csfle: this._csfleLogInformation(this._connectionOptions.fleOptions),
@@ -1626,6 +1629,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
16261629

16271630
const attr = {
16281631
connectionId: this._id,
1632+
clusterName: this._connectionOptions.lookup?.().clusterName,
16291633
isWritable: this.isWritable(),
16301634
isMongos: this.isMongos(),
16311635
};
@@ -1660,6 +1664,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
16601664
} catch (error) {
16611665
this._logger.info(mongoLogId(1_001_000_359), 'Connecting Failed', {
16621666
connectionId: this._id,
1667+
clusterName: this._connectionOptions.lookup?.().clusterName,
16631668
error:
16641669
error && typeof error === 'object' && 'message' in error
16651670
? error?.message
@@ -2474,6 +2479,18 @@ class DataServiceImpl extends WithLogContext implements DataService {
24742479

24752480
private _setupListeners(client: MongoClient): void {
24762481
if (client) {
2482+
client.on('connectionCreated', (evt: ConnectionCreatedEvent) => {
2483+
const { address, connectionId } = evt;
2484+
this._logger.info(
2485+
mongoLogId(1_001_000_027),
2486+
'Driver connection created',
2487+
{
2488+
address,
2489+
serverConnectionId: connectionId,
2490+
}
2491+
);
2492+
});
2493+
24772494
client.on(
24782495
'serverDescriptionChanged',
24792496
(evt: ServerDescriptionChangedEvent) => {
@@ -2595,13 +2612,30 @@ class DataServiceImpl extends WithLogContext implements DataService {
25952612
this._emitter.emit('serverHeartbeatFailed', evt);
25962613
});
25972614

2615+
client.on('commandStarted', (evt: CommandStartedEvent) => {
2616+
const { address, connectionId, requestId, commandName, databaseName } =
2617+
evt;
2618+
this._logger.debug(
2619+
mongoLogId(1_001_000_028),
2620+
'Driver command started',
2621+
{
2622+
address,
2623+
databaseName,
2624+
serverConnectionId: connectionId,
2625+
requestId,
2626+
commandName,
2627+
}
2628+
);
2629+
});
2630+
25982631
client.on('commandSucceeded', (evt: CommandSucceededEvent) => {
2599-
const { address, connectionId, duration, commandName } = evt;
2632+
const { address, connectionId, duration, requestId, commandName } = evt;
26002633
this._logger.debug(
26012634
mongoLogId(1_001_000_029),
26022635
'Driver command succeeded',
26032636
{
26042637
address,
2638+
requestId,
26052639
serverConnectionId: connectionId,
26062640
duration,
26072641
commandName,
@@ -2610,11 +2644,19 @@ class DataServiceImpl extends WithLogContext implements DataService {
26102644
});
26112645

26122646
client.on('commandFailed', (evt: CommandFailedEvent) => {
2613-
const { address, connectionId, duration, commandName, failure } = evt;
2647+
const {
2648+
address,
2649+
connectionId,
2650+
duration,
2651+
requestId,
2652+
commandName,
2653+
failure,
2654+
} = evt;
26142655
this._logger.debug(mongoLogId(1_001_000_030), 'Driver command failed', {
26152656
address,
26162657
serverConnectionId: connectionId,
26172658
duration,
2659+
requestId,
26182660
commandName,
26192661
failure: failure.message,
26202662
});

0 commit comments

Comments
 (0)