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

feat(express): auto-track errors #127

Merged
merged 2 commits into from
Jan 3, 2018
Merged

Conversation

Qard
Copy link
Contributor

@Qard Qard commented Dec 18, 2017

This enables automatic tracking of express errors, rather than requiring manual use of the middleware.

Fixes #84

@codecov-io
Copy link

codecov-io commented Dec 18, 2017

Codecov Report

Merging #127 into master will increase coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #127      +/-   ##
==========================================
+ Coverage   82.55%   82.86%   +0.31%     
==========================================
  Files          38       38              
  Lines        1920     1938      +18     
==========================================
+ Hits         1585     1606      +21     
+ Misses        335      332       -3
Impacted Files Coverage Δ
lib/instrumentation/modules/express.js 80.95% <100%> (+9.84%) ⬆️
lib/agent.js 88.09% <100%> (ø) ⬆️
lib/instrumentation/express-utils.js 88.88% <0%> (+22.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e18e9d...79a98de. Read the comment docs.

@Qard Qard self-assigned this Dec 18, 2017
shimmer.wrap(layer.constructor.prototype, 'handle_error', function (orig) {
return function (err, req) {
if (!err[reportedSymbol]) {
err[reportedSymbol] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like this approach. I can think of a few places in our code base where we should do that instead 😅

@@ -12,12 +12,45 @@ module.exports = function (express, agent, version) {
return express
}

// express 5 moves the router methods onto a prototype
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice that you're thinking of Express 5 already 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't fully tested express 5, but that was an easy part to fix.

Copy link
Contributor

@watson watson left a comment

Choose a reason for hiding this comment

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

Unless you see a reason for keeping middleware.express around, I suggest that we remove it from the source code and from the docs. What do you think?

I've found it referenced in these sections in the docs:

Missing tests:

@watson
Copy link
Contributor

watson commented Dec 18, 2017

We should probably also add the new Express test file file to .tav.yml 😃

@Qard
Copy link
Contributor Author

Qard commented Dec 18, 2017

Since it's in end-user code, would it be better to have a deprecation warning for a bit?

@watson
Copy link
Contributor

watson commented Dec 18, 2017

Normally I would deprecate yes, but as we're still in beta and since we're making a few other breaking changes when we go GA, I think it's ok for us to make this one breaking as well. The more we can clean up now and not carry around as legacy for a while the cleaner/better I think. We'll have to make an upgrade guide for both old Opbeat users and for beta users when we go into GA anyway, so we can have a section mentioning breaking changes like this here. That's at least my current philosophy 😄

@Qard Qard force-pushed the express-errors branch 2 times, most recently from c5c45be to cca845b Compare December 19, 2017 00:19
@Qard
Copy link
Contributor Author

Qard commented Dec 19, 2017

Made those changes and also, when adding the TAV details discovered the approach I took didn't work before express 4.6 so I made some changes to how the patch gets applied. It's not using the layer.constructor.prototype anymore, so each layer instance will get patched separately, but as far as I can tell that should only happen the first time that layer is used.

@watson
Copy link
Contributor

watson commented Dec 19, 2017

@Qard if you feel it's better I think we should consider just dropping support for Express <4.6 as that version was released in June 2014. What do you think?

Returns a middleware function used to collect and send errors to the APM Server.

The middleware can be used as-is with either Connect or Express in the same way.
The middleware can be used as-is with either Connect in the same way.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just remove the entire line 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.

fixed.

@watson
Copy link
Contributor

watson commented Dec 20, 2017

@Qard As you also mentioned in #131 (comment), we forgot to add the new tav test to the TAV environment variables. That should be the last thing missing 😃

Before merging we need to figure out if we want to publish a new version of the module right after (as it's changing the docs), or if there's a better way to handle this. See #134 for more details.

Tip: I just tested it locally on Node 9 by having the-all-versions module installed globally and then running this command:

tav express '>=4' -- node test/instrumentation/modules/express.js

... and it all worked perfectly 👍

This enables automatic tracking of express errors,
rather than requiring manual use of the middleware.
@watson
Copy link
Contributor

watson commented Dec 23, 2017

Weird... I tried to resolve the conflicts using the "Resolve conflicts" button, but even though the commit that resolves them are included in the PR, GitHub still thinks the conflicts exists.

@watson watson merged commit 8584ad0 into elastic:master Jan 3, 2018
@Qard Qard deleted the express-errors branch January 9, 2018 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants