app_profiler 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/app_profiler/middleware.rb +29 -0
- data/lib/app_profiler/railtie.rb +2 -0
- data/lib/app_profiler/version.rb +1 -1
- data/lib/app_profiler.rb +11 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e78035c478029d4ad4de636efab44240957c2bd05ea761dc9fe28b753b4fa1d3
|
4
|
+
data.tar.gz: c4d6659a31eaa7440c6c8a2550c9cf41fbadb567426cae7c6bd0cd4442e8039a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45610912af0b6952b2c104d27bfc3bf2b37b92f91d2c873bdf9e2bfc43498529decf9568af63b9ee47d84794dd921dbf6312de11aac272be296f99416d5f2b31
|
7
|
+
data.tar.gz: 29ee1a661cc8c81274fbdb7f6123ce90d7dbeaa351ca3b16a8a6bfe933ec3f68385bfe0f2d0afb2ae6c49ba59fa318d733bd23d6cf7724a3d03f1246e36b65ca
|
@@ -7,6 +7,11 @@ require "app_profiler/middleware/view_action"
|
|
7
7
|
|
8
8
|
module AppProfiler
|
9
9
|
class Middleware
|
10
|
+
OTEL_PROFILE_ID = "profile.id"
|
11
|
+
OTEL_PROFILE_BACKEND = "profile.profiler"
|
12
|
+
OTEL_PROFILE_MODE = "profile.mode"
|
13
|
+
OTEL_PROFILE_CONTEXT = "profile.context"
|
14
|
+
|
10
15
|
class_attribute :action, default: UploadAction
|
11
16
|
class_attribute :disabled, default: false
|
12
17
|
|
@@ -29,8 +34,11 @@ module AppProfiler
|
|
29
34
|
return yield unless app_profiler_params
|
30
35
|
|
31
36
|
params_hash = app_profiler_params.to_h
|
37
|
+
|
32
38
|
return yield unless before_profile(env, params_hash)
|
33
39
|
|
40
|
+
add_otel_instrumentation(env, params_hash) if AppProfiler.otel_instrumentation_enabled
|
41
|
+
|
34
42
|
profile = AppProfiler.run(**params_hash) do
|
35
43
|
response = yield
|
36
44
|
end
|
@@ -47,6 +55,27 @@ module AppProfiler
|
|
47
55
|
response
|
48
56
|
end
|
49
57
|
|
58
|
+
def add_otel_instrumentation(env, params)
|
59
|
+
rack_span = OpenTelemetry::Instrumentation::Rack.current_span
|
60
|
+
return unless rack_span.recording?
|
61
|
+
|
62
|
+
metadata = params[:metadata]
|
63
|
+
profile_id = if metadata[:id].present?
|
64
|
+
metadata[:id]
|
65
|
+
else
|
66
|
+
AppProfiler::ProfileId.current
|
67
|
+
end
|
68
|
+
|
69
|
+
attributes = {
|
70
|
+
OTEL_PROFILE_ID => profile_id,
|
71
|
+
OTEL_PROFILE_BACKEND => params[:backend].to_s,
|
72
|
+
OTEL_PROFILE_MODE => params[:mode].to_s,
|
73
|
+
OTEL_PROFILE_CONTEXT => AppProfiler.context,
|
74
|
+
}
|
75
|
+
|
76
|
+
rack_span.add_attributes(attributes)
|
77
|
+
end
|
78
|
+
|
50
79
|
def profile_params(params)
|
51
80
|
return params if params.valid?
|
52
81
|
return unless AppProfiler.profile_sampler_enabled
|
data/lib/app_profiler/railtie.rb
CHANGED
@@ -51,6 +51,8 @@ module AppProfiler
|
|
51
51
|
AppProfiler.profile_sampler_enabled = app.config.app_profiler.profile_sampler_enabled || false
|
52
52
|
AppProfiler.profile_sampler_config = app.config.app_profiler.profile_sampler_config ||
|
53
53
|
AppProfiler::Sampler::Config.new
|
54
|
+
|
55
|
+
AppProfiler.otel_instrumentation_enabled = app.config.app_profiler.otel_instrumentation_enabled || false
|
54
56
|
end
|
55
57
|
|
56
58
|
initializer "app_profiler.add_middleware" do |app|
|
data/lib/app_profiler/version.rb
CHANGED
data/lib/app_profiler.rb
CHANGED
@@ -76,6 +76,8 @@ module AppProfiler
|
|
76
76
|
mattr_reader :profile_file_name
|
77
77
|
|
78
78
|
class << self
|
79
|
+
attr_reader :otel_instrumentation_enabled
|
80
|
+
|
79
81
|
def deprecator # :nodoc:
|
80
82
|
@deprecator ||= ActiveSupport::Deprecation.new("in future releases", "app_profiler")
|
81
83
|
end
|
@@ -162,6 +164,15 @@ module AppProfiler
|
|
162
164
|
false
|
163
165
|
end
|
164
166
|
|
167
|
+
def otel_instrumentation_enabled=(value)
|
168
|
+
if value
|
169
|
+
gem("opentelemetry-instrumentation-rack")
|
170
|
+
require("opentelemetry/instrumentation/rack")
|
171
|
+
end
|
172
|
+
|
173
|
+
@otel_instrumentation_enabled = value
|
174
|
+
end
|
175
|
+
|
165
176
|
def backend_for(backend_name)
|
166
177
|
if vernier_supported? &&
|
167
178
|
backend_name&.to_sym == AppProfiler::VernierProfile::BACKEND_NAME
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gannon McGibbon
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
- Scott Francis
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2025-02-
|
15
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -112,6 +112,20 @@ dependencies:
|
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: opentelemetry-instrumentation-rack
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
115
129
|
- !ruby/object:Gem::Dependency
|
116
130
|
name: rake
|
117
131
|
requirement: !ruby/object:Gem::Requirement
|