Skip to content

Commit 26fc252

Browse files
committed
chore(data-service): add a log whenever connecting throws and include connection id
1 parent 825aeef commit 26fc252

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
15801580
this._isConnecting = true;
15811581

15821582
this._logger.info(mongoLogId(1_001_000_014), 'Connecting', {
1583+
connectionId: this._id,
15831584
url: redactConnectionString(this._connectionOptions.connectionString),
15841585
csfle: this._csfleLogInformation(this._connectionOptions.fleOptions),
15851586
});
@@ -1599,11 +1600,16 @@ class DataServiceImpl extends WithLogContext implements DataService {
15991600
});
16001601

16011602
const attr = {
1603+
connectionId: this._id,
16021604
isWritable: this.isWritable(),
16031605
isMongos: this.isMongos(),
16041606
};
16051607

1606-
this._logger.info(mongoLogId(1_001_000_015), 'Connected', attr);
1608+
this._logger.info(
1609+
mongoLogId(1_001_000_015),
1610+
'Connecting Succeeded',
1611+
attr
1612+
);
16071613
debug('connected!', attr);
16081614

16091615
state.oidcPlugin.logger.on('mongodb-oidc-plugin:state-updated', () => {
@@ -1626,6 +1632,15 @@ class DataServiceImpl extends WithLogContext implements DataService {
16261632
this,
16271633
this._crudClient
16281634
);
1635+
} catch (error) {
1636+
this._logger.info(mongoLogId(1_001_000_359), 'Connecting Error', {
1637+
connectionId: this._id,
1638+
error:
1639+
error && typeof error === 'object' && 'message' in error
1640+
? error?.message
1641+
: 'unknown error',
1642+
});
1643+
throw error;
16291644
} finally {
16301645
this._isConnecting = false;
16311646
}

0 commit comments

Comments
 (0)