-
Notifications
You must be signed in to change notification settings - Fork 373
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
RFC: Add helper to easily enable core dumps #2010
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
21ad3b9
RFC: Add helper to easily enable core dumps
ivoanjo 14afd4d
Make sure sorbet doesn't try to load enable_core_dumps
ivoanjo e368f5d
Add specs for enable_core_dumps helper
ivoanjo 274d505
Move helper to datadog/kit/enable_core_dumps
ivoanjo d910b2a
Scope `enable_core_dumps` helper in an actual module
ivoanjo 8c24368
Disable sorbet for file, doesn't work in this case
ivoanjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This helper is used to enable core dumps for the current Ruby app. This is useful when debugging native-level | ||
# crashes. | ||
# | ||
# It can be enabled simply by adding `require 'datadog/enable_core_dumps'` to start of the app. | ||
|
||
lambda do | ||
lloeki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
current_size, maximum_size = Process.getrlimit(:CORE) | ||
core_pattern = | ||
begin | ||
File.read('/proc/sys/kernel/core_pattern').strip | ||
rescue | ||
'(Could not open /proc/sys/kernel/core_pattern)' | ||
end | ||
|
||
if maximum_size <= 0 | ||
Kernel.warn("[DDTRACE] Could not enable core dumps on crash, maximum size is #{maximum_size} (disabled).") | ||
return | ||
elsif maximum_size == current_size | ||
Kernel.warn('[DDTRACE] Core dumps already enabled, nothing to do!') | ||
return | ||
end | ||
|
||
begin | ||
Process.setrlimit(:CORE, maximum_size) | ||
rescue => e | ||
Kernel.warn( | ||
"[DDTRACE] Failed to enable core dumps. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}" | ||
) | ||
return | ||
end | ||
|
||
if current_size == 0 | ||
Kernel.warn("[DDTRACE] Enabled core dumps. Maximum size: #{maximum_size} Output pattern: '#{core_pattern}'") | ||
else | ||
Kernel.warn( | ||
"[DDTRACE] Raised core dump limit. Old size: #{current_size} " \ | ||
"Maximum size: #{maximum_size} Output pattern: '#{core_pattern}'" | ||
) | ||
end | ||
end.call |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a significant side effect, so it needs
# typed: ignore
otherwise Sorbet will evaluate the file!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 14afd4d