# Ricorsione Stack Infinita quando si usa Sentry

**URL:** https://meta.discourse.org/t/infinite-stack-recursion-when-using-sentry/254639
**Category:** Self-hosting
**Tags:** unsupported-install
**Created:** [9 Febbraio 2023, 4:23pm UTC](https://meta.discourse.org/t/infinite-stack-recursion-when-using-sentry/254639 "2023-02-09T16:23:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![saulshanabrook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saulshanabrook/32/292864_2.png) [@saulshanabrook](https://meta.discourse.org/u/saulshanabrook)
#### Post date: [9 Febbraio 2023, 4:23pm UTC](https://meta.discourse.org/t/infinite-stack-recursion-when-using-sentry/254639/1 "2023-02-09T16:23:20Z")

</div>

Ciao!

Volevo scrivere qui per vedere se qualcuno avesse idee su questo bug che sto riscontrando quando provo a usare Sentry con Discourse. Sto cercando di usare Sentry (usando l’[implementazione open source del server Glitchtip](https://glitchtip.com/)) per raccogliere tutti gli errori generati nei task in background e nel server. So che Discourse ha la sua raccolta errori con Logster, ma volevo provare a usare Sentry per aiutare a tracciare tutti gli errori generati e ispezionarli con più contesto.

Ho aggiunto un inizializzatore con la configurazione di Sentry:

```ruby
Sentry.init do |config|
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]

  config.dsn = ENV['SENTRY_DSN']
end

```

e ho scoperto che stava ricorsivamente all’infinito durante le chiamate HTTP dei task rake e dei task sidekiq (anche se uscivano in modo pulito prima che Sentry venisse aggiunto). Ci sono maggiori dettagli e un modo per riprodurre sul problema di Github che ho aperto con sentry-ruby:

> <https://github.com/getsentry/sentry-ruby/issues/1999>
>
> \### Issue Description
> 
> Hello!
> 
> I am coming across an error trying to use the… sentry ruby bindings on with a rails app, during a rake task. The task uploads the precompiled assets to an S3 server. It exits cleanly without the sentry integration, but when I add it, it enters into an infinitely recursive loop with the patched HTTP module. I am not sure how to debug this further or what to do.
> 
> Thank you!
> 
> \### Reproduction Steps
> 
> \*\*edited with simpler steps\*\*:
> \`\`\`bash
> $ git clone https://github.com/saulshanabrook/discourse-hosting
> $ cd discourse-hosting
> $ echo 'HOSTNAME=any-domain.com' \> .env
> $ docker compose run --rm upload\_assets
> \`\`\`
> 
> Following the steps of https://github.com/saulshanabrook/discourse-hosting#local-development-with-docker-compose the error will be raised when running \`docker compose run --rm upload\_assets\`:
> 
> 
> 
> \### Expected Behavior
> 
> The command exits cleanly without an error
> 
> \### Actual Behavior
> 
> It raises a \`SystemStackError\`:
> 
> 
> \`\`\`ruby
> $ docker compose run --rm upload\_assets
> \[+\] Running 4/0
> ⠿ Container discourse-hosting-db-1 Running 0.0s
> ⠿ Container discourse-hosting-minio-1 Running 0.0s
> ⠿ Container discourse-hosting-redis-1 Running 0.0s
> ⠿ Container discourse-hosting-glitchtip-web-1 Running 0.0s
> \*\* Invoke s3:upload\_assets (first\_time)
> \*\* Invoke environment (first\_time)
> \*\* Execute environment
> \*\* Invoke s3:ensure\_cors\_rules (first\_time)
> \*\* Invoke environment 
> \*\* Execute s3:ensure\_cors\_rules
> \*\* Execute s3:upload\_assets
> rake aborted!
> SystemStackError: stack level too deep
> ...
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:35:in \`block in request'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/hub.rb:100:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry-ruby.rb:446:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:32:in \`request'
> (eval):5:in \`request'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:35:in \`block in request'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/hub.rb:100:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry-ruby.rb:446:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:32:in \`request'
> (eval):5:in \`request'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:35:in \`block in request'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/hub.rb:100:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry-ruby.rb:446:in \`with\_child\_span'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/net/http.rb:32:in \`request'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/connection\_pool.rb:348:in \`request'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/handler.rb:79:in \`block in transmit'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/handler.rb:133:in \`block in session'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/connection\_pool.rb:104:in \`session\_for'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/handler.rb:128:in \`session'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/handler.rb:76:in \`transmit'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/net\_http/handler.rb:50:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/plugins/content\_length.rb:24:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/plugins/request\_callback.rb:85:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/s3\_signer.rb:132:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/s3\_signer.rb:63:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/s3\_host\_id.rb:17:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/xml/error\_handler.rb:10:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/transfer\_encoding.rb:26:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/helpful\_socket\_errors.rb:12:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/s3\_signer.rb:110:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/redirects.rb:20:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/retry\_errors.rb:360:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/http\_checksum.rb:19:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/endpoint\_pattern.rb:30:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/accelerate.rb:67:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/checksum\_algorithm.rb:136:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/bucket\_dns.rb:35:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/dualstack.rb:41:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/expect\_100\_continue.rb:22:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/bucket\_name\_restrictions.rb:26:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/arn.rb:62:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/rest/handler.rb:10:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/recursion\_detection.rb:18:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/user\_agent.rb:13:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/plugins/endpoint.rb:47:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/param\_validator.rb:26:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/arn.rb:88:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/sse\_cpk.rb:24:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/dualstack.rb:27:in \`call'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/plugins/accelerate.rb:56:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/checksum\_algorithm.rb:111:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/jsonvalue\_converter.rb:22:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/idempotency\_token.rb:19:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/param\_converter.rb:26:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/plugins/request\_callback.rb:71:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/plugins/response\_paging.rb:12:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/plugins/response\_target.rb:24:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/seahorse/client/request.rb:72:in \`send\_request'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/poller.rb:65:in \`send\_request'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/poller.rb:51:in \`call'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:107:in \`block in poll'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:104:in \`loop'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:104:in \`poll'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:94:in \`block (2 levels) in wait'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:93:in \`catch'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:93:in \`block in wait'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:92:in \`catch'
> /usr/local/bundle/gems/aws-sdk-core-3.130.2/lib/aws-sdk-core/waiters/waiter.rb:92:in \`wait'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/waiters.rb:123:in \`wait'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/bucket.rb:98:in \`wait\_until\_exists'
> /usr/local/bundle/gems/aws-sdk-s3-1.114.0/lib/aws-sdk-s3/bucket.rb:79:in \`exists?'
> /var/www/discourse/lib/s3\_helper.rb:404:in \`s3\_bucket'
> /var/www/discourse/lib/s3\_helper.rb:240:in \`list'
> /var/www/discourse/lib/tasks/s3.rake:14:in \`existing\_assets'
> /var/www/discourse/lib/tasks/s3.rake:24:in \`should\_skip?'
> /var/www/discourse/lib/tasks/s3.rake:36:in \`upload'
> /var/www/discourse/lib/tasks/s3.rake:192:in \`block (2 levels) in \<main\>'
> /var/www/discourse/lib/tasks/s3.rake:192:in \`each'
> /var/www/discourse/lib/tasks/s3.rake:192:in \`block in \<main\>'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in \`block in execute'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in \`each'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in \`execute'
> /usr/local/bundle/gems/sentry-ruby-5.8.0/lib/sentry/rake.rb:26:in \`execute'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in \`block in invoke\_with\_call\_chain'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in \`synchronize'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in \`invoke\_with\_call\_chain'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in \`invoke'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in \`invoke\_task'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in \`block (2 levels) in top\_level'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in \`each'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in \`block in top\_level'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in \`run\_with\_threads'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in \`top\_level'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:83:in \`block in run'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in \`standard\_exception\_handling'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:80:in \`run'
> /usr/local/lib/ruby/gems/3.1.0/gems/rake-13.0.6/exe/rake:27:in \`\<top (required)\>'
> /usr/local/bin/rake:25:in \`load'
> /usr/local/bin/rake:25:in \`\<top (required)\>'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:58:in \`load'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:58:in \`kernel\_load'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli/exec.rb:23:in \`run'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli.rb:486:in \`exec'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/command.rb:27:in \`run'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in \`invoke\_command'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor.rb:392:in \`dispatch'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli.rb:31:in \`dispatch'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/vendor/thor/lib/thor/base.rb:485:in \`start'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/cli.rb:25:in \`start'
> /usr/local/bundle/gems/bundler-2.3.22/exe/bundle:48:in \`block in \<top (required)\>'
> /usr/local/bundle/gems/bundler-2.3.22/lib/bundler/friendly\_errors.rb:120:in \`with\_friendly\_errors'
> /usr/local/bundle/gems/bundler-2.3.22/exe/bundle:36:in \`\<top (required)\>'
> /usr/local/bundle/bin/bundle:25:in \`load'
> /usr/local/bundle/bin/bundle:25:in \`\<main\>'
> Tasks: TOP =\> s3:upload\_assets
> \`\`\`
> 
> \### Ruby Version
> 
> 3.1
> 
> \### SDK Version
> 
> sentry-ruby-5.8.0
> 
> \### Integration and Its Version
> 
> \_No response\_
> 
> \### Sentry Config
> 
> \`\`\`ruby
> Sentry.init do |config|
> 
> # this gem also provides a new breadcrumb logger that accepts instrumentations from ActiveSupport
> # it's not activated by default, but you can enable it with
> # config.breadcrumbs\_logger = \[:active\_support\_logger\]
> 
> config.dsn = ENV\['SENTRY\_DSN'\]
> end
> \`\`\`

So che non sto usando il repository supportato `discourse_docker`, ma volevo comunque scrivere qui per vedere se qualcun altro avesse riscontrato un errore simile e avesse qualche idea.

Nota che esiste già un plugin Sentry per Discourse ([Discourse Sentry](https://meta.discourse.org/t/discourse-sentry/109187)), ma utilizza una libreria client non supportata (`sentry-raven`), quindi ho scelto di non usarla.

---

<div class="post-metadata">

### Author: ![saulshanabrook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saulshanabrook/32/292864_2.png) [@saulshanabrook](https://meta.discourse.org/u/saulshanabrook)
#### Post date: [13 Febbraio 2023, 6:37pm UTC](https://meta.discourse.org/t/infinite-stack-recursion-when-using-sentry/254639/2 "2023-02-13T18:37:07Z")

</div>

Per chiunque sia interessato a utilizzare Sentry con Discourse, uno dei manutentori del pacchetto [ha risposto con una correzione suggerita](https://github.com/getsentry/sentry-ruby/issues/1999#issuecomment-1427136936).

Hanno affermato che il problema proveniva da `MethodProfiler` di Discourse [che utilizza `alias_method`](https://github.com/discourse/discourse/blob/main/lib/method_profiler.rb#L16-L33). Hanno suggerito di sostituirlo con `prepend` che, a loro dire, stava diventando più comune e avrebbe permesso a entrambi gli strumenti di lavorare insieme.

Non ho abbastanza familiarità con Ruby per capire le differenze. Per ora, proverò a commentare questa parte di codice per disabilitare il profiling dei metodi di Discourse.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [15 Marzo 2023, 6:37pm UTC](https://meta.discourse.org/t/infinite-stack-recursion-when-using-sentry/254639/3 "2023-03-15T18:37:16Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
