Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOSH-110: send telemetry events to segment if opted-in #121

Merged
merged 12 commits into from May 6, 2020
Merged

Conversation

lrlna
Copy link
Contributor

@lrlna lrlna commented Apr 20, 2020

Description

Sends information to segment if user opted-in.

API_KEY from segment is to be read from ./config.js file that evergreen writes when releasing the binary. This PR adds a task to release.js to populate that file. Evergreen already has the appropriate key to be written.

This PR also adds a few more events: mongosh:new-user, mongosh-update-user
and mongosh:toggle-telemetry.

Information sent to segment is stripped of possible sensitive information that
could come in queries via mongodb-redact module.

Adds documentation on events we listen to in logger.ts

Open Questions

@durran what's the best possible way for me to get this API key into an
Evergreen build?

let userId;
let telemetry;

let analytics = new NoopAnalytics();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a noop just in case something goes wrong with the definition below. That way the following analytics calls don't fail and pollute user with errors.

analytics.track({
userId,
event: 'mongosh:error',
properties: { error }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the side effects of how the node repl handles errors weirdly, is that we can send errors that we've thrown to telemetry but skip other errors, right? Since we don't want to send every JS error ever triggered on the shell to telemetry? I'm not 100% clear on what errors are getting sent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question! so we currently send everything, because all the errors ever make it to the writer get logged. This doesn't include unhandled exceptions, since we don't currently handle those.

Do you think we should be a bit more specific about what errors we send back? For example, only MongoshInternalError? I do agree, I think telemetry will be super polluted if we do everything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd say even only Mongosh errors and not generic javascript errors that get written to the logger but not thrown by us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, now telemetry only gets Mongosh errors. Local logs get everything tho, because I want to keep an eye on all the js throws in case we have missed something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, ty!

@@ -123,7 +123,7 @@ class ShellEvaluator {
this.saveState();
const rewrittenInput = this.asyncWriter.compile(input);
this.bus.emit(
'mongosh:rewrittenAsyncInput',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could emit a little more intelligently here if you want - we could only emit when the rewritten input does not match the original input. (We'd have to set a flag to babel to not 'prettify' the generated code, or have the async-rewriter indicate that it has inserted an await, or remove all whitespace before comparison).

As it is, it will emit an event for literally everything that gets run in the shell, so it might not be that useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ that would be heaps more useful to us and to other users!

Copy link
Contributor

@mcasimir mcasimir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can't spot any reason why this shouldn't work in evergreen.

packages/cli-repl/src/logger.ts Outdated Show resolved Hide resolved
});
}

export default logger;
// set up a noop, in case we are not able to connect to segment.
function NoopAnalytics() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't class be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the syntax for a noop class? I've only ever written it like this before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this:

class NoopAnalytics {
   identify() {}
   track() {}
}

I was wondering if you had some form of typescript issue with that. Just a formality anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, nothing to do with typescript! I am just old school and didn't know the new and fancy syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in an unexpected turn of events, typescript does not, in fact like the class syntax.

packages/mapper/src/mapper.ts Outdated Show resolved Hide resolved
scripts/release.js Outdated Show resolved Hide resolved
scripts/release.js Outdated Show resolved Hide resolved
@lrlna lrlna force-pushed the add-segment branch 2 times, most recently from 2e6b233 to 9037bbc Compare May 6, 2020 15:12
@lrlna
Copy link
Contributor Author

lrlna commented May 6, 2020

I am going to merge it in, and see if evergreen will properly inject this file when on master. If not, I'll debug tomorrow. If it doesn't inject the key properly, master will not be broken and everything will continue functioning as is. Segment just won't get any data, but that's not different from what's happening right now.

@lrlna lrlna merged commit 95f0950 into master May 6, 2020
@lrlna lrlna deleted the add-segment branch May 6, 2020 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants