Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cli-repl/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli-repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"analytics-node": "^3.4.0-beta.1",
"ansi-escape-sequences": "^5.1.2",
"bson": "^4.0.4",
"fast-json-parse": "^1.0.3",
"is-recoverable-error": "^1.0.0",
"lodash.set": "^4.3.2",
"minimist": "^1.2.5",
Expand Down
23 changes: 16 additions & 7 deletions packages/cli-repl/src/cli-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

import { CliServiceProvider, NodeOptions } from '@mongosh/service-provider-server';
import formatOutput, { formatError } from './format-output';
import { LineByLineInput } from './line-by-line-input';
import { TELEMETRY, MONGOSH_WIKI } from './constants';
import ShellEvaluator from '@mongosh/shell-evaluator';
import isRecoverableError from 'is-recoverable-error';
import { MongoshWarning } from '@mongosh/errors';
import { changeHistory } from '@mongosh/history';
import { REPLServer, Recoverable } from 'repl';
import getConnectInfo from './connect-info';
import { TELEMETRY, MONGOSH_WIKI } from './constants';
import jsonParse from 'fast-json-parse';
import CliOptions from './cli-options';
import completer from './completer';
import i18n from '@mongosh/i18n';
import { ObjectId } from 'bson';
import repl from 'pretty-repl';
import Nanobus from 'nanobus';
import { redactPwd } from '.';
import logger from './logger';
import mkdirp from 'mkdirp';
import clr from './clr';
Expand All @@ -23,8 +26,6 @@ import util from 'util';
import read from 'read';
import os from 'os';
import fs from 'fs';
import { redactPwd } from '.';
import { LineByLineInput } from './line-by-line-input';

/**
* Connecting text key.
Expand Down Expand Up @@ -243,17 +244,25 @@ class CliRepl {

try {
fd = fs.openSync(configPath, 'wx');
this.userId = new ObjectId(Date.now());
this.userId = new ObjectId(Date.now()).toString();
this.enableTelemetry = true;
this.disableGreetingMessage = false;
this.bus.emit('mongosh:new-user', this.userId, this.enableTelemetry);
this.writeConfigFileSync(configPath);
} catch (err) {
if (err.code === 'EEXIST') {
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
this.userId = config.userId;
// make sure we catch errors for json parse and always have err and
// value on config result
const config = jsonParse(fs.readFileSync(configPath, 'utf8'));

if (config.err) {
this.bus.emit('mongosh:error', 'Unable to parse user config', err);
return;
}

this.userId = config.value.userId;
this.disableGreetingMessage = true;
this.enableTelemetry = config.enableTelemetry;
this.enableTelemetry = config.value.enableTelemetry;
this.bus.emit('mongosh:update-user', this.userId, this.enableTelemetry);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-repl/src/connect-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('getConnectInfo', function() {
is_genuine: true,
non_genuine_server_name: 'mongodb',
server_arch: 'x86_64',
node_version: process.version,
server_os: 'osx',
uri: ATLAS_URI
};
Expand All @@ -107,6 +108,7 @@ describe('getConnectInfo', function() {
is_genuine: true,
non_genuine_server_name: 'mongodb',
server_arch: 'x86_64',
node_version: process.version,
server_os: 'osx',
uri: ATLAS_URI
};
Expand Down
2 changes: 2 additions & 0 deletions packages/cli-repl/src/connect-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ConnectInfo {
dl_version?: string;
is_genuine: boolean;
non_genuine_server_name: string;
node_version: string;
uri: string;
}

Expand Down Expand Up @@ -42,6 +43,7 @@ export default function getConnectInfo(uri: string, buildInfo: any, cmdLineOpts:
auth_type,
is_data_lake,
dl_version,
node_version: process.version,
is_genuine,
non_genuine_server_name
};
Expand Down
5 changes: 3 additions & 2 deletions packages/cli-repl/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ConnectEvent {
dl_version?: string;
is_genuine: boolean;
non_genuine_server_name: string;
node_version: string;
uri: string;
}

Expand All @@ -57,7 +58,7 @@ NoopAnalytics.prototype.identify = function(): void {};
NoopAnalytics.prototype.track = function(): void {};

export default function logger(bus: any, logDir: string): void {
const session_id = new ObjectId(Date.now());
const session_id = new ObjectId(Date.now()).toString();
const logDest = path.join(logDir, `${session_id}_log`);
const log = pino({ name: 'monogsh' }, pino.destination(logDest));
console.log(`Current sessionID: ${session_id}`);
Expand All @@ -67,7 +68,6 @@ export default function logger(bus: any, logDir: string): void {
let analytics = new NoopAnalytics();
try {
// this file gets written as a part of a release
log.warn(require('./analytics-config.js').SEGMENT_API_KEY);
analytics = new Analytics(require('./analytics-config.js').SEGMENT_API_KEY);
} catch (e) {
bus.emit('mongosh:error', e);
Expand Down Expand Up @@ -97,6 +97,7 @@ export default function logger(bus: any, logDir: string): void {
bus.on('mongosh:update-user', function(id, enableTelemetry) {
userId = id;
telemetry = enableTelemetry;
if (telemetry) analytics.identify({ userId });
log.info('mongosh:update-user', { enableTelemetry });
});

Expand Down
6 changes: 3 additions & 3 deletions packages/java-shell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.