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
Conversation
let userId; | ||
let telemetry; | ||
|
||
let analytics = new NoopAnalytics(); |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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.
}); | ||
} | ||
|
||
export default logger; | ||
// set up a noop, in case we are not able to connect to segment. | ||
function NoopAnalytics() {} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
2e6b233
to
9037bbc
Compare
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. |
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 torelease.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 anEvergreen build?