plain_apm 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +3 -0
- data/ext/object_tracing/extconf.rb +6 -0
- data/ext/object_tracing/object_tracing.c +25 -0
- data/lib/plain_apm/agent.rb +2 -1
- data/lib/plain_apm/extensions/thread_allocations.rb +35 -0
- data/lib/plain_apm/helpers.rb +12 -0
- data/lib/plain_apm/hooks/action_mailer.rb +1 -0
- data/lib/plain_apm/hooks/action_pack.rb +1 -0
- data/lib/plain_apm/hooks/action_view.rb +2 -1
- data/lib/plain_apm/hooks/active_job.rb +1 -0
- data/lib/plain_apm/hooks/active_record.rb +2 -1
- data/lib/plain_apm/hooks/deploy.rb +7 -1
- data/lib/plain_apm/hooks/manual.rb +30 -0
- data/lib/plain_apm/version.rb +1 -1
- data/lib/plain_apm.rb +5 -1
- metadata +23 -4
- data/lib/plain_apm/extensions/context/helpers.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d7ba5044b9386fbcbfb252e35649da1ad0b7573880510e0588323e24cf0bc11
|
4
|
+
data.tar.gz: 0ae2df2fea0bdbfc798be93a739a5b6d9144db045f38905feddd5e0975d852fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8af4f98d0e30a361e8c2aaf5ef6a3e31d5e1c533ea74b5bebcb03fde4069ef70d8ad9e8067d3c2d99bcaac0e1a73a03f847ef0b80c3ee6bea2be89c4829ec35
|
7
|
+
data.tar.gz: 007fab263d50573c67f710854ad60a6a3b4392e71599de2b6ed5f287bd63f7814e457c281f9135f130f78446b25af97be1669dcbc8d8ba731f78c16591d094ec
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@ require "bundler/gem_tasks"
|
|
4
4
|
require "appraisal"
|
5
5
|
require "standard/rake"
|
6
6
|
require "rake/testtask"
|
7
|
+
require "rake/extensiontask"
|
7
8
|
|
8
9
|
Rake::TestTask.new(:test) do |t|
|
9
10
|
t.libs << "test"
|
@@ -11,6 +12,8 @@ Rake::TestTask.new(:test) do |t|
|
|
11
12
|
t.test_files = FileList["test/**/*_test.rb"]
|
12
13
|
end
|
13
14
|
|
15
|
+
Rake::ExtensionTask.new("object_tracing")
|
16
|
+
|
14
17
|
namespace :test do
|
15
18
|
task all: "appraisal:all"
|
16
19
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#include <ruby/ruby.h>
|
2
|
+
#include <ruby/debug.h>
|
3
|
+
|
4
|
+
static __thread uint64_t allocated_objects = 0;
|
5
|
+
|
6
|
+
static VALUE rb_mPlainApm;
|
7
|
+
static VALUE rb_mObjTracing;
|
8
|
+
|
9
|
+
static VALUE total_thread_allocated_objects(VALUE self) {
|
10
|
+
return ULL2NUM(allocated_objects);
|
11
|
+
}
|
12
|
+
|
13
|
+
static void track_thread_allocated_objects(VALUE tpval, void *data) {
|
14
|
+
allocated_objects++;
|
15
|
+
}
|
16
|
+
|
17
|
+
void Init_object_tracing(void) {
|
18
|
+
rb_mPlainApm = rb_define_module("PlainApm");
|
19
|
+
rb_mObjTracing = rb_define_module_under(rb_mPlainApm, "ObjectTracing");
|
20
|
+
|
21
|
+
rb_define_module_function(rb_mObjTracing, "total_thread_allocated_objects", total_thread_allocated_objects, 0);
|
22
|
+
|
23
|
+
VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, track_thread_allocated_objects, NULL);
|
24
|
+
rb_tracepoint_enable(tpval);
|
25
|
+
}
|
data/lib/plain_apm/agent.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module PlainApm
|
2
|
+
module Extensions
|
3
|
+
module ThreadAllocations
|
4
|
+
def start!
|
5
|
+
super
|
6
|
+
@thread_allocation_count_start = now_thread_allocations
|
7
|
+
end
|
8
|
+
|
9
|
+
def finish!
|
10
|
+
super
|
11
|
+
@thread_allocation_count_finish = now_thread_allocations
|
12
|
+
end
|
13
|
+
|
14
|
+
def thread_allocations
|
15
|
+
@thread_allocation_count_finish - @thread_allocation_count_start
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
if defined?(PlainApm::ObjectTracing)
|
21
|
+
def now_thread_allocations
|
22
|
+
PlainApm::ObjectTracing.total_thread_allocated_objects
|
23
|
+
end
|
24
|
+
else
|
25
|
+
def now_thread_allocations
|
26
|
+
0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if defined?(ActiveSupport)
|
32
|
+
ActiveSupport::Notifications::Event.prepend(PlainApm::Extensions::ThreadAllocations)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PlainApm
|
2
|
+
module Helpers
|
3
|
+
def plain_apm_context(context = {})
|
4
|
+
PlainApm::Extensions::Context.context.merge!(context)
|
5
|
+
end
|
6
|
+
|
7
|
+
def plain_apm_instrument(name, context = {}, &block)
|
8
|
+
sanitized_name = name.gsub(/\W/, "_").gsub(/(?!^)([A-Z])/) { |m| "_#{m}" }.gsub(/_+/, "_").downcase
|
9
|
+
ActiveSupport::Notifications.instrument("#{sanitized_name}.manual.plain_apm", **context, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -21,7 +21,8 @@ module PlainApm
|
|
21
21
|
"backtrace" => filtered_backtrace,
|
22
22
|
"started_at" => event.time,
|
23
23
|
"finished_at" => event.end,
|
24
|
-
"allocations" => event.allocations
|
24
|
+
"allocations" => event.allocations,
|
25
|
+
"thread_allocations" => event.thread_allocations
|
25
26
|
}
|
26
27
|
|
27
28
|
case name
|
@@ -23,6 +23,7 @@ module PlainApm
|
|
23
23
|
"started_at" => event.time,
|
24
24
|
"finished_at" => event.end,
|
25
25
|
"allocations" => event.allocations,
|
26
|
+
"thread_allocations" => event.thread_allocations,
|
26
27
|
"queue_name" => job.queue_name,
|
27
28
|
"job_id" => job.job_id,
|
28
29
|
"job_class" => job.class.name,
|
@@ -23,7 +23,8 @@ module PlainApm
|
|
23
23
|
"backtrace" => filtered_backtrace,
|
24
24
|
"started_at" => event.time,
|
25
25
|
"finished_at" => event.end,
|
26
|
-
"allocations" => event.allocations
|
26
|
+
"allocations" => event.allocations,
|
27
|
+
"thread_allocations" => event.thread_allocations
|
27
28
|
}
|
28
29
|
|
29
30
|
case name
|
@@ -18,7 +18,13 @@ module PlainApm
|
|
18
18
|
tool, revision = *result
|
19
19
|
|
20
20
|
Agent.instance.collect(
|
21
|
-
{
|
21
|
+
{
|
22
|
+
"source" => tool,
|
23
|
+
"revision" => revision,
|
24
|
+
"name" => "deploy",
|
25
|
+
"started_at" => Time.now.to_f,
|
26
|
+
"finished_at" => Time.now.to_f
|
27
|
+
}
|
22
28
|
)
|
23
29
|
end
|
24
30
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PlainApm
|
4
|
+
module Hooks
|
5
|
+
class Manual < ActiveSupportSubscriber
|
6
|
+
NOTIFICATION_PATTERN = /\A[^!]\w+\.manual\.plain_apm\Z/.freeze
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def notification_pattern
|
11
|
+
NOTIFICATION_PATTERN
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload(event)
|
15
|
+
name, source, _ = *event.name.split(".")
|
16
|
+
|
17
|
+
{
|
18
|
+
"source" => source,
|
19
|
+
"name" => name,
|
20
|
+
"backtrace" => filtered_backtrace,
|
21
|
+
"started_at" => event.time,
|
22
|
+
"finished_at" => event.end,
|
23
|
+
"allocations" => event.allocations,
|
24
|
+
"thread_allocations" => event.thread_allocations,
|
25
|
+
"payload" => event.payload
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/plain_apm/version.rb
CHANGED
data/lib/plain_apm.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative "plain_apm/transport"
|
|
5
5
|
require_relative "plain_apm/config"
|
6
6
|
require_relative "plain_apm/agent"
|
7
7
|
|
8
|
+
require "object_tracing"
|
9
|
+
|
8
10
|
require_relative "plain_apm/hooks/deploy"
|
9
11
|
|
10
12
|
# Rails extensions
|
@@ -12,10 +14,11 @@ begin
|
|
12
14
|
require "rack/body_proxy"
|
13
15
|
|
14
16
|
require_relative "plain_apm/extensions/context"
|
15
|
-
require_relative "plain_apm/extensions/context/helpers"
|
16
17
|
require_relative "plain_apm/extensions/context/middleware"
|
17
18
|
require_relative "plain_apm/extensions/context/active_job" if defined?(ActiveSupport)
|
18
19
|
require_relative "plain_apm/extensions/context/railtie" if defined?(Rails::Railtie)
|
20
|
+
require_relative "plain_apm/extensions/thread_allocations"
|
21
|
+
require_relative "plain_apm/helpers"
|
19
22
|
rescue LoadError
|
20
23
|
nil
|
21
24
|
end
|
@@ -31,6 +34,7 @@ require_relative "plain_apm/hooks/action_pack"
|
|
31
34
|
require_relative "plain_apm/hooks/action_view"
|
32
35
|
require_relative "plain_apm/hooks/active_job"
|
33
36
|
require_relative "plain_apm/hooks/active_record"
|
37
|
+
require_relative "plain_apm/hooks/manual"
|
34
38
|
require_relative "plain_apm/hooks/error_reporter"
|
35
39
|
|
36
40
|
module PlainApm
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PlainAPM Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +84,8 @@ description: Ruby gem to collect events/metrics and send them to PlainAPM.
|
|
70
84
|
email:
|
71
85
|
- support@plainapm.com
|
72
86
|
executables: []
|
73
|
-
extensions:
|
87
|
+
extensions:
|
88
|
+
- ext/object_tracing/extconf.rb
|
74
89
|
extra_rdoc_files: []
|
75
90
|
files:
|
76
91
|
- CHANGELOG.md
|
@@ -78,6 +93,8 @@ files:
|
|
78
93
|
- LICENSE.txt
|
79
94
|
- README.md
|
80
95
|
- Rakefile
|
96
|
+
- ext/object_tracing/extconf.rb
|
97
|
+
- ext/object_tracing/object_tracing.c
|
81
98
|
- lib/plain_apm.rb
|
82
99
|
- lib/plain_apm/agent.rb
|
83
100
|
- lib/plain_apm/backoff.rb
|
@@ -85,12 +102,13 @@ files:
|
|
85
102
|
- lib/plain_apm/extensions/context.rb
|
86
103
|
- lib/plain_apm/extensions/context/LICENSE.txt
|
87
104
|
- lib/plain_apm/extensions/context/active_job.rb
|
88
|
-
- lib/plain_apm/extensions/context/helpers.rb
|
89
105
|
- lib/plain_apm/extensions/context/middleware.rb
|
90
106
|
- lib/plain_apm/extensions/context/railtie.rb
|
91
107
|
- lib/plain_apm/extensions/exceptions/active_job.rb
|
92
108
|
- lib/plain_apm/extensions/exceptions/rack.rb
|
93
109
|
- lib/plain_apm/extensions/exceptions/railtie.rb
|
110
|
+
- lib/plain_apm/extensions/thread_allocations.rb
|
111
|
+
- lib/plain_apm/helpers.rb
|
94
112
|
- lib/plain_apm/hooks/action_mailer.rb
|
95
113
|
- lib/plain_apm/hooks/action_pack.rb
|
96
114
|
- lib/plain_apm/hooks/action_view.rb
|
@@ -99,6 +117,7 @@ files:
|
|
99
117
|
- lib/plain_apm/hooks/active_support_subscriber.rb
|
100
118
|
- lib/plain_apm/hooks/deploy.rb
|
101
119
|
- lib/plain_apm/hooks/error_reporter.rb
|
120
|
+
- lib/plain_apm/hooks/manual.rb
|
102
121
|
- lib/plain_apm/transport.rb
|
103
122
|
- lib/plain_apm/version.rb
|
104
123
|
homepage: https://plainapm.com
|