Skip to content

Send tags with captureException #75

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
jacobsvante opened this issue Feb 19, 2013 · 12 comments
Closed

Send tags with captureException #75

jacobsvante opened this issue Feb 19, 2013 · 12 comments

Comments

@jacobsvante
Copy link

I haven't been able to send tags with captureException, but it is possible with captureMessage. Example:

Raven.captureException(exc, {tags: {'host': host}}); // Doesn't send "host" tag to sentry

Raven.captureMessage(exc, {tags: {'host': host}}); // Sends "host" tag to sentry
@mattrobenolt
Copy link
Contributor

I'll take a look at this today.

@mattrobenolt
Copy link
Contributor

@jmagnusson I just tested this and all appears well. Are you using the latest version of raven? And if so, what browser?

@jacobsvante
Copy link
Author

Hopefully it's on my end. I have Raven 1.0.5 and testing has been done on OS X with Chrome. I just tested it in the latest versions of Firefox and Safari, but it seems that sentry doesn't actually record the event for those two browsers, even though the GET request is sent just fine with a 200 response code. The Chrome request is handled by sentry, but without the tags sent along as previously mentioned.

Other info:
Sentry 5.4.1
* is used in CORS-setting in Sentry

This is what the Raven-related code looks like:

require(['startup'], function() {
    require([
        'cs!app/state',
        'app/config',
        'raven'
    ], function(
        appstate,
        appConf,
        Raven
    ) {
    var host = window.location.host,
        ravenOpts = {tags: {host: host}};

        // Initialize the error handler
        Raven.config(appConf.sentryDSN).install();

        try {
            appstate();
        }
        catch (exc) {
            // TODO: Why doesn't tags appear in Sentry?
            // TODO #2: Maybe alert user that an error has occurred
            Raven.captureException(exc, ravenOpts);
            throw exc;
        }
    });
});

@jacobsvante
Copy link
Author

I've also tried the latest master (5f92fc02f6) combined with the TraceKit version this repo links to (2964a1e at the time of writing). No success.

I should also add that captureMessage works fine in all three browsers. captureException only works in Chrome as I previously mentioned.

@jacobsvante
Copy link
Author

Removing install() from the code above so that window.onerror handler isn't added didn't make a difference either.

Passing my ravenOpts directly to Raven.config didn't send along tags either (not even for captureMessage).

@mattrobenolt
Copy link
Contributor

Are you trying to run from git directly, by any chance? Just including the src/raven.js is probably not the best idea.

Either way, could you intercept the makeRequest() function and see the data that's being sent?

@jacobsvante
Copy link
Author

I first tried the tagged 1.0.5 version found here, then also tried the src/raven.js and vendor/TraceKit/tracekit.js using the require.js shim config like this:

requirejs.config({
    paths: {
        jquery: 'ext/jquery',
        tracekit: 'ext/tracekit', // Error reporting
        raven: 'ext/raven', // Error reporting
    },
    shim: {
        jquery: {exports: 'jQuery'},
        tracekit: {exports: 'TraceKit', deps: ['jquery']},
        raven: {exports: 'Raven', deps: ['tracekit']},
    }
})

Both "flavors" had the same problems which I mentioned previously.

Here's the data being sent with makeRequest:

URL (same for all tested browsers):
http://our.sentry.dev/api/5/store/?sentry_version=2.0&sentry_client=raven-js/1.0.5&sentry_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&sentry_data=<json>

Gist with sentry_data for the different browsers can be found here

Our main.js where raven-js handler is added:

require(['startup'], function() {
    require([
        'cs!our/app/state',
        'our/app/config',
        'raven',
        'underscore.string'
    ], function(
        appstate,
        appConf,
        Raven,
        _s
    ) {
        var host = window.location.host,
            ravenOpts = {tags: {host: host}};

        // Initialize the error handler
        // Raven.install adds a global error handler to window.onerror
        Raven.config(appConf.sentryDSN, ravenOpts).install();

        throw Error('Testing captureException with raven-js');
        appstate();
    });
});

@mattrobenolt
Copy link
Contributor

First of all, thanks a ton for the information! :)

Now, just to clarify, you've posted two different ways of tacking on the extra data. First, you showed it being added directly to captureException(), then second, you showed it added to the config() call. I'm guessing that they're both working incorrectly?

@jacobsvante
Copy link
Author

And thanks for making this awesome script! :-)

Actually I noticed that the catch-statement was never reached. It seems that the global window.onerror handler added by Raven.install re-raised the exception and script execution stopped after that. Maybe I could create a simple test so that it can be replicated.

@mattrobenolt
Copy link
Contributor

Well, technically, an error that is cause, is supposed to be reraised. That is by design. Raven's job isn't supposed to intercept all of your errors and make them go away. Raven is just a middleware, if you will, that logs it. Typically, on an uncaught exception, you want the error to bubble up to the user and break because unexpected things can happen if your code keeps executing. So as a developer, it's your job to still catch your own errors and handle things appropriately.

@sinyagin
Copy link

Hello
I use 1.0.8.
Could you help me how can I send tags with function ?
function traceKitWindowOnError(message, url, lineNo)

var options = {
logger: 'my-logger',
tags: {
bank_id: "999999"}};
Raven.config(sentryUrl, options).install();
It doesn't send tags

@mattrobenolt
Copy link
Contributor

This should all be working just fine. Open a new ticket if it's broken in 1.1.

mgedmin added a commit to mgedmin/raven-js that referenced this issue Mar 26, 2014
I looked for a way to specify unchanging tags (such as git commit hash of my software), and mistakenly decided it wasn't possible to pass them to Raven.config() because the documentation enumerated various possible options but didn't mention `tags`.

Bugs like getsentry#75 convinced me that this was supposed to be a supported feature.  So here's a doc patch to avoid sending other users into confusion.
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

No branches or pull requests

3 participants