-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
with_scope sometimes provides a scope = nil if there is no client. Other SDKs don't do this. #2010
Comments
I agree that it's better to have scope always present, but:
So from my experience, users aren't bothered by this behaviour much. And regarding the change itself, I think it "may" be possible, but we need to clarify a few things first:
Finally, given this will be a large change and almost certainly would introduce problems when it's rolled out, I think we should not proceed until we see other clear benefits. |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
I don't see the strong reason for diverging from common behavior. We don't recommend always initializing any other sdk all the time to avoid nullpointers in with-scope. The wizards and quickstart documentation out there is largely phrased the same across platforms, and I followed the rails one to the letter, yet still ended up in this state where tests break. The python sdk is a decent reference for exact behavior that I believe is also present in js. Yes there's always a hub with a scope present, so setting tags works before and after client initialization. |
@st0012 I guess we can line this up for the major? (unless you're really opposed to it) |
If we only look at the Ruby SDK itself, I don't see much benefit for such change. But if aligning SDKs' behaviours has high priority, sure let's do it 👍 And given you're more familiar with the Python SDK, can you help me check these behaviours? 🙏
|
I think the main benefit is as @untitaker said to not break any user code even if The following is basically what is missing since this runs irrespective of whether init is called or not on module import. |
Every thread has a Hub at all times, i.e. "get current hub" lazily creates a hub on the thread local based on the "main hub" (= hub on the main thread) if there is none
Then, the hub has a stack of the stack cannot be empty, it is initialized with
this results in the external behavior changes:
|
Configuration object doesn't exist in Python, I suppose that's equivalent to Client
no, I have to call
yes by the way, i have no strong opinion on whether all SDKs should be aligned to this level of detail -- just describing what python does I do sort of care about being able to set_tag before the sdk is initialized, and I strongly feel that it should not be possible to crash user code by having forgotten to initialize the SDK (since this can happen in a completely different part of the codebase) that said I am no longer involved with SDK development and cannot make any calls here. Just commenting as a user and former maintainer of py sdk |
fwiw these are not really relevant to ruby
the order problem is solved separately in ruby/rails land and this is a non-issue
again opaque behaviour that no one really needs tbh it's fine to simplify this discussion to "don't break user code when not initialized", we don't really need to talk about random edge case behaviours. |
we will be re-working the scope/hub system completely anyway so this is kinda stale now, closing. |
Issue Description
Sentry.with_scope
calls the passed block withnil
if the SDK is not initialized. This is inconsistent with the Python SDK.Reproduction Steps
run this code with the SDK imported but not initialized.
This code crashes if the Sentry SDK is set up, because
scope
isnil
.Expected Behavior
I expect
scope
to be non-nullable, i.e. there is a current scope at all times regardless of the SDK's state. I expect this because I am used to this behavior from the Python SDK, but I also just like this behavior more because there's less of a chance my added instrumentation code crashes depending on the environment I deploy it in.Actual Behavior
The code crashes.
Further comment: It seems to me that the Ruby SDK internally diverges significantly from Python in how it manages current hubs, current scope etc. The Python SDK always has a current hub and a current scope no matter how the SDK is configured, no matter which thread the current hub is fetched from. Ruby OTOH seems to create its first hub upon initialization.
I imagine that causes further issues, for example in the Ruby SDK, can I even set tags before I initialize the SDK? In Python I can.
Ruby Version
3.2.1, but it is irrelevant
SDK Version
5.7.0
Integration and Its Version
rails and sidekiq, all on 5.7.0
Sentry Config
that's the point, there's none
The text was updated successfully, but these errors were encountered: