skylight-core 4.2.1 → 4.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c4b136b3f461ff94a6d693a2b1aca9c63c178e4bd3db96101ad667cfe54441e
4
- data.tar.gz: fc5d2e143f1c03184d8ae05cbca803c5e27320ed070a04f7eff13101f4b29023
3
+ metadata.gz: 2030258255754028163967778c9b3ca8ab63a2971e7037c29d99d1cc34ae4b36
4
+ data.tar.gz: 746fd493621405f7f443a40150722a1b018b0a6ace05421bff3c9ce5069d9bad
5
5
  SHA512:
6
- metadata.gz: 9e9ed8c974221845ad2724cbedf5deea98a51519a3d098b6d9f5309e6660f6f0327ad6435fd5bf8e420bc3b474e377ab732e4a6fa90b80fac53f222ec16996e2
7
- data.tar.gz: dff09e0c589d7e2d84eba7c7e5baf8edc294dd44717a5fda4cc2d1effeb9e58adb28fce645176c4d6fcd7c48a4c5ae30db6145e9c5d97367ad92e8e0c7101a24
6
+ metadata.gz: 4acc9a1b9d9f299fd609a75f2f0f51608e4f26d7aa30ef5748db41c04177aa5c399ea384085218781ceb85f023542a05617009e2c70c0de7fb2a2106163f2299
7
+ data.tar.gz: c9ac1d3ac95a970827bd1a3e9a4264ef78be0bb39af9754e380de82ac7e8839e9ec4cecc2bcbc0e3d06397e9c09c6d1567caa51bfb5612f53ae2195e5434044e
@@ -98,6 +98,7 @@ module Skylight::Core
98
98
  action_view/render_collection
99
99
  action_view/render_partial
100
100
  action_view/render_template
101
+ action_view/render_layout
101
102
  active_job/perform
102
103
  active_model_serializers/render
103
104
  active_record/instantiation
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skylight
4
+ module Core
5
+ module Normalizers
6
+ module ActionView
7
+ # Normalizer for Rails layout rendering
8
+ class RenderLayout < RenderNormalizer
9
+ register "render_layout.action_view"
10
+
11
+ CAT = "view.render.layout"
12
+
13
+ # @param trace [Skylight::Messages::Trace::Builder] ignored, only present to match API
14
+ # @param name [String] ignored, only present to match API
15
+ # @param payload (see RenderNormalizer#normalize_render)
16
+ # @option payload (see RenderNormalizer#normalize_render)
17
+ # @return (see RenderNormalizer#normalize_render)
18
+ def normalize(_trace, _name, payload)
19
+ normalize_render(CAT, payload)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -25,7 +25,8 @@ module Skylight::Core
25
25
  end
26
26
 
27
27
  def get_namespace(endpoint)
28
- ::Grape::Namespace.joined_space(endpoint.namespace_stackable(:namespace))
28
+ # slice off preceding slash for data continuity
29
+ ::Grape::Namespace.joined_space_path(endpoint.namespace_stackable(:namespace)).to_s[1..-1]
29
30
  end
30
31
  end
31
32
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/inflector"
4
+
3
5
  module Skylight::Core::Normalizers::GraphQL
4
6
  # Some AS::N events in GraphQL are not super useful.
5
7
  # We are purposefully ignoring the following keys (and you probably shouldn't add them):
@@ -11,25 +13,61 @@ module Skylight::Core::Normalizers::GraphQL
11
13
  ANONYMOUS = "[anonymous]".freeze
12
14
  CAT = "app.graphql".freeze
13
15
 
14
- def normalize(_trace, name, _payload)
15
- [CAT, name, nil]
16
+ if defined?(::GraphQL::VERSION) && Gem::Version.new(::GraphQL::VERSION) >= Gem::Version.new("1.10")
17
+ def self.register_graphql
18
+ register("#{key}.graphql")
19
+ end
20
+ else
21
+ def self.register_graphql
22
+ register("graphql.#{key}")
23
+ end
24
+ end
25
+
26
+ def self.inherited(klass)
27
+ klass.const_set(
28
+ :KEY,
29
+ ActiveSupport::Inflector.underscore(
30
+ ActiveSupport::Inflector.demodulize(klass.name)
31
+ ).freeze
32
+ )
33
+ end
34
+
35
+ def self.key
36
+ self::KEY
16
37
  end
38
+
39
+ def normalize(_trace, _name, _payload)
40
+ [CAT, "graphql.#{key}", nil]
41
+ end
42
+
43
+ private
44
+
45
+ def key
46
+ self.class.key
47
+ end
48
+
49
+ def extract_query_name(query)
50
+ query&.context&.[](:skylight_endpoint) ||
51
+ query&.operation_name ||
52
+ ANONYMOUS
53
+ end
17
54
  end
18
55
 
19
56
  class Lex < Base
20
- register "graphql.lex"
57
+ register_graphql
21
58
  end
22
59
 
23
60
  class Parse < Base
24
- register "graphql.parse"
61
+ register_graphql
25
62
  end
26
63
 
27
64
  class Validate < Base
28
- register "graphql.validate"
65
+ register_graphql
29
66
  end
30
67
 
31
68
  class ExecuteMultiplex < Base
32
- register "graphql.execute_multiplex"
69
+ register_graphql
70
+
33
71
  def normalize_after(trace, _span, _name, payload)
34
72
  # This is in normalize_after because the queries may not have
35
73
  # an assigned operation name before they are executed.
@@ -44,7 +82,7 @@ module Skylight::Core::Normalizers::GraphQL
44
82
  # has not been done yet at the point where execute_multiplex starts.
45
83
  # [1] https://graphql.org/learn/serving-over-http/#post-request
46
84
  queries, has_errors = payload[:multiplex].queries.each_with_object([Set.new, Set.new]) do |query, (names, errors)|
47
- names << (query.operation_name || ANONYMOUS)
85
+ names << extract_query_name(query)
48
86
  errors << query.static_errors.any?
49
87
  end
50
88
 
@@ -58,14 +96,14 @@ module Skylight::Core::Normalizers::GraphQL
58
96
  end
59
97
 
60
98
  class AnalyzeQuery < Base
61
- register "graphql.analyze_query"
99
+ register_graphql
62
100
  end
63
101
 
64
102
  class ExecuteQuery < Base
65
- register "graphql.execute_query"
103
+ register_graphql
66
104
 
67
- def normalize(trace, name, payload)
68
- query_name = payload[:query]&.operation_name || ANONYMOUS
105
+ def normalize(trace, _name, payload)
106
+ query_name = extract_query_name(payload[:query])
69
107
 
70
108
  if query_name == ANONYMOUS
71
109
  meta = { mute_children: true }
@@ -75,18 +113,18 @@ module Skylight::Core::Normalizers::GraphQL
75
113
  # but in the case of a single query, it will be the same value anyway.
76
114
  trace.endpoint = "graphql:#{query_name}"
77
115
 
78
- [CAT, "#{name}: #{query_name}", nil, meta]
116
+ [CAT, "graphql.#{key}: #{query_name}", nil, meta]
79
117
  end
80
118
  end
81
119
 
82
120
  class ExecuteQueryLazy < ExecuteQuery
83
- register "graphql.execute_query_lazy"
121
+ register_graphql
84
122
 
85
- def normalize(trace, name, payload)
123
+ def normalize(trace, _name, payload)
86
124
  if payload[:query]
87
125
  super
88
126
  elsif payload[:multiplex]
89
- [CAT, "#{name}.multiplex", nil]
127
+ [CAT, "graphql.#{key}.multiplex", nil]
90
128
  end
91
129
  end
92
130
  end
@@ -27,6 +27,13 @@ module Skylight::Core
27
27
  elsif respond_to?(:rendered_format) && rendered_format
28
28
  rendered_format
29
29
  end
30
+ rescue
31
+ # There are cases in which actionpack can return
32
+ # a stringified representation of a Mime::NullType instance,
33
+ # which is invalid for a number of reasons. This string raises
34
+ # errors when piped through Mime::Type.lookup, so it's probably
35
+ # best to just return nil in those cases.
36
+ nil
30
37
  end
31
38
  end
32
39
  end
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Skylight::Core
2
4
  module Probes
3
5
  module ActionView
4
6
  class Probe
5
7
  def install
8
+ return if ::ActionView.gem_version >= Gem::Version.new("6.1.0.alpha")
9
+
6
10
  ::ActionView::TemplateRenderer.class_eval do
7
11
  alias_method :render_with_layout_without_sk, :render_with_layout
8
12
 
@@ -3,35 +3,36 @@
3
3
  module Skylight::Core
4
4
  module Probes
5
5
  module GraphQL
6
+ module Instrumentation
7
+ def initialize(*, **)
8
+ super
9
+
10
+ return unless defined?(@tracers)
11
+
12
+ unless @tracers.include?(::GraphQL::Tracing::ActiveSupportNotificationsTracing)
13
+ @tracers << ::GraphQL::Tracing::ActiveSupportNotificationsTracing
14
+ end
15
+ end
16
+ end
17
+
6
18
  class Probe
7
19
  def install
8
- ::GraphQL::Schema.class_eval do
9
- alias_method :multiplex_without_sk, :multiplex
10
-
11
- # Schema#execute also delegates to multiplex, so this is the only method
12
- # we need to override.
13
- def multiplex(*args, &block)
14
- sk_add_tracer
15
- multiplex_without_sk(*args, &block)
16
- end
17
-
18
- def sk_add_tracer
19
- Skylight::Core::Config::MUTEX.synchronize do
20
- graphql_tracer = ::GraphQL::Tracing::ActiveSupportNotificationsTracing
21
- unless tracers.include?(graphql_tracer)
22
- $stdout.puts "[SKYLIGHT::CORE] Adding tracer 'GraphQL::Tracing::ActiveSupportNotificationsTracing' to schema"
23
- tracers << graphql_tracer
24
- end
25
-
26
- class << self
27
- # Remove the probe and reset multiplex/execute to original version
28
- # after the tracer has been added
29
- alias_method :multiplex, :multiplex_without_sk
30
- end
31
- end
32
- end
20
+ tracing_klass_name = "::GraphQL::Tracing::ActiveSupportNotificationsTracing"
21
+ klasses_to_probe = %w(
22
+ ::GraphQL::Execution::Multiplex
23
+ ::GraphQL::Query
24
+ )
25
+
26
+ return unless ([tracing_klass_name] + klasses_to_probe).all?(&method(:safe_constantize))
27
+
28
+ klasses_to_probe.each do |klass_name|
29
+ safe_constantize(klass_name).prepend(Instrumentation)
33
30
  end
34
31
  end
32
+
33
+ def safe_constantize(klass_name)
34
+ Skylight::Core::Util::Inflector.safe_constantize(klass_name)
35
+ end
35
36
  end
36
37
  end
37
38
 
@@ -1,5 +1,5 @@
1
1
  module Skylight
2
2
  module Core
3
- VERSION = "4.2.1".freeze
3
+ VERSION = "4.3.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -150,7 +150,7 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ description:
154
154
  email:
155
155
  - engineering@tilde.io
156
156
  executables: []
@@ -172,6 +172,7 @@ files:
172
172
  - lib/skylight/core/normalizers/action_controller/send_file.rb
173
173
  - lib/skylight/core/normalizers/action_dispatch/process_middleware.rb
174
174
  - lib/skylight/core/normalizers/action_view/render_collection.rb
175
+ - lib/skylight/core/normalizers/action_view/render_layout.rb
175
176
  - lib/skylight/core/normalizers/action_view/render_partial.rb
176
177
  - lib/skylight/core/normalizers/action_view/render_template.rb
177
178
  - lib/skylight/core/normalizers/active_job/perform.rb
@@ -254,7 +255,7 @@ homepage: https://www.skylight.io
254
255
  licenses:
255
256
  - Nonstandard
256
257
  metadata: {}
257
- post_install_message:
258
+ post_install_message:
258
259
  rdoc_options: []
259
260
  require_paths:
260
261
  - lib
@@ -269,8 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
270
  - !ruby/object:Gem::Version
270
271
  version: '0'
271
272
  requirements: []
272
- rubygems_version: 3.0.6
273
- signing_key:
273
+ rubygems_version: 3.1.4
274
+ signing_key:
274
275
  specification_version: 4
275
276
  summary: The core methods of the Skylight profiler.
276
277
  test_files: []