|
1 | 1 | use ffikit::Signal; |
2 | | -use pyroscope::backend::Tag; |
| 2 | +use pyroscope::backend::{Report, StackFrame, Tag}; |
3 | 3 | use pyroscope::PyroscopeAgent; |
4 | 4 | use pyroscope_rbspy::{rbspy_backend, RbspyConfig}; |
5 | 5 | use std::collections::hash_map::DefaultHasher; |
6 | 6 | use std::ffi::CStr; |
7 | 7 | use std::hash::Hasher; |
8 | 8 | use std::os::raw::c_char; |
9 | 9 |
|
| 10 | +pub fn transform_report(report: Report) -> Report { |
| 11 | + let data = report |
| 12 | + .data |
| 13 | + .iter() |
| 14 | + .map(|(stacktrace, count)| { |
| 15 | + let new_frames = stacktrace |
| 16 | + .frames |
| 17 | + .iter() |
| 18 | + .map(|frame| { |
| 19 | + let frame = frame.to_owned(); |
| 20 | + let regex = regex::Regex::new(r"(.+?/gems/|.+?/ruby/)").unwrap(); |
| 21 | + let new_filename = Some( |
| 22 | + regex |
| 23 | + .replace_all(frame.filename.unwrap().as_str(), "") |
| 24 | + .to_string(), |
| 25 | + ); |
| 26 | + |
| 27 | + // something |
| 28 | + StackFrame::new( |
| 29 | + frame.module, |
| 30 | + frame.name, |
| 31 | + new_filename, |
| 32 | + frame.relative_path, |
| 33 | + frame.absolute_path, |
| 34 | + frame.line, |
| 35 | + ) |
| 36 | + }) |
| 37 | + .collect(); |
| 38 | + |
| 39 | + let mut mystack = stacktrace.to_owned(); |
| 40 | + |
| 41 | + mystack.frames = new_frames; |
| 42 | + |
| 43 | + (mystack, count.to_owned()) |
| 44 | + }) |
| 45 | + .collect(); |
| 46 | + |
| 47 | + let new_report = Report::new(data).metadata(report.metadata.clone()); |
| 48 | + |
| 49 | + new_report |
| 50 | +} |
| 51 | + |
10 | 52 | #[no_mangle] |
11 | 53 | pub extern "C" fn initialize_agent( |
12 | 54 | application_name: *const c_char, server_address: *const c_char, auth_token: *const c_char, |
@@ -55,9 +97,17 @@ pub extern "C" fn initialize_agent( |
55 | 97 | let tags = string_to_tags(tags_ref); |
56 | 98 | let rbspy = rbspy_backend(rbspy_config); |
57 | 99 |
|
| 100 | + let mut regex_pattern = String::from(r""); |
| 101 | + |
| 102 | + if directory_name != String::from(".") { |
| 103 | + regex_pattern.push_str(directory_name.as_str()); |
| 104 | + regex_pattern.push_str(r"/"); |
| 105 | + } |
| 106 | + |
58 | 107 | let mut agent_builder = PyroscopeAgent::builder(server_address, application_name) |
59 | 108 | .backend(rbspy) |
60 | | - .regex(regex::Regex::new(&directory_name).unwrap()) |
| 109 | + .func(transform_report) |
| 110 | + .regex(regex::Regex::new(regex_pattern.as_str()).unwrap()) |
61 | 111 | .tags(tags); |
62 | 112 |
|
63 | 113 | if auth_token != "" { |
|
0 commit comments