@mongosh/logging 3.0.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +1 -0
- package/lib/analytics-helpers.d.ts +1 -1
- package/lib/helpers.d.ts +7 -0
- package/lib/helpers.js +31 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/logging-and-telemetry.d.ts +2 -0
- package/lib/logging-and-telemetry.js +429 -0
- package/lib/logging-and-telemetry.js.map +1 -0
- package/lib/types.d.ts +33 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +6 -6
- package/src/analytics-helpers.ts +1 -1
- package/src/helpers.spec.ts +26 -0
- package/src/helpers.ts +49 -0
- package/src/index.ts +2 -1
- package/src/{setup-logger-and-telemetry.spec.ts → logging-and-telemetry.spec.ts} +298 -84
- package/src/logging-and-telemetry.ts +871 -0
- package/src/types.ts +35 -0
- package/lib/setup-logger-and-telemetry.d.ts +0 -5
- package/lib/setup-logger-and-telemetry.js +0 -361
- package/lib/setup-logger-and-telemetry.js.map +0 -1
- package/src/setup-logger-and-telemetry.ts +0 -783
|
@@ -1,35 +1,14 @@
|
|
|
1
1
|
/* eslint-disable mocha/max-top-level-suites */
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
import { MongoLogWriter } from 'mongodb-log-writer';
|
|
4
|
-
import { setupLoggerAndTelemetry } from './';
|
|
5
4
|
import { EventEmitter } from 'events';
|
|
6
5
|
import { MongoshInvalidInputError } from '@mongosh/errors';
|
|
7
6
|
import type { MongoshBus } from '@mongosh/types';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const useCases = [
|
|
12
|
-
{ input: 'MongoDB REPL', output: 'mongo_db_repl' },
|
|
13
|
-
{
|
|
14
|
-
input: 'Node.js REPL Instantiation',
|
|
15
|
-
output: 'node_js_repl_instantiation',
|
|
16
|
-
},
|
|
17
|
-
{ input: 'A', output: 'a' },
|
|
18
|
-
{
|
|
19
|
-
input: 'OneLongThingInPascalCase',
|
|
20
|
-
output: 'one_long_thing_in_pascal_case',
|
|
21
|
-
},
|
|
22
|
-
{ input: 'Removes .Dots in Node.js', output: 'removes_dots_in_node_js' },
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
for (const { input, output } of useCases) {
|
|
26
|
-
it(`should convert ${input} to ${output}`, function () {
|
|
27
|
-
expect(toSnakeCase(input)).to.equal(output);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
7
|
+
import type { Writable } from 'stream';
|
|
8
|
+
import type { MongoshLoggingAndTelemetry } from '.';
|
|
9
|
+
import { setupLoggingAndTelemetry } from '.';
|
|
31
10
|
|
|
32
|
-
describe('
|
|
11
|
+
describe('MongoshLoggingAndTelemetry', function () {
|
|
33
12
|
let logOutput: any[];
|
|
34
13
|
let analyticsOutput: ['identify' | 'track' | 'log', any][];
|
|
35
14
|
let bus: MongoshBus;
|
|
@@ -37,15 +16,8 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
37
16
|
const userId = '53defe995fa47e6c13102d9d';
|
|
38
17
|
const logId = '5fb3c20ee1507e894e5340f3';
|
|
39
18
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
logOutput.push(JSON.parse(chunk));
|
|
43
|
-
cb();
|
|
44
|
-
},
|
|
45
|
-
end(cb: () => void) {
|
|
46
|
-
cb();
|
|
47
|
-
},
|
|
48
|
-
} as any);
|
|
19
|
+
let logger: MongoLogWriter;
|
|
20
|
+
|
|
49
21
|
const analytics = {
|
|
50
22
|
identify(info: any) {
|
|
51
23
|
analyticsOutput.push(['identify', info]);
|
|
@@ -58,26 +30,61 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
58
30
|
},
|
|
59
31
|
};
|
|
60
32
|
|
|
33
|
+
let loggingAndTelemetry: MongoshLoggingAndTelemetry;
|
|
34
|
+
|
|
61
35
|
beforeEach(function () {
|
|
62
36
|
logOutput = [];
|
|
63
37
|
analyticsOutput = [];
|
|
64
38
|
bus = new EventEmitter();
|
|
65
|
-
});
|
|
66
39
|
|
|
67
|
-
|
|
68
|
-
setupLoggerAndTelemetry(
|
|
40
|
+
loggingAndTelemetry = setupLoggingAndTelemetry({
|
|
69
41
|
bus,
|
|
70
|
-
logger,
|
|
71
42
|
analytics,
|
|
72
|
-
{
|
|
43
|
+
userTraits: {
|
|
73
44
|
platform: process.platform,
|
|
74
45
|
arch: process.arch,
|
|
75
46
|
},
|
|
76
|
-
'1.0.0'
|
|
47
|
+
mongoshVersion: '1.0.0',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
logger = new MongoLogWriter(logId, `/tmp/${logId}_log`, {
|
|
51
|
+
write(chunk: string, cb: () => void) {
|
|
52
|
+
logOutput.push(JSON.parse(chunk));
|
|
53
|
+
cb();
|
|
54
|
+
},
|
|
55
|
+
end(cb: () => void) {
|
|
56
|
+
cb();
|
|
57
|
+
},
|
|
58
|
+
} as Writable);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(function () {
|
|
62
|
+
loggingAndTelemetry.detachLogger();
|
|
63
|
+
logger.destroy();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('throws when running attachLogger twice without detaching', function () {
|
|
67
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
68
|
+
expect(() => loggingAndTelemetry.attachLogger(logger)).throws(
|
|
69
|
+
'Previously set logger has not been detached. Run detachLogger() before setting.'
|
|
77
70
|
);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('does not throw when attaching and detaching loggers', function () {
|
|
74
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
75
|
+
loggingAndTelemetry.detachLogger();
|
|
76
|
+
expect(() => loggingAndTelemetry.attachLogger(logger)).does.not.throw();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('tracks new local connection events', function () {
|
|
80
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
81
|
+
|
|
78
82
|
expect(logOutput).to.have.lengthOf(0);
|
|
79
83
|
expect(analyticsOutput).to.be.empty;
|
|
80
84
|
|
|
85
|
+
bus.emit('mongosh:new-user', { userId, anonymousId: userId });
|
|
86
|
+
bus.emit('mongosh:log-initialized');
|
|
87
|
+
|
|
81
88
|
bus.emit('mongosh:connect', {
|
|
82
89
|
uri: 'mongodb://localhost/',
|
|
83
90
|
is_localhost: true,
|
|
@@ -94,14 +101,25 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
94
101
|
expect(logOutput[0].attr.node_version).to.equal('v12.19.0');
|
|
95
102
|
|
|
96
103
|
expect(analyticsOutput).to.deep.equal([
|
|
104
|
+
[
|
|
105
|
+
'identify',
|
|
106
|
+
{
|
|
107
|
+
anonymousId: userId,
|
|
108
|
+
traits: {
|
|
109
|
+
arch: process.arch,
|
|
110
|
+
platform: process.platform,
|
|
111
|
+
session_id: logId,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
97
115
|
[
|
|
98
116
|
'track',
|
|
99
117
|
{
|
|
100
|
-
anonymousId:
|
|
118
|
+
anonymousId: userId,
|
|
101
119
|
event: 'New Connection',
|
|
102
120
|
properties: {
|
|
103
121
|
mongosh_version: '1.0.0',
|
|
104
|
-
session_id:
|
|
122
|
+
session_id: logId,
|
|
105
123
|
is_localhost: true,
|
|
106
124
|
is_atlas: false,
|
|
107
125
|
atlas_hostname: null,
|
|
@@ -113,19 +131,14 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
113
131
|
});
|
|
114
132
|
|
|
115
133
|
it('tracks new atlas connection events', function () {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
logger,
|
|
119
|
-
analytics,
|
|
120
|
-
{
|
|
121
|
-
platform: process.platform,
|
|
122
|
-
arch: process.arch,
|
|
123
|
-
},
|
|
124
|
-
'1.0.0'
|
|
125
|
-
);
|
|
134
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
135
|
+
|
|
126
136
|
expect(logOutput).to.have.lengthOf(0);
|
|
127
137
|
expect(analyticsOutput).to.be.empty;
|
|
128
138
|
|
|
139
|
+
bus.emit('mongosh:new-user', { userId, anonymousId: userId });
|
|
140
|
+
bus.emit('mongosh:log-initialized');
|
|
141
|
+
|
|
129
142
|
bus.emit('mongosh:connect', {
|
|
130
143
|
uri: 'mongodb://test-data-sets-a011bb.mongodb.net/',
|
|
131
144
|
is_localhost: false,
|
|
@@ -146,14 +159,25 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
146
159
|
expect(logOutput[0].attr.node_version).to.equal('v12.19.0');
|
|
147
160
|
|
|
148
161
|
expect(analyticsOutput).to.deep.equal([
|
|
162
|
+
[
|
|
163
|
+
'identify',
|
|
164
|
+
{
|
|
165
|
+
anonymousId: userId,
|
|
166
|
+
traits: {
|
|
167
|
+
arch: process.arch,
|
|
168
|
+
platform: process.platform,
|
|
169
|
+
session_id: logId,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
149
173
|
[
|
|
150
174
|
'track',
|
|
151
175
|
{
|
|
152
|
-
anonymousId:
|
|
176
|
+
anonymousId: userId,
|
|
153
177
|
event: 'New Connection',
|
|
154
178
|
properties: {
|
|
155
179
|
mongosh_version: '1.0.0',
|
|
156
|
-
session_id:
|
|
180
|
+
session_id: logId,
|
|
157
181
|
is_localhost: false,
|
|
158
182
|
is_atlas: true,
|
|
159
183
|
atlas_hostname: 'test-data-sets-00-02-a011bb.mongodb.net',
|
|
@@ -164,21 +188,100 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
164
188
|
]);
|
|
165
189
|
});
|
|
166
190
|
|
|
191
|
+
it('detaching logger leads to no logging but persists analytics', function () {
|
|
192
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
193
|
+
|
|
194
|
+
expect(logOutput).to.have.lengthOf(0);
|
|
195
|
+
expect(analyticsOutput).to.have.lengthOf(0);
|
|
196
|
+
|
|
197
|
+
loggingAndTelemetry.detachLogger();
|
|
198
|
+
|
|
199
|
+
// This event has both analytics and logging
|
|
200
|
+
bus.emit('mongosh:use', { db: '' });
|
|
201
|
+
|
|
202
|
+
expect(logOutput).to.have.lengthOf(0);
|
|
203
|
+
expect(analyticsOutput).to.have.lengthOf(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('detaching logger applies to devtools-connect events', function () {
|
|
207
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
208
|
+
|
|
209
|
+
bus.emit('devtools-connect:connect-fail-early');
|
|
210
|
+
bus.emit('devtools-connect:connect-fail-early');
|
|
211
|
+
|
|
212
|
+
expect(logOutput).to.have.lengthOf(2);
|
|
213
|
+
// No analytics event attached to this
|
|
214
|
+
expect(analyticsOutput).to.have.lengthOf(0);
|
|
215
|
+
|
|
216
|
+
loggingAndTelemetry.detachLogger();
|
|
217
|
+
bus.emit('devtools-connect:connect-fail-early');
|
|
218
|
+
|
|
219
|
+
expect(logOutput).to.have.lengthOf(2);
|
|
220
|
+
expect(analyticsOutput).to.have.lengthOf(0);
|
|
221
|
+
|
|
222
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
223
|
+
|
|
224
|
+
bus.emit('devtools-connect:connect-fail-early');
|
|
225
|
+
bus.emit('devtools-connect:connect-fail-early');
|
|
226
|
+
expect(logOutput).to.have.lengthOf(4);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('detaching logger mid-way leads to no logging but persists analytics', function () {
|
|
230
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
231
|
+
|
|
232
|
+
expect(logOutput).to.have.lengthOf(0);
|
|
233
|
+
expect(analyticsOutput).to.have.lengthOf(0);
|
|
234
|
+
|
|
235
|
+
// This event has both analytics and logging
|
|
236
|
+
bus.emit('mongosh:use', { db: '' });
|
|
237
|
+
|
|
238
|
+
expect(logOutput).to.have.lengthOf(1);
|
|
239
|
+
expect(analyticsOutput).to.have.lengthOf(1);
|
|
240
|
+
|
|
241
|
+
loggingAndTelemetry.detachLogger();
|
|
242
|
+
|
|
243
|
+
bus.emit('mongosh:use', { db: '' });
|
|
244
|
+
|
|
245
|
+
expect(logOutput).to.have.lengthOf(1);
|
|
246
|
+
expect(analyticsOutput).to.have.lengthOf(2);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('detaching logger is recoverable', function () {
|
|
250
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
251
|
+
|
|
252
|
+
expect(logOutput).to.have.lengthOf(0);
|
|
253
|
+
expect(analyticsOutput).to.have.lengthOf(0);
|
|
254
|
+
|
|
255
|
+
// This event has both analytics and logging
|
|
256
|
+
bus.emit('mongosh:use', { db: '' });
|
|
257
|
+
|
|
258
|
+
expect(logOutput).to.have.lengthOf(1);
|
|
259
|
+
expect(analyticsOutput).to.have.lengthOf(1);
|
|
260
|
+
|
|
261
|
+
loggingAndTelemetry.detachLogger();
|
|
262
|
+
|
|
263
|
+
bus.emit('mongosh:use', { db: '' });
|
|
264
|
+
|
|
265
|
+
expect(logOutput).to.have.lengthOf(1);
|
|
266
|
+
expect(analyticsOutput).to.have.lengthOf(2);
|
|
267
|
+
|
|
268
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
269
|
+
|
|
270
|
+
bus.emit('mongosh:use', { db: '' });
|
|
271
|
+
|
|
272
|
+
expect(logOutput).to.have.lengthOf(2);
|
|
273
|
+
expect(analyticsOutput).to.have.lengthOf(3);
|
|
274
|
+
});
|
|
275
|
+
|
|
167
276
|
it('tracks a sequence of events', function () {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
logger,
|
|
171
|
-
analytics,
|
|
172
|
-
{
|
|
173
|
-
platform: process.platform,
|
|
174
|
-
arch: process.arch,
|
|
175
|
-
},
|
|
176
|
-
'1.0.0'
|
|
177
|
-
);
|
|
277
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
278
|
+
|
|
178
279
|
expect(logOutput).to.have.lengthOf(0);
|
|
179
280
|
expect(analyticsOutput).to.be.empty;
|
|
180
281
|
|
|
181
282
|
bus.emit('mongosh:new-user', { userId, anonymousId: userId });
|
|
283
|
+
bus.emit('mongosh:log-initialized');
|
|
284
|
+
|
|
182
285
|
bus.emit('mongosh:update-user', { userId, anonymousId: userId });
|
|
183
286
|
bus.emit('mongosh:start-session', {
|
|
184
287
|
isInteractive: true,
|
|
@@ -297,11 +400,13 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
297
400
|
error: new Error('failed'),
|
|
298
401
|
duringLoad: false,
|
|
299
402
|
resolutionDetails: [],
|
|
403
|
+
durationMs: 1,
|
|
300
404
|
});
|
|
301
405
|
bus.emit('devtools-connect:resolve-srv-succeeded', {
|
|
302
406
|
from: 'mongodb+srv://foo:bar@hello.world/',
|
|
303
407
|
to: 'mongodb://foo:bar@db.hello.world/',
|
|
304
408
|
resolutionDetails: [],
|
|
409
|
+
durationMs: 1,
|
|
305
410
|
});
|
|
306
411
|
bus.emit('devtools-connect:missing-optional-dependency', {
|
|
307
412
|
name: 'kerberos',
|
|
@@ -427,12 +532,14 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
427
532
|
error: 'failed',
|
|
428
533
|
duringLoad: false,
|
|
429
534
|
resolutionDetails: [],
|
|
535
|
+
durationMs: 1,
|
|
430
536
|
});
|
|
431
537
|
expect(logOutput[i].msg).to.equal('Resolving SRV record succeeded');
|
|
432
538
|
expect(logOutput[i++].attr).to.deep.equal({
|
|
433
539
|
from: 'mongodb+srv://<credentials>@hello.world/',
|
|
434
540
|
to: 'mongodb://<credentials>@db.hello.world/',
|
|
435
541
|
resolutionDetails: [],
|
|
542
|
+
durationMs: 1,
|
|
436
543
|
});
|
|
437
544
|
expect(logOutput[i].msg).to.equal('Missing optional dependency');
|
|
438
545
|
expect(logOutput[i++].attr).to.deep.equal({
|
|
@@ -472,7 +579,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
472
579
|
traits: {
|
|
473
580
|
platform: process.platform,
|
|
474
581
|
arch: process.arch,
|
|
475
|
-
session_id:
|
|
582
|
+
session_id: logId,
|
|
476
583
|
},
|
|
477
584
|
},
|
|
478
585
|
],
|
|
@@ -483,7 +590,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
483
590
|
traits: {
|
|
484
591
|
platform: process.platform,
|
|
485
592
|
arch: process.arch,
|
|
486
|
-
session_id:
|
|
593
|
+
session_id: logId,
|
|
487
594
|
},
|
|
488
595
|
},
|
|
489
596
|
],
|
|
@@ -498,7 +605,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
498
605
|
boxed_node_bindings: 50,
|
|
499
606
|
node_repl: 100,
|
|
500
607
|
mongosh_version: '1.0.0',
|
|
501
|
-
session_id:
|
|
608
|
+
session_id: logId,
|
|
502
609
|
},
|
|
503
610
|
},
|
|
504
611
|
],
|
|
@@ -509,7 +616,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
509
616
|
event: 'Error',
|
|
510
617
|
properties: {
|
|
511
618
|
mongosh_version: '1.0.0',
|
|
512
|
-
session_id:
|
|
619
|
+
session_id: logId,
|
|
513
620
|
name: 'MongoshInvalidInputError',
|
|
514
621
|
code: 'CLIREPL-1005',
|
|
515
622
|
scope: 'CLIREPL',
|
|
@@ -524,7 +631,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
524
631
|
event: 'Error',
|
|
525
632
|
properties: {
|
|
526
633
|
mongosh_version: '1.0.0',
|
|
527
|
-
session_id:
|
|
634
|
+
session_id: logId,
|
|
528
635
|
name: 'MongoshInvalidInputError',
|
|
529
636
|
code: 'CLIREPL-1005',
|
|
530
637
|
scope: 'CLIREPL',
|
|
@@ -539,7 +646,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
539
646
|
event: 'Use',
|
|
540
647
|
properties: {
|
|
541
648
|
mongosh_version: '1.0.0',
|
|
542
|
-
session_id:
|
|
649
|
+
session_id: logId,
|
|
543
650
|
},
|
|
544
651
|
},
|
|
545
652
|
],
|
|
@@ -550,7 +657,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
550
657
|
event: 'Show',
|
|
551
658
|
properties: {
|
|
552
659
|
mongosh_version: '1.0.0',
|
|
553
|
-
session_id:
|
|
660
|
+
session_id: logId,
|
|
554
661
|
method: 'dbs',
|
|
555
662
|
},
|
|
556
663
|
},
|
|
@@ -561,7 +668,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
561
668
|
event: 'Script Loaded CLI',
|
|
562
669
|
properties: {
|
|
563
670
|
mongosh_version: '1.0.0',
|
|
564
|
-
session_id:
|
|
671
|
+
session_id: logId,
|
|
565
672
|
nested: true,
|
|
566
673
|
shell: true,
|
|
567
674
|
},
|
|
@@ -574,7 +681,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
574
681
|
event: 'Script Loaded',
|
|
575
682
|
properties: {
|
|
576
683
|
mongosh_version: '1.0.0',
|
|
577
|
-
session_id:
|
|
684
|
+
session_id: logId,
|
|
578
685
|
nested: false,
|
|
579
686
|
},
|
|
580
687
|
anonymousId: '53defe995fa47e6c13102d9d',
|
|
@@ -586,7 +693,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
586
693
|
event: 'Mongoshrc Loaded',
|
|
587
694
|
properties: {
|
|
588
695
|
mongosh_version: '1.0.0',
|
|
589
|
-
session_id:
|
|
696
|
+
session_id: logId,
|
|
590
697
|
},
|
|
591
698
|
anonymousId: '53defe995fa47e6c13102d9d',
|
|
592
699
|
},
|
|
@@ -597,7 +704,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
597
704
|
event: 'Mongorc Warning',
|
|
598
705
|
properties: {
|
|
599
706
|
mongosh_version: '1.0.0',
|
|
600
|
-
session_id:
|
|
707
|
+
session_id: logId,
|
|
601
708
|
},
|
|
602
709
|
anonymousId: '53defe995fa47e6c13102d9d',
|
|
603
710
|
},
|
|
@@ -608,7 +715,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
608
715
|
event: 'Script Evaluated',
|
|
609
716
|
properties: {
|
|
610
717
|
mongosh_version: '1.0.0',
|
|
611
|
-
session_id:
|
|
718
|
+
session_id: logId,
|
|
612
719
|
shell: true,
|
|
613
720
|
},
|
|
614
721
|
anonymousId: '53defe995fa47e6c13102d9d',
|
|
@@ -621,7 +728,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
621
728
|
event: 'Snippet Install',
|
|
622
729
|
properties: {
|
|
623
730
|
mongosh_version: '1.0.0',
|
|
624
|
-
session_id:
|
|
731
|
+
session_id: logId,
|
|
625
732
|
},
|
|
626
733
|
},
|
|
627
734
|
],
|
|
@@ -629,11 +736,14 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
629
736
|
});
|
|
630
737
|
|
|
631
738
|
it('buffers deprecated API calls', function () {
|
|
632
|
-
|
|
739
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
740
|
+
|
|
633
741
|
expect(logOutput).to.have.lengthOf(0);
|
|
634
742
|
expect(analyticsOutput).to.be.empty;
|
|
635
743
|
|
|
636
744
|
bus.emit('mongosh:new-user', { userId, anonymousId: userId });
|
|
745
|
+
bus.emit('mongosh:log-initialized');
|
|
746
|
+
|
|
637
747
|
bus.emit('mongosh:evaluate-started');
|
|
638
748
|
|
|
639
749
|
logOutput = [];
|
|
@@ -712,7 +822,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
712
822
|
event: 'Deprecated Method',
|
|
713
823
|
properties: {
|
|
714
824
|
mongosh_version: '1.0.0',
|
|
715
|
-
session_id:
|
|
825
|
+
session_id: logId,
|
|
716
826
|
class: 'Database',
|
|
717
827
|
method: 'cloneDatabase',
|
|
718
828
|
},
|
|
@@ -725,7 +835,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
725
835
|
event: 'Deprecated Method',
|
|
726
836
|
properties: {
|
|
727
837
|
mongosh_version: '1.0.0',
|
|
728
|
-
session_id:
|
|
838
|
+
session_id: logId,
|
|
729
839
|
class: 'Database',
|
|
730
840
|
method: 'copyDatabase',
|
|
731
841
|
},
|
|
@@ -738,7 +848,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
738
848
|
event: 'Deprecated Method',
|
|
739
849
|
properties: {
|
|
740
850
|
mongosh_version: '1.0.0',
|
|
741
|
-
session_id:
|
|
851
|
+
session_id: logId,
|
|
742
852
|
class: 'Database',
|
|
743
853
|
method: 'mangleDatabase',
|
|
744
854
|
},
|
|
@@ -751,7 +861,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
751
861
|
event: 'API Call',
|
|
752
862
|
properties: {
|
|
753
863
|
mongosh_version: '1.0.0',
|
|
754
|
-
session_id:
|
|
864
|
+
session_id: logId,
|
|
755
865
|
class: 'Database',
|
|
756
866
|
method: 'cloneDatabase',
|
|
757
867
|
count: 3,
|
|
@@ -765,7 +875,7 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
765
875
|
event: 'API Call',
|
|
766
876
|
properties: {
|
|
767
877
|
mongosh_version: '1.0.0',
|
|
768
|
-
session_id:
|
|
878
|
+
session_id: logId,
|
|
769
879
|
class: 'Database',
|
|
770
880
|
method: 'copyDatabase',
|
|
771
881
|
count: 1,
|
|
@@ -801,7 +911,8 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
801
911
|
});
|
|
802
912
|
|
|
803
913
|
it('does not track database calls outside of evaluate-{started,finished}', function () {
|
|
804
|
-
|
|
914
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
915
|
+
|
|
805
916
|
expect(logOutput).to.have.lengthOf(0);
|
|
806
917
|
expect(analyticsOutput).to.be.empty;
|
|
807
918
|
|
|
@@ -822,4 +933,107 @@ describe('setupLoggerAndTelemetry', function () {
|
|
|
822
933
|
expect(logOutput).to.have.lengthOf(0);
|
|
823
934
|
expect(analyticsOutput).to.be.empty;
|
|
824
935
|
});
|
|
936
|
+
|
|
937
|
+
it('tracks custom logging events', function () {
|
|
938
|
+
expect(logOutput).to.have.lengthOf(0);
|
|
939
|
+
expect(analyticsOutput).to.be.empty;
|
|
940
|
+
|
|
941
|
+
loggingAndTelemetry.attachLogger(logger);
|
|
942
|
+
|
|
943
|
+
bus.emit('mongosh:connect', {
|
|
944
|
+
uri: 'mongodb://localhost/',
|
|
945
|
+
is_localhost: true,
|
|
946
|
+
is_atlas: false,
|
|
947
|
+
resolved_hostname: 'localhost',
|
|
948
|
+
node_version: 'v12.19.0',
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
bus.emit('mongosh:write-custom-log', {
|
|
952
|
+
method: 'info',
|
|
953
|
+
message: 'This is an info message',
|
|
954
|
+
attr: { some: 'value' },
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
bus.emit('mongosh:write-custom-log', {
|
|
958
|
+
method: 'warn',
|
|
959
|
+
message: 'This is a warn message',
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
bus.emit('mongosh:write-custom-log', {
|
|
963
|
+
method: 'error',
|
|
964
|
+
message: 'Error!',
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
bus.emit('mongosh:write-custom-log', {
|
|
968
|
+
method: 'fatal',
|
|
969
|
+
message: 'Fatal!',
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
bus.emit('mongosh:write-custom-log', {
|
|
973
|
+
method: 'debug',
|
|
974
|
+
message: 'Debug with level',
|
|
975
|
+
level: 1,
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
bus.emit('mongosh:write-custom-log', {
|
|
979
|
+
method: 'debug',
|
|
980
|
+
message: 'Debug without level',
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
expect(logOutput[0].msg).to.equal('Connecting to server');
|
|
984
|
+
expect(logOutput[0].attr.connectionUri).to.equal('mongodb://localhost/');
|
|
985
|
+
expect(logOutput[0].attr.is_localhost).to.equal(true);
|
|
986
|
+
expect(logOutput[0].attr.is_atlas).to.equal(false);
|
|
987
|
+
expect(logOutput[0].attr.atlas_hostname).to.equal(null);
|
|
988
|
+
expect(logOutput[0].attr.node_version).to.equal('v12.19.0');
|
|
989
|
+
|
|
990
|
+
expect(logOutput[1].s).to.equal('I');
|
|
991
|
+
expect(logOutput[1].c).to.equal('MONGOSH-SCRIPTS');
|
|
992
|
+
expect(logOutput[1].ctx).to.equal('custom-log');
|
|
993
|
+
expect(logOutput[1].msg).to.equal('This is an info message');
|
|
994
|
+
expect(logOutput[1].attr.some).to.equal('value');
|
|
995
|
+
|
|
996
|
+
expect(logOutput[2].s).to.equal('W');
|
|
997
|
+
expect(logOutput[2].c).to.equal('MONGOSH-SCRIPTS');
|
|
998
|
+
expect(logOutput[2].ctx).to.equal('custom-log');
|
|
999
|
+
expect(logOutput[2].msg).to.equal('This is a warn message');
|
|
1000
|
+
|
|
1001
|
+
expect(logOutput[3].s).to.equal('E');
|
|
1002
|
+
expect(logOutput[3].c).to.equal('MONGOSH-SCRIPTS');
|
|
1003
|
+
expect(logOutput[3].ctx).to.equal('custom-log');
|
|
1004
|
+
expect(logOutput[3].msg).to.equal('Error!');
|
|
1005
|
+
|
|
1006
|
+
expect(logOutput[4].s).to.equal('F');
|
|
1007
|
+
expect(logOutput[4].c).to.equal('MONGOSH-SCRIPTS');
|
|
1008
|
+
expect(logOutput[4].ctx).to.equal('custom-log');
|
|
1009
|
+
expect(logOutput[4].msg).to.equal('Fatal!');
|
|
1010
|
+
|
|
1011
|
+
expect(logOutput[5].s).to.equal('D1');
|
|
1012
|
+
expect(logOutput[5].c).to.equal('MONGOSH-SCRIPTS');
|
|
1013
|
+
expect(logOutput[5].ctx).to.equal('custom-log');
|
|
1014
|
+
expect(logOutput[5].msg).to.equal('Debug with level');
|
|
1015
|
+
|
|
1016
|
+
expect(logOutput[6].s).to.equal('D1');
|
|
1017
|
+
expect(logOutput[6].c).to.equal('MONGOSH-SCRIPTS');
|
|
1018
|
+
expect(logOutput[6].ctx).to.equal('custom-log');
|
|
1019
|
+
expect(logOutput[6].msg).to.equal('Debug without level');
|
|
1020
|
+
|
|
1021
|
+
expect(analyticsOutput).to.deep.equal([
|
|
1022
|
+
[
|
|
1023
|
+
'track',
|
|
1024
|
+
{
|
|
1025
|
+
anonymousId: undefined,
|
|
1026
|
+
event: 'New Connection',
|
|
1027
|
+
properties: {
|
|
1028
|
+
mongosh_version: '1.0.0',
|
|
1029
|
+
session_id: '5fb3c20ee1507e894e5340f3',
|
|
1030
|
+
is_localhost: true,
|
|
1031
|
+
is_atlas: false,
|
|
1032
|
+
atlas_hostname: null,
|
|
1033
|
+
node_version: 'v12.19.0',
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
],
|
|
1037
|
+
]);
|
|
1038
|
+
});
|
|
825
1039
|
});
|