Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Instrument require() for autobreadcrumbs - #322

Merged
LewisJEllis merged 5 commits into
masterfrom
require-hook-instrumentation
Jun 2, 2017
Merged

LewisJEllis merged 5 commits into
masterfrom
require-hook-instrumentation

Conversation

@LewisJEllis

Copy link
Copy Markdown
Contributor

This is a bit behind where I am locally, will push an update soon, but here's the PR to start tracking.

@LewisJEllis

LewisJEllis commented May 23, 2017 •

Copy link
Copy Markdown
Contributor Author

This is now pretty much fully working. I had a bunch of subtle module caching and double-instrumentation stuff going on in the tests because my first pass at uninstall() was slightly insufficient, but got that worked out now.

Still want to investigate a couple things:

  • http breadcrumbs are sometimes missing req.method, unsure if related to these changes or a separate thing
  • option of hooking Module._load instead of Module.prototype.require: pros and cons, any reason to prefer one or the other?
  • observation: when node-core's https module does its own require('http'), it won't hit our hooked require to instrument http, but if we've previously instrumented http it will get our instrumented version, hence the proactive require('http') in instrumentor.instrument; I want to better understand why this is.

/cc @MaxBittker @benvinegar

@benvinegar

Copy link
Copy Markdown
Contributor

This is now pretty much fully working.

Still want to investigate a couple things:

Is this still WIP? Should we be reviewing?

@LewisJEllis

Copy link
Copy Markdown
Contributor Author

Worked through investigation points 2 and 3 and determined that current state is acceptable. Identified a duplication issue of some sort in point 1, tracking it down and then I'll remove WIP tag and request review.

@LewisJEllis
LewisJEllis force-pushed the require-hook-instrumentation branch from 129f3f8 to b555acf Compare June 1, 2017 23:26
@LewisJEllis
LewisJEllis force-pushed the require-hook-instrumentation branch from c10116c to 838330f Compare June 1, 2017 23:41
@LewisJEllis

LewisJEllis commented Jun 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Tracked down duplication. Also actually figured out the explanation behind point 3, but opted to leave it as is to avoid a significant mostly-unnecessary refactor; explained in a comment above where we proactively require('http').

Ready for review; primary piece to review is instrumentor.js; aspects of that in particular are how instrumentor is used from client.js and the coupling between instrumentor and Raven, and the interface between instrumentor and each of the three "instrument this module" files.

@LewisJEllis LewisJEllis changed the title WIP: instrument require() for autobreadcrumbs Instrument require() for autobreadcrumbs Jun 2, 2017

@benvinegar benvinegar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I actually wrote a bunch more comments, then worked through the logic and realized I had it wrong – seems good. My one request changes is re: DRYing the fill helper.

Comment thread lib/instrumentation/instrumentor.js Outdated
pg: false
};

function fill(obj, name, replacement, track) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we not put this in ../utils? It's duplicated 3 times in this patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yea, sure, I had a mental note on this but forgot about it. This was another of my motivating factors for a shared js utils, but that's a separate issue.

var Module = require('module');
fill(Module, '_load', function (origLoad) {
return function (moduleId, parent, isMain) {
var origModule = origLoad.apply(this, arguments);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth doing that Array args copy / perf trick here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but there are a few other spots where we're doing something.apply(this, arguments) in instrumentation for console and http (and fwiw raven-js also has spots where it doesn't do the copy opt...), so I'd rather go all-or-nothing on it.

Comment thread lib/client.js
this.autoBreadcrumbs = options.autoBreadcrumbs || false;
// default to 30, don't allow higher than 100
this.maxBreadcrumbs = Math.max(0, Math.min(options.maxBreadcrumbs || 30, 100));
this.autoBreadcrumbs = extend({}, autoBreadcrumbDefaults);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought we had a test for this logic. Is it not affected by this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For which part in particular? I basically moved the "figure out what our autobreadcrumb to turn on" bit into instrumentor. I don't think anything really changed behavior-wise, just where it lives, so now client has to care a lot less and just has to pass its config on to the instrumentor. It actually ended up simplifying things quite a bit from a combination of two or three small differences.

@benvinegar benvinegar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔥 Lets run the memcheck stuff before cutting a new version.

@LewisJEllis
LewisJEllis merged commit 77f022c into master Jun 2, 2017
@LewisJEllis
LewisJEllis deleted the require-hook-instrumentation branch June 2, 2017 01:02
MaxBittker added a commit that referenced this pull request Jun 20, 2017
Version 2.1.0
- Truncate long lines in surrounding source to avoid sending large amounts of minified code [See #329]
- Refactor automatic breadcrumb instrumentation of modules to accommodate compilation tools [See #322]
- Testing for Node 8 [See #328]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants