Skip to content

Commit dfc252e

Browse files
authored
adjust telemetry names for connect event (#181)
* adjust telemetry names for connect event * Title Case all analytics events
1 parent e93faf0 commit dfc252e

File tree

5 files changed

+81
-64
lines changed

5 files changed

+81
-64
lines changed

packages/cli-repl/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-repl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"minimist": "^1.2.5",
5353
"mkdirp": "^1.0.3",
5454
"mongodb-ace-autocompleter": "^0.4.1",
55-
"mongodb-build-info": "^1.0.0",
55+
"mongodb-build-info": "^1.1.0",
5656
"mongodb-redact": "^0.2.0",
5757
"nanobus": "^4.4.0",
5858
"pino": "^5.16.0",

packages/cli-repl/src/connect-info.spec.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint camelcase: 0, @typescript-eslint/camelcase: 0 */
12
import { expect } from 'chai';
23
import getConnectInfo from './connect-info';
34

@@ -74,15 +75,17 @@ describe('getConnectInfo', function() {
7475

7576
it('reports on an enterprise version >=3.2 of mongodb with credentials', function() {
7677
const output = {
77-
isAtlas: true,
78-
isLocalhost: false,
79-
serverVersion: '3.2.0-rc2',
80-
isEnterprise: true,
81-
authType: 'LDAP',
82-
isDataLake: false,
83-
dlVersion: null,
84-
isGenuine: true,
85-
serverName: 'mongodb',
78+
is_atlas: true,
79+
is_localhost: false,
80+
server_version: '3.2.0-rc2',
81+
is_enterprise: true,
82+
auth_type: 'LDAP',
83+
is_data_lake: false,
84+
dl_version: null,
85+
is_genuine: true,
86+
non_genuine_server_name: 'mongodb',
87+
server_arch: 'x86_64',
88+
server_os: 'osx',
8689
uri: ATLAS_URI
8790
};
8891
expect(getConnectInfo(
@@ -94,15 +97,17 @@ describe('getConnectInfo', function() {
9497

9598
it('reports on an enterprise version >=3.2 of mongodb with no credentials', function() {
9699
const output = {
97-
isAtlas: true,
98-
isLocalhost: false,
99-
serverVersion: '3.2.0-rc2',
100-
isEnterprise: true,
101-
authType: null,
102-
isDataLake: false,
103-
dlVersion: null,
104-
isGenuine: true,
105-
serverName: 'mongodb',
100+
is_atlas: true,
101+
is_localhost: false,
102+
server_version: '3.2.0-rc2',
103+
is_enterprise: true,
104+
auth_type: null,
105+
is_data_lake: false,
106+
dl_version: null,
107+
is_genuine: true,
108+
non_genuine_server_name: 'mongodb',
109+
server_arch: 'x86_64',
110+
server_os: 'osx',
106111
uri: ATLAS_URI
107112
};
108113
expect(getConnectInfo(
Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
1+
/* eslint camelcase: 0, @typescript-eslint/camelcase: 0 */
2+
// ^ segment data is in snake_case: forgive me javascript, for i have sinned.
3+
14
import getBuildInfo from 'mongodb-build-info';
25

36
interface ConnectInfo {
4-
isAtlas: boolean;
5-
isLocalhost: boolean;
6-
serverVersion: string;
7-
isEnterprise: boolean;
7+
is_atlas: boolean;
8+
is_localhost: boolean;
9+
server_version: string;
10+
server_os?: string;
11+
server_arch?: string;
12+
is_enterprise: boolean;
13+
auth_type?: string;
14+
is_data_lake: boolean;
15+
dl_version?: string;
16+
is_genuine: boolean;
17+
non_genuine_server_name: string;
818
uri: string;
9-
authType?: string;
10-
isDataLake: boolean;
11-
dlVersion?: string;
12-
isGenuine: boolean;
13-
serverName: string;
1419
}
1520

1621
export default function getConnectInfo(uri: string, buildInfo: any, cmdLineOpts: any, topology: any): ConnectInfo {
17-
const { isGenuine, serverName } =
22+
const { isGenuine: is_genuine, serverName: non_genuine_server_name } =
1823
getBuildInfo.getGenuineMongoDB(buildInfo, cmdLineOpts);
19-
const { isDataLake, dlVersion } = getBuildInfo.getDataLake(buildInfo);
24+
const { isDataLake: is_data_lake, dlVersion: dl_version }
25+
= getBuildInfo.getDataLake(buildInfo);
2026

2127
// get this information from topology rather than cmdLineOpts, since not all
2228
// connections are able to run getCmdLineOpts command
23-
const authType = topology.s.credentials
29+
const auth_type = topology.s.credentials
2430
? topology.s.credentials.mechanism : null;
31+
const { serverOs: server_os, serverArch: server_arch }
32+
= getBuildInfo.getBuildEnv(buildInfo);
2533

2634
return {
27-
isAtlas: getBuildInfo.isAtlas(uri),
28-
isLocalhost: getBuildInfo.isLocalhost(uri),
29-
serverVersion: buildInfo.version,
30-
isEnterprise: getBuildInfo.isEnterprise(buildInfo),
35+
is_atlas: getBuildInfo.isAtlas(uri),
36+
is_localhost: getBuildInfo.isLocalhost(uri),
37+
server_version: buildInfo.version,
38+
server_os,
3139
uri,
32-
authType,
33-
isDataLake,
34-
dlVersion,
35-
isGenuine,
36-
serverName
40+
server_arch,
41+
is_enterprise: getBuildInfo.isEnterprise(buildInfo),
42+
auth_type,
43+
is_data_lake,
44+
dl_version,
45+
is_genuine,
46+
non_genuine_server_name
3747
};
3848
}

packages/cli-repl/src/logger.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint no-console:0, no-empty-function: 0 */
1+
/* eslint no-console: 0, no-empty-function: 0, camelcase: 0, @typescript-eslint/camelcase: 0 */
22

33
import redactInfo from 'mongodb-redact';
44
import Analytics from 'analytics-node';
@@ -36,16 +36,18 @@ interface ShowEvent {
3636
}
3737

3838
interface ConnectEvent {
39+
is_atlas: boolean;
40+
is_localhost: boolean;
41+
server_version: string;
42+
server_os?: string;
43+
server_arch?: string;
44+
is_enterprise: boolean;
45+
auth_type?: string;
46+
is_data_lake: boolean;
47+
dl_version?: string;
48+
is_genuine: boolean;
49+
non_genuine_server_name: string;
3950
uri: string;
40-
isAtlas: boolean;
41-
isLocalhost: boolean;
42-
serverVersion: string;
43-
isEnterprise: boolean;
44-
authType: string;
45-
isDataLake: boolean;
46-
dlVersion?: string;
47-
isGenuine: boolean;
48-
serverName: string;
4951
}
5052

5153
// set up a noop, in case we are not able to connect to segment.
@@ -55,10 +57,10 @@ NoopAnalytics.prototype.identify = function(): void {};
5557
NoopAnalytics.prototype.track = function(): void {};
5658

5759
export default function logger(bus: any, logDir: string): void {
58-
const sessionID = new ObjectId(Date.now());
59-
const logDest = path.join(logDir, `${sessionID}_log`);
60+
const session_id = new ObjectId(Date.now());
61+
const logDest = path.join(logDir, `${session_id}_log`);
6062
const log = pino({ name: 'monogsh' }, pino.destination(logDest));
61-
console.log(`Current sessionID: ${sessionID}`);
63+
console.log(`Current sessionID: ${session_id}`);
6264
let userId;
6365
let telemetry;
6466

@@ -74,14 +76,14 @@ export default function logger(bus: any, logDir: string): void {
7476
bus.on('mongosh:connect', function(args: ConnectEvent) {
7577
const connectionUri = redactPwd(args.uri);
7678
delete args.uri;
77-
const params = { sessionID, userId, connectionUri, ...args };
79+
const params = { session_id, userId, connectionUri, ...args };
7880
log.info('mongosh:connect', params);
7981

8082
if (telemetry) {
8183
analytics.track({
8284
userId,
83-
event: 'mongosh:connect',
84-
properties: { sessionID, connectionUri, ...args }
85+
event: 'New Connection',
86+
properties: { session_id, ...args }
8587
});
8688
}
8789
});
@@ -105,7 +107,7 @@ export default function logger(bus: any, logDir: string): void {
105107
if (telemetry && error.name.includes('Mongosh')) {
106108
analytics.track({
107109
userId,
108-
event: 'mongosh:error',
110+
event: 'Error',
109111
properties: { error }
110112
});
111113
}
@@ -117,7 +119,7 @@ export default function logger(bus: any, logDir: string): void {
117119
if (telemetry) {
118120
analytics.track({
119121
userId,
120-
event: 'mongosh:help'
122+
event: 'Help'
121123
});
122124
}
123125
});
@@ -132,7 +134,7 @@ export default function logger(bus: any, logDir: string): void {
132134
if (telemetry) {
133135
analytics.track({
134136
userId,
135-
event: 'mongosh:use'
137+
event: 'Use'
136138
});
137139
}
138140
});
@@ -143,7 +145,7 @@ export default function logger(bus: any, logDir: string): void {
143145
if (telemetry) {
144146
analytics.track({
145147
userId,
146-
event: 'mongosh:show',
148+
event: 'Show',
147149
properties: { method: args.method }
148150
});
149151
}
@@ -166,7 +168,7 @@ export default function logger(bus: any, logDir: string): void {
166168
if (telemetry) {
167169
analytics.track({
168170
userId,
169-
event: 'mongosh:api-call',
171+
event: 'Api Call',
170172
properties: redactInfo(properties)
171173
});
172174
}

0 commit comments

Comments
 (0)