Skip to content

Add support for integrating with external reporting #196

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

Closed

Conversation

sullivanst
Copy link

We use Raygun to record JavaScript errors. It would be nice to have migrate warnings there too. Raygun likes Error objects - and we like stack traces - so save Error objects in parallel with the warning messages in migrateWarn() and also raise an event that a listener can trigger on to extract the data & send it wherever it wishes.

sullivanst and others added 5 commits May 27, 2016 18:48
We use Raygun to log our javascript errors, and we'd like to automatically report migration warnings there too. Raising an event when a warning is logged seems a very natural way to do this - we can come scrape $.migrateWarnings when triggered. A stack trace also seems like a very useful thing to have, so extending the warning seems like a natural way to achieve this (it also helps a lot with Raygun, which likes to send Error objects).
Lint rules do not allow use of new String(), so use a parallel array to store Errors rather than a property on a String object.
Update tests to account for additional assert in expectWarning with a
specified, non-zero count
@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @dmethvin, @mgol and @markelog to be potential reviewers

@jquerybot
Copy link

Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA).

📝 Please visit http://contribute.jquery.org/CLA/ to sign.

After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know.


If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, check the status of your CLA check.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 88.444% when pulling b72995e on sullivanst:sullivanst-patch-raiseEvents into 94d9800 on jquery:master.

@mgol
Copy link
Member

mgol commented May 27, 2016

What's the purpose of jQuery.migrateWarnings.asErrors? It just duplicates the jQuery.migrateWarnings array.

migrateWarnings.asErrors was supposed to wrap the message in an Error message to create a stack trace
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 88.444% when pulling 97eddc0 on sullivanst:sullivanst-patch-raiseEvents into 94d9800 on jquery:master.

@sullivanst
Copy link
Author

@mgol Oops, I missed of wrapping it in a new Error() - added that now.

@sullivanst
Copy link
Author

I made the mistake of using my actual full name instead of my github username when signing the CLA. How do I fix those commits?

@gibson042
Copy link
Member

I made the mistake of using my actual full name instead of my github username when signing the CLA. How do I fix those commits?

You can rewrite b72995e with git rebase -i b72995e^, marking it for edit and using git commit --amend --reset-author (or --author=…) before git rebase --continue. Once your sullivanst-patch-raiseEvents history is clean, git push --force it to GitHub.

};

function migrateWarn( msg ) {
var console = window.console;
if ( !warnedAbout[ msg ] ) {
warnedAbout[ msg ] = true;
jQuery.migrateWarnings.push( msg );
jQuery.migrateWarnings.asErrors.push( new Error( msg ) );
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mgol; this is completely redundant.

Copy link
Author

Choose a reason for hiding this comment

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

new Error( msg ).stack makes a difference (I managed to forget to put the wrapping in at first). We have a warning I'll have to try to track down after the weekend because we're muted for production and migrateWarnings doesn't provide context.

@dmethvin
Copy link
Member

I think that the discussion in #15 still covers this use case, it doesn't seem to be a common enough need to add more plumbing. The warnings are already exposed as an array, you can enumerate them as needed and send them up to a server. If your error telemetry package already traps console messages it seems like you'd be getting this for free anyway.

if ( console && console.warn && !jQuery.migrateMute ) {
console.warn( "JQMIGRATE: " + msg );
if ( jQuery.migrateTrace && console.trace ) {
console.trace();
}
}
jQuery( window ).trigger( "migrateWarning" );
Copy link
Member

Choose a reason for hiding this comment

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

The only time we currently call back into jQuery is to shim a method for warnings. This introduces a situation where we are using the host jQuery's functionality, which makes me nervous. It could potentially cause a recursive crash if Migrate was to give .trigger() warnings in the future.

Copy link
Member

Choose a reason for hiding this comment

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

I'd consider it bad form to leak global events, but would be happy to see a hook that gets invoked here, including event emitter style (e.g., jQuery.migrateWarningHooks.push( handler ) or jQuery.migrateWarnings.on( "warning", handler )).

Copy link
Author

Choose a reason for hiding this comment

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

I have to say I hadn't thought of intercepting the console. Obviously that would require unmuting jquery-migrate, and adding the wrapper in that intercept would be another uninformative line in the stack trace, but that's certainly no dealbreaker. Would scraping for /^JQMIGRATE:/ be safe both now and in the future for consumers who have other cruft in their console they aren't interested in recording?

I understand your hesitation about looping back through .trigger, although it would certainly be possible if you were duckpunching trigger to call the original directly in that one case (or presumably if you were raising warnings, there's a decent chance it'd be because some other way would be preferred).

Copy link
Member

Choose a reason for hiding this comment

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

I have to say I hadn't thought of intercepting the console. Obviously that would require unmuting jquery-migrate, and adding the wrapper in that intercept would be another uninformative line in the stack trace

Then duckpunch jQuery.migrateWarnings.push like I suggested in #15.

Copy link
Author

Choose a reason for hiding this comment

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

That'll work.

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.

8 participants