-
Notifications
You must be signed in to change notification settings - Fork 401
DI: add a C extension #5111
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
Merged
DI: add a C extension #5111
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6366dc5
create ddsketch.h like the other components
p 6d92220
runtime iseqs
p 39b2d27
exception_message
p 94aa14a
remove wip require
p fa6a15f
rakefile bits
p a66b254
steep standard
p fecec13
Remove ddsketch.h and di.h, inline forward declarations in init.c
p-ddsign 0676421
Consolidate C helper files into di.c and datadog_ruby_common.h
p-ddsign 5a2463a
Simplify all_iseqs and move consumer-side docs to lib/datadog/di.rb
p-ddsign 897bf2c
Fix trailing whitespace and add @return tag to file_iseqs
p-ddsign 4ef85c9
Sync datadog_ruby_common.h between profiling and libdatadog_api exten…
p-ddsign e2d57cd
Populate throwable in method probe snapshots using exception_message
p-ddsign b3ef61d
Rename 'raw' variable to 'msg' to fix semgrep false positive
p-ddsign b7bbee2
Add error boundary around probe_executed_callback in method probes
p-ddsign e0230ed
Handle nil exception constructor argument in serialize_throwable
p-ddsign 7ec9f32
Handle nil exception message and document exception reporting caveats
p-ddsign 390db62
Add integration test for method probe exception throwable capture
p-ddsign a7a8a51
Address review findings: YARD tags, logger verification, freeze constant
p-ddsign 1e70fd3
Require C extension for DI; remove fallback code paths
p-ddsign 0eb8f18
Move all DI specs to di_with_ext task (requires C extension)
p-ddsign a2e53d7
Skip DI component test in spec:main when C extension unavailable
p-ddsign 5a2b108
Add test for DI disabled when C extension is absent on MRI
p-ddsign 4bbff23
Return redacted placeholder for non-string exception constructor args
p-ddsign 6eabbe0
Improve "Application Data Sent to Datadog" docs section
p-ddsign 3e7d756
Merge branch 'master' into di-c-ext
p-datadog 0d1c652
Add stacktrace to throwable in method probe snapshots
p-ddsign 933923f
Return empty array instead of nil for throwable stacktrace
p-ddsign 12ea888
Add di_with_ext to Matrixfile; fix throwable integration test
p-ddsign 98b25fe
Revert "Add di_with_ext to Matrixfile; fix throwable integration test"
p-ddsign e8ae9f7
Add di_with_ext to Matrixfile
p-ddsign e663a39
Fix throwable integration test to include stacktrace
p-ddsign b162e3d
Restore original error message assertion after cherry-pick
p-ddsign dde515f
Fix di_with_ext task name in Matrixfile and spec:all
p-ddsign 15dc3eb
Exclude DI contrib specs from di_with_ext task
p-ddsign b6577c2
Fix StandardRB style: use double-quoted symbol
p-ddsign 6d63f39
Extract backtrace frame regex into named constant
p-ddsign 3539fa7
Fix Steep type check: add missing BACKTRACE_FRAME_PATTERN RBS declara…
p-ddsign 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,79 @@ | ||
| #include <stdbool.h> | ||
|
|
||
| #include "datadog_ruby_common.h" | ||
|
|
||
| // Prototypes for Ruby functions declared in internal Ruby headers. | ||
| VALUE rb_iseqw_new(const void *iseq); | ||
| int rb_objspace_internal_object_p(VALUE obj); | ||
| void rb_objspace_each_objects( | ||
| int (*callback)(void *start, void *end, size_t stride, void *data), | ||
| void *data); | ||
|
|
||
| #define IMEMO_TYPE_ISEQ 7 | ||
|
|
||
| // The ID value of the string "mesg" which is used in Ruby source as | ||
| // id_mesg or idMesg, and is used to set and retrieve the exception message | ||
| // from standard library exception classes like NameError. | ||
| static ID id_mesg; | ||
|
|
||
| // Returns whether the argument is an IMEMO of type ISEQ. | ||
| static bool ddtrace_imemo_iseq_p(VALUE v) { | ||
| return rb_objspace_internal_object_p(v) && RB_TYPE_P(v, T_IMEMO) && ddtrace_imemo_type(v) == IMEMO_TYPE_ISEQ; | ||
| } | ||
|
|
||
| static int ddtrace_di_os_obj_of_i(void *vstart, void *vend, size_t stride, void *data) | ||
| { | ||
| VALUE *array = (VALUE *)data; | ||
|
|
||
| VALUE v = (VALUE)vstart; | ||
| for (; v != (VALUE)vend; v += stride) { | ||
| if (ddtrace_imemo_iseq_p(v)) { | ||
| VALUE iseq = rb_iseqw_new((void *) v); | ||
| rb_ary_push(*array, iseq); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /* | ||
| Returns all RubyVM::InstructionSequence objects existing in the current process. | ||
|
|
||
| This uses the same approach as ruby/debug's iseq_collector.c: | ||
| https://github.com/ruby/debug/blob/master/ext/debug/iseq_collector.c | ||
| */ | ||
| static VALUE all_iseqs(DDTRACE_UNUSED VALUE _self) { | ||
| VALUE array = rb_ary_new(); | ||
| rb_objspace_each_objects(ddtrace_di_os_obj_of_i, &array); | ||
| return array; | ||
| } | ||
|
|
||
| /* | ||
| * call-seq: | ||
| * DI.exception_message(exception) -> String | Object | ||
| * | ||
| * Returns the exception message associated with the exception via the | ||
| * exception's constructor. | ||
| * | ||
| * This method does not invoke Ruby code and as such will not call | ||
| * the +message+ method, if one is defined on the exception object. | ||
| * | ||
| * Normally, the exception message is a string, however there is no | ||
| * type enforcement done by Ruby for the messages and objects of arbitrary | ||
| * classes can be passed to exception constructors and will, subsequently, | ||
| * be returned by this method. | ||
| * | ||
| * @param exception [Exception] The exception object | ||
| * @return [String | Object] The exception message | ||
| */ | ||
| static VALUE exception_message(DDTRACE_UNUSED VALUE _self, VALUE exception) { | ||
| return rb_ivar_get(exception, id_mesg); | ||
| } | ||
|
|
||
| void di_init(VALUE datadog_module) { | ||
| id_mesg = rb_intern("mesg"); | ||
|
|
||
| VALUE di_module = rb_define_module_under(datadog_module, "DI"); | ||
| rb_define_singleton_method(di_module, "all_iseqs", all_iseqs, 0); | ||
| rb_define_singleton_method(di_module, "exception_message", exception_message, 1); | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.