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

sentry-rails: NoMethodError: undefined method `span' for nil:NilClass #1539

Closed
timhaines opened this issue Aug 17, 2021 · 4 comments · Fixed by #1547
Closed

sentry-rails: NoMethodError: undefined method `span' for nil:NilClass #1539

timhaines opened this issue Aug 17, 2021 · 4 comments · Fixed by #1547
Assignees
Projects
Milestone

Comments

@timhaines
Copy link

Describe the bug
In a sidekiq job, I'm getting an error at gems/sentry-rails-4.6.5/app/jobs/sentry/send_event_job.rb:26:in:

In perform, Sentry.get_current_scope must be returning nil, resulting in:

NoMethodError: undefined method 'span' for nil:NilClass

Environment

  • Ruby Version: 2.7.4p191
  • SDK Version: 4.6.5
  • Integration Versions (if any):
  • e.g. Rails 6.1.4, Sidekiq 6.2.1

Sentry Config

This is not necessary but could be helpful.

dsn is actually not set, as I don't have SENTRY_DSN setup in my env.

Sentry.init do |config|
    config.dsn = ENV["SENTRY_DSN"]
    config.breadcrumbs_logger = [:active_support_logger, :http_logger]

    # Set tracesSampleRate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production
    config.traces_sample_rate = 0.5

    filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
    config.before_send = lambda do |event, hint|
      filter.filter(event.to_hash)
    end

    config.async = lambda do |event, hint|
      Sentry::SendEventJob.perform_later(event, hint)
    end
  end
end
@timhaines
Copy link
Author

Providing config.dsn with the actual DSN resolved this error. Perhaps jobs shouldn't attempt to be performed if the DSN is not set, and/or a better error message is surfaced?

@st0012 st0012 added this to To do in 4.x via automation Aug 20, 2021
@st0012 st0012 added this to the 4.7.0 milestone Aug 20, 2021
@st0012
Copy link
Collaborator

st0012 commented Aug 21, 2021

It looks like you have the SDK enabled in one part of your app (perhaps the Rails app?) but disabled for your worker.
Or you once enabled both of them but left unprocessed Sentry::SendEventJob before restarted the worker without DSN.

Either way, I think this exception should not happen so I'll fix it. Thanks for reporting this 👍

A slightly related suggestion: the async options is no longer recommended. If you're a new user of Sentry, I'd suggest not using it unless you find it necessary for a reason. I've detailed the reason in #1522

@timhaines
Copy link
Author

@st0012 Thanks for mentioning async is no longer recommended. I've removed it. This app is new yep, and I only added it due to seeing it in docs.

4.x automation moved this from To do to Done Aug 22, 2021
@st0012
Copy link
Collaborator

st0012 commented Aug 22, 2021

@timhaines thanks for reminding me about the doc. I'll mark async as deprecated so people don't use it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.x
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants