Skip to content

Apply patches when initializing the SDK#1432

Merged
st0012 merged 2 commits intomasterfrom
improve-patching-method
May 5, 2021
Merged

Apply patches when initializing the SDK#1432
st0012 merged 2 commits intomasterfrom
improve-patching-method

Conversation

@st0012
Copy link
Copy Markdown
Contributor

@st0012 st0012 commented May 5, 2021

This new change has 2 benefits:

  1. It gives the SDK more control on how/when to apply the patches.
  2. By applying patches later (usually in app initialization phase), we can avoid the conflict between different patching approaches.

The 2 patching approaches are alias and prepend. When 2 gems patch the same class in this order, it'll cause "stack level too deep" error:

# gem requiring phase
prepend <- sentry-ruby
alias <- gems like scout_apm or rack-mini-profiler

After this commit, we can almost be certain that the order would be:

# gem requiring phase
alias <- gems like scout_apm or rack-mini-profiler
----
# app initialization phase
prepend <- sentry-ruby

And thus avoid the error.

This new change has 2 benefits:
1. It gives the SDK more control on how/when to apply the patches.
2. By applying patches later (usually in app initialization phase), we
   can avoid the conflict between different patching approaches.

The 2 patching approaches are `alias` and `prepend`. When 2 gems patch
the same class in this order, it'll cause "stack level too deep" error:

```
prepend <- sentry-ruby
alias <- gems like scout_apm or rack-mini-profiler
```

After this commit, we can almost be certain that the order would be:

```
alias <- gems like scout_apm or rack-mini-profiler
----
prepend <- sentry-ruby
```

And thus avoid the error.
@st0012 st0012 added this to the sentry-ruby-4.4.1 milestone May 5, 2021
@st0012 st0012 self-assigned this May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant