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

enable breadcrumbs and context-scoped calls for node #1927

Merged
merged 15 commits into from
Aug 7, 2023

Conversation

djskinner
Copy link
Contributor

@djskinner djskinner commented Feb 16, 2023

Goal

  • Enable full support for breadcrumbs on node.js

Design

  • Remove the noop method override on leaveBreadcrumb that prevented usage of breadcrumbs on the main client instance. Note cloned instances such as those inside a request handler didn't have this limitation though such usage was undocumented.
  • When calling method on the main client instance, such as Bugsnag.leaveBreadrumb or Bugsnag.addFeatureFlag from within an AsyncLocalStorage context (e.g. when using the express plugin or plugin-contextualize) forward the method onto the cloned client instance thereby achieving scoped context without having to pass the cloned instance of the client (e.g. req.bugsnag) around.
  • Add a runInContext middleware for express that can be used to re-establish the AsyncLocalStorage context which can be lost in some scenarios (where such context loss prevents the correct operation of Bugsnag. calls, such as Bugsnag.leaveBreadcrumb)

Testing

  • e2e test coverage
  • manual testing

@github-actions
Copy link

github-actions bot commented Feb 16, 2023

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 44.38 kB 13.53 kB
After 44.38 kB 13.53 kB
± No change No change

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against 036f3da

@djskinner djskinner force-pushed the node-breadcrumbs branch 6 times, most recently from 20015fd to 550caa4 Compare February 17, 2023 11:59
@djskinner djskinner marked this pull request as ready for review February 17, 2023 13:45
Copy link
Contributor

@imjoehaines imjoehaines left a comment

Choose a reason for hiding this comment

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

Changes look good, but I think we need to test the APIs we're changing here — adding some unit tests to notifier.test.ts for Bugsnag.addMetadata & friends should be fine

Base automatically changed from contextualize to integration/v8 March 8, 2023 08:53
Dan Skinner and others added 6 commits March 8, 2023 10:10
the previous version suffered from loss of AsyncLocalStorage context so was updated
to show the Bugsnag.addFeatureFlag capabilities working inside a request context.

Further coverage will be considered separately for the context-loss cases.
Comment on lines +58 to +60
const runInContext = (req, res, next) => {
client._clientContext.run(req.bugsnag, next)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new express middleware that can be used to restore async local storage context if it is lost. See E2E tes showing usage

Comment on lines -66 to -70
bugsnag.leaveBreadcrumb = function () {
bugsnag._logger.warn('Breadcrumbs are not supported in Node.js yet')
}

bugsnag._config.enabledBreadcrumbTypes = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove the patches that were preventing breadcrumbs from being used with the node notifier

@@ -1,7 +1,7 @@
{
"name": "bugsnag-test",
"dependencies": {
"body-parser": "^1.19.0",
"body-parser": "^1.20.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bumping this to fix the context-loss present in the older versions

Comment on lines +147 to +148
Bugsnag.addFeatureFlags(featureFlags)
Bugsnag.clearFeatureFlag('from config 3')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was failing due to the context loss from doing bodyParser.urlencoded() with the older version of the dependency. Bumping fixes it. Could also have used middleware.runInContext to restore it

@@ -55,50 +55,6 @@ Scenario: not reporting unhandledRejections when autoDetectErrors is off
And I wait for 1 second
Then I should receive no requests

Scenario: using contextualize to add context to an error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to the new contextualize suite

@djskinner djskinner merged commit 08a2bd8 into integration/v8 Aug 7, 2023
9 checks passed
@djskinner djskinner deleted the node-breadcrumbs branch August 7, 2023 12:12
@gingerbenw gingerbenw mentioned this pull request Aug 29, 2024
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.

2 participants