-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tracking issue for @sentry/* SDKs #1281
Comments
https://github.com/getsentry/sentry-cordova and https://github.com/getsentry/sentry-electron are both using our new SDKs internally. We already got a lot of feedback and the public API and in general should be pretty safe now. |
Hey! I maintain I think the only thing I see missing is a way to lazily configure the scope. With If you do support registering a callback like this, it would also be good to support unregistering the callback, since in a server side rendering context we may want to (lazily) set this scope once per request. An API method like import createStore from 'redux';
const store = createStore(/* ... */);
const unsubscribe = Sentry.configureScopeOnError(scope => {
scope.setExtra('state', transformState(store.getState()));
scope.setUser(deriveUserFromState(store.getState()));
}); Another option would be to expose some way to register a generic import createStore from 'redux';
const store = createStore(/* ... */);
const unsubscribe = Sentry.onError(()=> {
Sentry.configureScope((scope) => {
scope.setExtra('state', transformState(store.getState()));
scope.setUser(deriveUserFromState(store.getState()));
});
}); These are just the ideas the jump to mind immediately. Maybe you see another way to do it, or a clearer API? |
@captbaritone Thank you for taking the time to look at our new SDK. For the new SDKs we came up with something we call So I think what you want to do is build an integration. We introduced so you could do something like this: public install(): void {
getCurrentHub().addEventProcessor(async (event: SentryEvent) => {
// mutate event before sending in here
// return mutated event OR null of you want to discard it
});
} This integration (in node) also configures a scope: And the usage of you integration would also be super easy: import * as Sentry from '@sentry/browser';
import { ReduxIntegration } from "raven-for-redux";
init({
dsn: '__DSN__',
integrations: (integrations) => {
// integrations include all default integrations we provide
// you could do this:
integrations.push(new ReduxIntegration(/* you can pass anything here e.g. store*/));
return integrations;
}
}); I hope you get the idea, |
We. Are. Doneee. |
Hey, I'm not sure if this is the right place to ask but I'm currently playing with the new SDK and have some questions: 1: How do we set a custom log level when logging exceptions via 2: How exactly does scope work, the docs are not clear on this at all? I assume this:
2.1: Do I need to need to explictly call |
Furthermore, how we do we set global tags now? |
So, I played around with this for a bit, calling |
@SimonSchick Thanks for your feedback, also I like to mention that we are working the docs as we speak, it's planned that we ship the new docs today which should clear up everything but nevertheless I'd like to give you answers to your questions directly. 1.: We dropped the "arbitrary" second parameter in 2.: Like I mentioned, scope docs are in the works, but you can think of it like a stack which is holding context information. The example you provided is almost correct and works the way as you expect. 2.1.: For this case (while not documented here yet), we introduced a way to Sentry.getCurrentHub().pushScope();
Sentry.configureScope(scope => {
scope.setUser({ id: 'superuser' });
});
Sentry.captureException(err);
Sentry.getCurrentHub().pushScope(); In this code example we 2.1.1: A scope lives in memory and is not persisted to disk or something like that, defining global context can be done in the root scope. 2.2.: Yes, You can set a global tag simply with Sentry.configureScope(scope => {
scope.setTag(bla, 'blub');
}); Calling This was a bit of a long comment but I hope this makes stuff more clear. |
@SimonSchick We are disscussing if we should add something like: captureException(exception, scope => {
scope.setTag('bla', 'blub');
scope.setLevel('warning');
}); will keep you posted. |
Update: It's already in master and the next rc will contain it. Sentry.withScope(scope => {
scope.setTag(bla, 'blub').setLevel('warning');
Sentry.captureException(new Error('bla'));
}); This example will have the tag and level only set for this exception. |
Thanks for the replies, can you explain the difference between Furthermore, I worked around the limitation by instantiating a The code looks roughly like this:
Looking forward to not having to do that :) |
Again, thanks for the swift reply, I understand this is an RC so I really appreciate you guys reacting to quickly! |
@SimonSchick Correct, |
Yea that's what I thought, I will use the new API once the package is released :) |
Hi there! I'm currently migrating our codebase to use new sdk, and trying to figure out what would be good way to replicated While So far I ended up with having a Or should I open separate issue altogether? Thanks in advance! |
You usually want to set the user on the global scope upon login (single page app) or set it on page load. |
@SimonSchick I'm talking about |
Can you tell us a little bit more about your use-case? If you have a system with middlewares it should be easy enough to just use |
@kblcuk you have an access to the request itself in all middlewares, thus you can parse user manually in any way you need // express example
function yourCustomUserParser (req, res, next) {
Sentry.configureScope((scope) => scope.setUser({
username: req.specialUserField.username,
id: req.specialUserField.getId()
}));
next();
}
// order matters
app.use(Sentry.Handlers.requestHandler());
app.use(yourCustomUserParser);
app.get('/', function mainHandler(req, res) {
throw new Error('Broke!');
});
app.use(Sentry.Handlers.errorHandler());
app.listen(3000); |
@kamilogorek isn't |
@SimonSchick not when used alongside sentry-javascript/packages/hub/src/hub.ts Lines 326 to 360 in d9bb595
The main part: sentry-javascript/packages/hub/src/hub.ts Lines 354 to 358 in d9bb595
|
I'm attempting to use configureScope to set user context during a session. According to the doc, it should be as simple as
This didn't work for me. I also attempted using slightly modified code posted by @HazAT above:
This also did not work for me. Do I need to configureScope every time captureException is called? I thought I could just set it once and it would be set for the entirety of the user's session unless otherwise modified. I inspected the Sentry module itself and saw there is a setUser function I can call directly:
This one did work for me and I am seeing user info attached to issues in the event log. Could someone help explain what I might be doing wrong when trying to use the recommended configuration? |
@brianmock This is really strange, all three of them should work and they do here: Not sure what's going on. Can you confirm it works in the example I posted? |
@HazAT works in the example posted and I figured out my issue, it was my fault. There was a race condition between the exception and setting the user context so sometimes user info was there and sometimes it was not and I had happened to see it work with setUser instead of configureScope. Thank you for your time tho. |
@brianmock what did you do to address the race condition? i'm running into similar issues but it doesn't seem like setUser returns a promise or something to enable awaiting its completion before moving on |
Can we set the user scope under |
Next Generation SDK Discussion
As you might have noticed, we have started pushing out pre-release versions for our next line of JavaScript SDKs. You can identify them by the
@sentry/*
namespace on NPM. The goal in this new lineup is to provide a more convenient interface and improved consistency between various JavaScript environments.The SDKs are developed in mono-repository located in packages.
Updated Interface
Library minimal
A new feature of this SDK lineup is the minimal package. It allows library authors add support for a Sentry SDK without having to bundle the entire SDK or being dependent on a specific platform. If the library is included and a Sentry SDK is present, it will automagically work:
We hope to see library authors adopt this feature in the future to facilitate better error tracking across the ecosystem.
Scope concept
We introduced a new concept we called
Scope
. AScope
holds an isolated state of breadcrumbs, context and other metadata.raven-node
andraven-js
had a similar feature, ambiguously called "context". There always is a "default"Scope
which handles all the stuff as we did before you have to do nothing but we also support pushing new aScope
if you ever want to have isolated context information lets say for example, each request that comes in in a node application should have it's ownScope
.To add
extra
,tags
oruser
to your event you have to call:If you want to have isolated information for only on specific event you can to:
The text was updated successfully, but these errors were encountered: