skylight 4.2.3 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +420 -331
  3. data/CLA.md +1 -1
  4. data/CONTRIBUTING.md +2 -8
  5. data/ERRORS.md +3 -0
  6. data/LICENSE.md +7 -17
  7. data/README.md +1 -1
  8. data/ext/extconf.rb +61 -56
  9. data/ext/libskylight.yml +8 -6
  10. data/ext/skylight_native.c +26 -100
  11. data/lib/skylight/api.rb +32 -21
  12. data/lib/skylight/cli/doctor.rb +64 -65
  13. data/lib/skylight/cli/helpers.rb +19 -19
  14. data/lib/skylight/cli/merger.rb +142 -138
  15. data/lib/skylight/cli.rb +48 -46
  16. data/lib/skylight/config.rb +640 -201
  17. data/lib/skylight/data/cacert.pem +730 -1023
  18. data/lib/skylight/deprecation.rb +17 -0
  19. data/lib/skylight/errors.rb +26 -9
  20. data/lib/skylight/extensions/source_location.rb +291 -0
  21. data/lib/skylight/extensions.rb +95 -0
  22. data/lib/skylight/formatters/http.rb +18 -0
  23. data/lib/skylight/gc.rb +99 -0
  24. data/lib/skylight/helpers.rb +81 -36
  25. data/lib/skylight/instrumenter.rb +336 -18
  26. data/lib/skylight/middleware.rb +147 -1
  27. data/lib/skylight/native.rb +60 -12
  28. data/lib/skylight/native_ext_fetcher.rb +13 -14
  29. data/lib/skylight/normalizers/action_controller/process_action.rb +68 -0
  30. data/lib/skylight/normalizers/action_controller/send_file.rb +51 -0
  31. data/lib/skylight/normalizers/action_dispatch/process_middleware.rb +22 -0
  32. data/lib/skylight/normalizers/action_dispatch/route_set.rb +27 -0
  33. data/lib/skylight/normalizers/action_view/render_collection.rb +24 -0
  34. data/lib/skylight/normalizers/action_view/render_layout.rb +25 -0
  35. data/lib/skylight/normalizers/action_view/render_partial.rb +23 -0
  36. data/lib/skylight/normalizers/action_view/render_template.rb +23 -0
  37. data/lib/skylight/normalizers/active_job/perform.rb +87 -0
  38. data/lib/skylight/normalizers/active_model_serializers/render.rb +32 -0
  39. data/lib/skylight/normalizers/active_record/instantiation.rb +16 -0
  40. data/lib/skylight/normalizers/active_record/sql.rb +20 -0
  41. data/lib/skylight/normalizers/active_storage.rb +28 -0
  42. data/lib/skylight/normalizers/active_support/cache.rb +11 -0
  43. data/lib/skylight/normalizers/active_support/cache_clear.rb +16 -0
  44. data/lib/skylight/normalizers/active_support/cache_decrement.rb +16 -0
  45. data/lib/skylight/normalizers/active_support/cache_delete.rb +16 -0
  46. data/lib/skylight/normalizers/active_support/cache_exist.rb +16 -0
  47. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +16 -0
  48. data/lib/skylight/normalizers/active_support/cache_generate.rb +16 -0
  49. data/lib/skylight/normalizers/active_support/cache_increment.rb +16 -0
  50. data/lib/skylight/normalizers/active_support/cache_read.rb +16 -0
  51. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +16 -0
  52. data/lib/skylight/normalizers/active_support/cache_write.rb +16 -0
  53. data/lib/skylight/normalizers/coach/handler_finish.rb +44 -0
  54. data/lib/skylight/normalizers/coach/middleware_finish.rb +33 -0
  55. data/lib/skylight/normalizers/couch_potato/query.rb +20 -0
  56. data/lib/skylight/normalizers/data_mapper/sql.rb +12 -0
  57. data/lib/skylight/normalizers/default.rb +24 -0
  58. data/lib/skylight/normalizers/elasticsearch/request.rb +20 -0
  59. data/lib/skylight/normalizers/faraday/request.rb +38 -0
  60. data/lib/skylight/normalizers/grape/endpoint.rb +28 -0
  61. data/lib/skylight/normalizers/grape/endpoint_render.rb +25 -0
  62. data/lib/skylight/normalizers/grape/endpoint_run.rb +39 -0
  63. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +20 -0
  64. data/lib/skylight/normalizers/grape/format_response.rb +20 -0
  65. data/lib/skylight/normalizers/graphiti/render.rb +22 -0
  66. data/lib/skylight/normalizers/graphiti/resolve.rb +31 -0
  67. data/lib/skylight/normalizers/graphql/base.rb +127 -0
  68. data/lib/skylight/normalizers/render.rb +79 -0
  69. data/lib/skylight/normalizers/sequel/sql.rb +12 -0
  70. data/lib/skylight/normalizers/shrine.rb +32 -0
  71. data/lib/skylight/normalizers/sql.rb +41 -0
  72. data/lib/skylight/normalizers.rb +157 -0
  73. data/lib/skylight/probes/action_controller.rb +52 -0
  74. data/lib/skylight/probes/action_dispatch/request_id.rb +33 -0
  75. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +30 -0
  76. data/lib/skylight/probes/action_dispatch.rb +2 -0
  77. data/lib/skylight/probes/action_view.rb +42 -0
  78. data/lib/skylight/probes/active_job.rb +27 -0
  79. data/lib/skylight/probes/active_job_enqueue.rb +35 -0
  80. data/lib/skylight/probes/active_model_serializers.rb +50 -0
  81. data/lib/skylight/probes/active_record_async.rb +96 -0
  82. data/lib/skylight/probes/delayed_job.rb +144 -0
  83. data/lib/skylight/probes/elasticsearch.rb +36 -0
  84. data/lib/skylight/probes/excon/middleware.rb +65 -0
  85. data/lib/skylight/probes/excon.rb +25 -0
  86. data/lib/skylight/probes/faraday.rb +23 -0
  87. data/lib/skylight/probes/graphql.rb +38 -0
  88. data/lib/skylight/probes/httpclient.rb +44 -0
  89. data/lib/skylight/probes/middleware.rb +135 -0
  90. data/lib/skylight/probes/mongo.rb +156 -0
  91. data/lib/skylight/probes/mongoid.rb +13 -0
  92. data/lib/skylight/probes/net_http.rb +54 -0
  93. data/lib/skylight/probes/rack_builder.rb +37 -0
  94. data/lib/skylight/probes/redis.rb +51 -0
  95. data/lib/skylight/probes/sequel.rb +29 -0
  96. data/lib/skylight/probes/sinatra.rb +66 -0
  97. data/lib/skylight/probes/sinatra_add_middleware.rb +10 -10
  98. data/lib/skylight/probes/tilt.rb +25 -0
  99. data/lib/skylight/probes.rb +173 -0
  100. data/lib/skylight/railtie.rb +166 -28
  101. data/lib/skylight/sidekiq.rb +47 -0
  102. data/lib/skylight/sinatra.rb +1 -1
  103. data/lib/skylight/subscriber.rb +130 -0
  104. data/lib/skylight/test.rb +147 -0
  105. data/lib/skylight/trace.rb +325 -22
  106. data/lib/skylight/user_config.rb +58 -0
  107. data/lib/skylight/util/allocation_free.rb +26 -0
  108. data/lib/skylight/util/clock.rb +57 -0
  109. data/lib/skylight/util/component.rb +22 -22
  110. data/lib/skylight/util/deploy.rb +19 -24
  111. data/lib/skylight/util/gzip.rb +20 -0
  112. data/lib/skylight/util/http.rb +106 -113
  113. data/lib/skylight/util/instrumenter_method.rb +26 -0
  114. data/lib/skylight/util/logging.rb +136 -0
  115. data/lib/skylight/util/lru_cache.rb +36 -0
  116. data/lib/skylight/util/platform.rb +3 -7
  117. data/lib/skylight/util/ssl.rb +1 -25
  118. data/lib/skylight/util.rb +12 -0
  119. data/lib/skylight/vendor/cli/thor/rake_compat.rb +1 -1
  120. data/lib/skylight/version.rb +5 -1
  121. data/lib/skylight/vm/gc.rb +60 -0
  122. data/lib/skylight.rb +201 -14
  123. metadata +134 -18
data/CLA.md CHANGED
@@ -6,4 +6,4 @@ right (whether now known or hereinafter invented), title, and interest,
6
6
  throughout the world, including any copyrights and renewals or extensions
7
7
  thereto, in the contributions to Skylight made by Assignor.
8
8
 
9
- IN WITNESS THEREOF, Assignor has duly executed this Agreement.
9
+ IN WITNESS THEREOF, Assignor has duly executed this Agreement.
data/CONTRIBUTING.md CHANGED
@@ -16,14 +16,8 @@ If you prefer to run tests in your own environment, you may do so as follows:
16
16
 
17
17
  ```shell
18
18
  # Select a gemfile and bundle install
19
- export BUNDLE_GEMFILE=$PWD/gemfiles/Gemfile.rails-5.2.x
19
+ export BUNDLE_GEMFILE=$PWD/gemfiles/rails-5.2.x/Gemfile
20
20
  bundle install
21
-
22
- # Run the skylight-core test suite (takes a few seconds)
23
- pushd skylight-core
24
- bundle exec rspec
25
- popd
26
-
27
- # Run the main test suite (takes 5-10 minutes)
21
+ # Run the test suite (takes 5-10 minutes)
28
22
  bundle exec rspec
29
23
  ```
data/ERRORS.md CHANGED
@@ -2,4 +2,7 @@ E0001 - Spans were closed out of order
2
2
  E0002 - Exceeded the number of unique span descriptions
3
3
  E0003 - Exceeded maximum number of spans
4
4
  E0004 - Failed to lex SQL query
5
+ E0005 - Instrumenter is not running
6
+ E0006 - Invalid UTF-8
7
+ E0007 - Failed to connect to gRPC server
5
8
  E9999 - Unknown
data/LICENSE.md CHANGED
@@ -28,19 +28,15 @@ brand (if any) provided by Tilde.
28
28
  Unless otherwise expressly agreed by Tilde in a separate written
29
29
  license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
30
30
  ANY KIND, including without any implied warranties of MERCHANTABILITY,
31
- FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
31
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
32
32
  condition to your use of these files, you are solely responsible for
33
33
  such use. Tilde will have no liability to you for direct,
34
34
  indirect, consequential, incidental, special, or punitive damages or
35
35
  for lost profits or data.
36
36
 
37
+ # Other Licenses
37
38
 
38
-
39
- Other Licenses
40
- ==============
41
-
42
- Ruby on Rails
43
- -------------
39
+ ## Ruby on Rails
44
40
 
45
41
  Copyright (c) 2005-2016 David Heinemeier Hansson
46
42
 
@@ -48,9 +44,7 @@ Released under the MIT License.
48
44
 
49
45
  Original source at https://github.com/rails/rails.
50
46
 
51
-
52
- HighLine
53
- --------
47
+ ## HighLine
54
48
 
55
49
  Copyright (c) 2014 James Edward Gray II, Gregory Brown, et al.
56
50
 
@@ -58,9 +52,7 @@ Distributed under the user's choice of the GPL Version 2 or the Ruby software li
58
52
 
59
53
  Original source at https://github.com/JEG2/highline.
60
54
 
61
-
62
- Thor
63
- ----
55
+ ## Thor
64
56
 
65
57
  Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
66
58
 
@@ -68,12 +60,10 @@ Released under the MIT License.
68
60
 
69
61
  Original source at https://github.com/erikhuda/thor.
70
62
 
71
-
72
- ThreadSafe
73
- ----------
63
+ ## ThreadSafe
74
64
 
75
65
  Copyright (c) 2014 Charles Oliver Nutter, thedarkone, et al.
76
66
 
77
67
  Distributed under Apache License, Version 2.0, January 2004
78
68
 
79
- Original source at https://github.com/ruby-concurrency/thread_safe.
69
+ Original source at https://github.com/ruby-concurrency/thread_safe.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Skylight Ruby Agent
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/skylight.svg)](https://badge.fury.io/rb/skylight)
3
4
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=skylight&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=skylight&package-manager=bundler&version-scheme=semver)
4
5
 
@@ -9,7 +10,6 @@ Sign up at https://www.skylight.io.
9
10
 
10
11
  For more documentation see https://www.skylight.io/support.
11
12
 
12
-
13
13
  ## Bug Reports and Feature Requests
14
14
 
15
15
  If you've got a bug report or have a feature you'd like to request, please contact us at support@skylight.io or use the built-in messenger in the Skylight web interface. We'll be much quicker to respond that way :)
data/ext/extconf.rb CHANGED
@@ -9,6 +9,22 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
9
9
  require "skylight/native_ext_fetcher"
10
10
  require "skylight/util/platform"
11
11
 
12
+ GLIBC_MIN = 2.23
13
+ GLIBC_V4_MIN = 2.15
14
+
15
+ ldd_output =
16
+ begin
17
+ `ldd --version`
18
+ rescue Errno::ENOENT
19
+ nil
20
+ end
21
+
22
+ if ldd_output =~ /GLIBC (\d+(\.\d+)+)/ && ($1.to_f < GLIBC_MIN)
23
+ message = "glibc #{GLIBC_MIN}+ is required but you have #{$1} installed."
24
+ message << "\nYou may be able to use Skylight v4 instead." if $1.to_f >= GLIBC_V4_MIN
25
+ fail message
26
+ end
27
+
12
28
  # Util allowing proxying writes to multiple location
13
29
  class MultiIO
14
30
  def initialize(*targets)
@@ -27,12 +43,13 @@ end
27
43
  include Skylight::Util
28
44
 
29
45
  SKYLIGHT_INSTALL_LOG = File.expand_path("install.log", __dir__)
30
- SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV["SKYLIGHT_REQUIRED"] !~ /^false$/i
31
- SKYLIGHT_FETCH_LIB = !ENV.key?("SKYLIGHT_FETCH_LIB") || ENV["SKYLIGHT_FETCH_LIB"] !~ /^false$/i
46
+ SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV["SKYLIGHT_REQUIRED"] !~ /^false$/i
47
+ SKYLIGHT_FETCH_LIB = !ENV.key?("SKYLIGHT_FETCH_LIB") || ENV["SKYLIGHT_FETCH_LIB"] !~ /^false$/i
32
48
 
33
49
  # Directory where skylight.h exists
34
50
  SKYLIGHT_HDR_PATH = ENV["SKYLIGHT_HDR_PATH"] || ENV["SKYLIGHT_LIB_PATH"] || "."
35
- SKYLIGHT_LIB_PATH = ENV["SKYLIGHT_LIB_PATH"] || File.expand_path("../../lib/skylight/native/#{Platform.tuple}", __FILE__)
51
+ SKYLIGHT_LIB_PATH =
52
+ ENV["SKYLIGHT_LIB_PATH"] || File.expand_path("../../lib/skylight/native/#{Platform.tuple}", __FILE__)
36
53
 
37
54
  SKYLIGHT_SOURCE_URL = ENV["SKYLIGHT_SOURCE_URL"]
38
55
  SKYLIGHT_VERSION = ENV["SKYLIGHT_VERSION"]
@@ -41,7 +58,7 @@ SKYLIGHT_CHECKSUM = ENV["SKYLIGHT_CHECKSUM"]
41
58
  SKYLIGHT_EXT_STRICT = ENV.key?("SKYLIGHT_EXT_STRICT") && ENV["SKYLIGHT_EXT_STRICT"] =~ /^true$/i
42
59
 
43
60
  # Setup logger
44
- LOG = Logger.new(MultiIO.new(STDOUT, File.open(SKYLIGHT_INSTALL_LOG, "a")))
61
+ LOG = Logger.new(MultiIO.new($stdout, File.open(SKYLIGHT_INSTALL_LOG, "a")))
45
62
 
46
63
  # Handles terminating in the case of a failure. If we have a bug, we do not
47
64
  # want to break our customer's deploy, but extconf.rb requires a Makefile to be
@@ -65,26 +82,26 @@ end
65
82
  # Check that Xcode license has been approved
66
83
  # Based on Homebrew's implementation
67
84
  # https://github.com/Homebrew/homebrew/blob/03708b016755847facc4f19a43ee9f7a44141ed7/Library/Homebrew/cmd/doctor.rb#L1183
68
- if Platform::OS == "darwin"
69
- # If the user installs Xcode-only, they have to approve the
70
- # license or no "xc*" tool will work.
71
- if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?
72
- fail <<~MESSAGE
73
- You have not agreed to the Xcode license and so we are unable to build the native agent.
74
- To resolve this, you can agree to the license by opening Xcode.app or running:
75
- sudo xcodebuild -license
76
- MESSAGE
77
- end
85
+ # If the user installs Xcode-only, they have to approve the
86
+ # license or no "xc*" tool will work.
87
+
88
+ # prettier-ignore
89
+ if Platform::OS == "darwin" && (`/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?)
90
+ fail <<~MESSAGE
91
+ You have not agreed to the Xcode license and so we are unable to build the native agent.
92
+ To resolve this, you can agree to the license by opening Xcode.app or running:
93
+ sudo xcodebuild -license
94
+ MESSAGE
78
95
  end
79
96
 
80
97
  #
81
98
  # === Setup paths
82
99
  #
83
- root = File.expand_path(__dir__)
84
- hdrpath = File.expand_path(SKYLIGHT_HDR_PATH)
85
- libpath = File.expand_path(SKYLIGHT_LIB_PATH)
86
- libskylight = File.expand_path("libskylight.#{Platform.libext}", libpath)
87
- libskylight_yml = File.expand_path("libskylight.yml", root)
100
+ root = File.expand_path(__dir__)
101
+ hdrpath = File.expand_path(SKYLIGHT_HDR_PATH)
102
+ libpath = File.expand_path(SKYLIGHT_LIB_PATH)
103
+ libskylight = File.expand_path("libskylight.#{Platform.libext}", libpath)
104
+ libskylight_yml = File.expand_path("libskylight.yml", root)
88
105
  skylight_dlopen_h = File.expand_path("skylight_dlopen.h", hdrpath)
89
106
  skylight_dlopen_c = File.expand_path("skylight_dlopen.c", hdrpath)
90
107
 
@@ -96,14 +113,10 @@ LOG.info "file exists; path=#{skylight_dlopen_h}" if File.exist?(skylight_dlopen
96
113
 
97
114
  # If libskylight is not present, fetch it
98
115
  if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(skylight_dlopen_h)
99
- unless SKYLIGHT_FETCH_LIB
100
- fail "libskylight.#{LIBEXT} not found -- remote download disabled; aborting install"
101
- end
116
+ fail "libskylight.#{LIBEXT} not found -- remote download disabled; aborting install" unless SKYLIGHT_FETCH_LIB
102
117
 
103
118
  # Ensure that libskylight.yml is present and load it
104
- unless File.exist?(libskylight_yml)
105
- fail "`#{libskylight_yml}` does not exist"
106
- end
119
+ fail "`#{libskylight_yml}` does not exist" unless File.exist?(libskylight_yml)
107
120
 
108
121
  unless (libskylight_info = YAML.load_file(libskylight_yml))
109
122
  fail "`#{libskylight_yml}` does not contain data"
@@ -132,26 +145,26 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
132
145
 
133
146
  unless (checksum = checksums[Platform.tuple])
134
147
  fail "no checksum entry for requested architecture -- " \
135
- "this probably means the requested architecture is not supported; " \
136
- "platform=#{Platform.tuple}; available=#{checksums.keys}", :info
148
+ "this probably means the requested architecture is not supported; " \
149
+ "platform=#{Platform.tuple}; available=#{checksums.keys}",
150
+ :info
137
151
  end
138
152
  end
139
153
 
140
154
  begin
141
- res = Skylight::NativeExtFetcher.fetch(
142
- source: SKYLIGHT_SOURCE_URL,
143
- version: version,
144
- target: hdrpath,
145
- checksum: checksum,
146
- arch: Platform.tuple,
147
- required: SKYLIGHT_REQUIRED,
148
- platform: Platform.tuple,
149
- logger: LOG
150
- )
151
-
152
- unless res
153
- fail "could not fetch archive -- aborting skylight native extension build"
154
- end
155
+ res =
156
+ Skylight::NativeExtFetcher.fetch(
157
+ source: SKYLIGHT_SOURCE_URL,
158
+ version: version,
159
+ target: hdrpath,
160
+ checksum: checksum,
161
+ arch: Platform.tuple,
162
+ required: SKYLIGHT_REQUIRED,
163
+ platform: Platform.tuple,
164
+ logger: LOG
165
+ )
166
+
167
+ fail "could not fetch archive -- aborting skylight native extension build" unless res
155
168
 
156
169
  # Move skylightd & libskylight to appropriate directory
157
170
  if hdrpath != libpath
@@ -159,15 +172,11 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
159
172
  FileUtils.mkdir_p libpath
160
173
 
161
174
  # Move
162
- FileUtils.mv "#{hdrpath}/libskylight.#{Platform.libext}",
163
- "#{libpath}/libskylight.#{Platform.libext}",
164
- force: true
175
+ FileUtils.mv "#{hdrpath}/libskylight.#{Platform.libext}", "#{libpath}/libskylight.#{Platform.libext}", force: true
165
176
 
166
- FileUtils.mv "#{hdrpath}/skylightd",
167
- "#{libpath}/skylightd",
168
- force: true
177
+ FileUtils.mv "#{hdrpath}/skylightd", "#{libpath}/skylightd", force: true
169
178
  end
170
- rescue => e
179
+ rescue StandardError => e
171
180
  fail "unable to fetch native extension; msg=#{e.message}\n#{e.backtrace.join("\n")}"
172
181
  end
173
182
  end
@@ -181,9 +190,7 @@ end
181
190
  def find_file(file, root = nil)
182
191
  path = File.expand_path(file, root || ".")
183
192
 
184
- unless File.exist?(path)
185
- fail "#{file} missing; path=#{root}"
186
- end
193
+ fail "#{file} missing; path=#{root}" unless File.exist?(path)
187
194
  end
188
195
 
189
196
  $VPATH << libpath
@@ -206,8 +213,8 @@ find_header "skylight_dlopen.h", hdrpath
206
213
  fail "could not create Makefile; dlfcn.h missing" unless have_header "dlfcn.h"
207
214
 
208
215
  # For escaping the GVL
209
- unless have_func("rb_thread_call_without_gvl", "ruby/thread.h") || have_func("rb_thread_blocking_region")
210
- abort "Ruby is unexpectedly missing rb_thread_blocking_region. This should not happen."
216
+ unless have_func("rb_thread_call_without_gvl", "ruby/thread.h")
217
+ abort "Ruby is unexpectedly missing rb_thread_call_without_gvl. This should not happen."
211
218
  end
212
219
 
213
220
  # Previous comment stated:
@@ -217,9 +224,7 @@ end
217
224
  # flag can cause issues for some customers we're turning it off by default. However,
218
225
  # in development and CI, we still have the option of turning it back on to help catch
219
226
  # potential issues.
220
- if SKYLIGHT_EXT_STRICT
221
- $CFLAGS << " -Werror"
222
- end
227
+ $CFLAGS << " -Werror" if SKYLIGHT_EXT_STRICT
223
228
 
224
229
  checking_for "fast thread local storage" do
225
230
  if try_compile("__thread int foo;")
data/ext/libskylight.yml CHANGED
@@ -1,7 +1,9 @@
1
- version: "4.1.0-46806f5"
1
+ version: "5.1.0-6812c12"
2
2
  checksums:
3
- x86-linux: "4054632757516aa44e812860601fcb7f21c8c5d412b2d585868b46c7a8e3cae6"
4
- x86_64-linux: "4675694fba4448ba14787551237bd4e388443895d5c9e5d8a71c550eccd203db"
5
- x86_64-linux-musl: "7a81880830d0a409a6f0f39ff42f90a1422542b05384e2480ae05515f6b5f831"
6
- x86_64-darwin: "84eef6c330818c2bad1628ff189b9cb88275c9d72a28afac88a0d054d8002230"
7
- x86_64-freebsd: "a86a52203fab4f9a56ad91d5700e14823e6e997b4df1bcb3ae2d9e4296c50b1f"
3
+ x86-linux: "d3acbbcd14209e8564226e005db2163b7d1ae49133eb250a7901ff2687abe330"
4
+ x86_64-linux: "dfb1062572780285795eef2e99d32ff3ad6be1c944c1a6add442488f7a4a9b22"
5
+ x86_64-linux-musl: "af09469f20c666a15ccbb910d8906c6a69a99f87f69db6cbba41908baf3fcef2"
6
+ x86_64-darwin: "eb4cb7b9301e0b1f88623203a4476bdabf299ec62556dc40bedda78c5eeb1437"
7
+ aarch64-linux: "3d5e8743c4dfdde5be3b6162c75b0351ff0be5658819c1fec9f3a936c4c81a32"
8
+ aarch64-linux-musl: "30705f76e333f4883a9481a34bc2dfeb7e9fd6f98c0cf8afbe63f232f3ceb1e5"
9
+ aarch64-darwin: "9f8ffc752b0e17bde587e5a5510b17554096b2b65fa2e19203ff1ee3a3145b1d"
@@ -86,14 +86,6 @@ typedef void* (*blocking_fn_t)(void*);
86
86
  #define WITHOUT_GVL(fn, a) \
87
87
  rb_thread_call_without_gvl((blocking_fn_t)(fn), (a), 0, 0)
88
88
 
89
- // Ruby 1.9
90
- #elif defined(HAVE_RB_THREAD_BLOCKING_REGION)
91
-
92
- typedef VALUE (*blocking_fn_t)(void*);
93
- #define WITHOUT_GVL(fn, a) \
94
- rb_thread_blocking_region((blocking_fn_t)(fn), (a), 0, 0)
95
-
96
-
97
89
  #endif
98
90
 
99
91
 
@@ -103,7 +95,6 @@ typedef VALUE (*blocking_fn_t)(void*);
103
95
 
104
96
  VALUE rb_mSkylight;
105
97
  VALUE rb_eNativeError;
106
- VALUE rb_mCore;
107
98
  VALUE rb_mUtil;
108
99
  VALUE rb_cClock;
109
100
  VALUE rb_cTrace;
@@ -140,7 +131,7 @@ load_libskylight(VALUE klass, VALUE path) {
140
131
 
141
132
  /*
142
133
  *
143
- * class Skylight::Core::Util::Clock
134
+ * class Skylight::Util::Clock
144
135
  *
145
136
  */
146
137
 
@@ -152,7 +143,7 @@ clock_high_res_time(VALUE self) {
152
143
 
153
144
  /*
154
145
  *
155
- * class Skylight::Core::Instrumenter
146
+ * class Skylight::Instrumenter
156
147
  *
157
148
  */
158
149
 
@@ -243,33 +234,9 @@ instrumenter_submit_trace(VALUE self, VALUE rb_trace) {
243
234
  return Qnil;
244
235
  }
245
236
 
246
- static VALUE
247
- instrumenter_track_desc(VALUE self, VALUE rb_endpoint, VALUE rb_desc) {
248
- int tracked;
249
- sky_instrumenter_t* instrumenter;
250
-
251
- CHECK_TYPE(rb_endpoint, T_STRING);
252
- CHECK_TYPE(rb_desc, T_STRING);
253
-
254
- tracked = 0;
255
-
256
- My_Struct(instrumenter, sky_instrumenter_t, no_instrumenter_msg);
257
-
258
- CHECK_FFI(
259
- sky_instrumenter_track_desc(instrumenter, STR2BUF(rb_endpoint), STR2BUF(rb_desc), &tracked),
260
- "Instrumenter#native_track_desc");
261
-
262
- if (tracked) {
263
- return Qtrue;
264
- }
265
- else {
266
- return Qfalse;
267
- }
268
- }
269
-
270
237
  /*
271
238
  *
272
- * class Skylight::Core::Trace
239
+ * class Skylight::Trace
273
240
  *
274
241
  */
275
242
 
@@ -503,15 +470,31 @@ trace_span_set_description(VALUE self, VALUE span, VALUE desc) {
503
470
 
504
471
  static VALUE
505
472
  trace_span_set_meta(VALUE self, VALUE span, VALUE meta) {
506
- UNUSED(self);
507
- UNUSED(span);
508
- UNUSED(meta);
473
+ sky_trace_t* trace;
474
+ VALUE rb_source_location;
475
+
476
+ My_Struct(trace, sky_trace_t, consumed_trace_msg);
477
+
478
+ CHECK_TYPE(span, T_FIXNUM);
479
+ CHECK_TYPE(meta, T_HASH);
480
+
481
+ rb_source_location = rb_hash_lookup(meta, ID2SYM(rb_intern("source_location")));
482
+ if (rb_source_location != Qnil) {
483
+ sky_buf_t source_location;
484
+
485
+ CHECK_TYPE(rb_source_location, T_STRING);
486
+ source_location = STR2BUF(rb_source_location);
487
+
488
+ sky_trace_span_add_string_annotation(trace, FIX2UINT(span), 3, source_location);
489
+ }
490
+
509
491
  return Qnil;
510
492
  }
511
493
 
512
494
  static VALUE
513
- trace_span_started(VALUE self) {
495
+ trace_span_started(VALUE self, VALUE span) {
514
496
  UNUSED(self);
497
+ UNUSED(span);
515
498
  return Qnil;
516
499
  }
517
500
 
@@ -524,76 +507,20 @@ trace_span_set_exception(VALUE self, VALUE span, VALUE exception, VALUE exceptio
524
507
  return Qnil;
525
508
  }
526
509
 
527
- static VALUE
528
- trace_span_get_correlation_header(VALUE self, VALUE span_id) {
529
- UNUSED(self);
530
- UNUSED(span_id);
531
- return Qnil;
532
- }
533
-
534
- static VALUE
535
- lex_sql(VALUE klass, VALUE rb_sql) {
536
- sky_buf_t sql;
537
- sky_buf_t title;
538
- sky_buf_t statement;
539
- uint8_t title_store[128];
540
- VALUE rb_statement;
541
- VALUE ret;
542
-
543
- UNUSED(klass);
544
- CHECK_TYPE(rb_sql, T_STRING);
545
-
546
- sql = STR2BUF(rb_sql);
547
- title = (sky_buf_t) {
548
- .data = title_store,
549
- .len = sizeof(title_store),
550
- };
551
-
552
- // The statement cannot be longer than the original sql string
553
- rb_statement = rb_str_buf_new(RSTRING_LEN(rb_sql));
554
- statement = (sky_buf_t) {
555
- .data = RSTRING_PTR(rb_statement),
556
- .len = RSTRING_LEN(rb_sql),
557
- };
558
-
559
- CHECK_FFI(sky_lex_sql(sql, &title, &statement),
560
- "Skylight#lex_sql");
561
-
562
- // Set the statement return
563
- rb_str_set_len(rb_statement, statement.len);
564
- rb_enc_associate(rb_statement, rb_utf8_encoding());
565
-
566
- ret = rb_ary_new2(2);
567
-
568
- if (title.len > 0) {
569
- rb_ary_store(ret, 0, BUF2STR(title));
570
- }
571
- else {
572
- rb_ary_store(ret, 0, Qnil);
573
- }
574
-
575
- rb_ary_store(ret, 1, rb_statement);
576
-
577
- return ret;
578
- }
579
-
580
510
  void Init_skylight_native() {
581
511
  rb_mSkylight = rb_define_module("Skylight");
582
512
 
583
513
  rb_eNativeError = rb_const_get(rb_mSkylight, rb_intern("NativeError"));
584
514
 
585
515
  rb_define_singleton_method(rb_mSkylight, "load_libskylight", load_libskylight, 1);
586
- rb_define_singleton_method(rb_mSkylight, "lex_sql", lex_sql, 1);
587
-
588
- rb_mCore = rb_define_module_under(rb_mSkylight, "Core");
589
516
 
590
- // FIXME: Don't put these under Core
591
- rb_mUtil = rb_define_module_under(rb_mCore, "Util");
517
+ rb_mUtil = rb_define_module_under(rb_mSkylight, "Util");
592
518
  rb_cClock = rb_define_class_under(rb_mUtil, "Clock", rb_cObject);
593
519
  rb_define_method(rb_cClock, "native_hrtime", clock_high_res_time, 0);
594
520
 
595
521
  rb_cTrace = rb_const_get(rb_mSkylight, rb_intern("Trace"));
596
522
  rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 4);
523
+ rb_undef_alloc_func(rb_cTrace);
597
524
  rb_define_method(rb_cTrace, "native_get_started_at", trace_get_started_at, 0);
598
525
  rb_define_method(rb_cTrace, "native_get_endpoint", trace_get_endpoint, 0);
599
526
  rb_define_method(rb_cTrace, "native_set_endpoint", trace_set_endpoint, 1);
@@ -611,12 +538,11 @@ void Init_skylight_native() {
611
538
  rb_define_method(rb_cTrace, "native_span_set_meta", trace_span_set_meta, 2);
612
539
  rb_define_method(rb_cTrace, "native_span_started", trace_span_started, 1);
613
540
  rb_define_method(rb_cTrace, "native_span_set_exception", trace_span_set_exception, 3);
614
- rb_define_method(rb_cTrace, "native_span_get_correlation_header", trace_span_get_correlation_header, 1);
615
541
 
616
542
  rb_cInstrumenter = rb_const_get(rb_mSkylight, rb_intern("Instrumenter"));
617
543
  rb_define_singleton_method(rb_cInstrumenter, "native_new", instrumenter_new, 2);
544
+ rb_undef_alloc_func(rb_cInstrumenter);
618
545
  rb_define_method(rb_cInstrumenter, "native_start", instrumenter_start, 0);
619
546
  rb_define_method(rb_cInstrumenter, "native_stop", instrumenter_stop, 0);
620
547
  rb_define_method(rb_cInstrumenter, "native_submit_trace", instrumenter_submit_trace, 1);
621
- rb_define_method(rb_cInstrumenter, "native_track_desc", instrumenter_track_desc, 2);
622
548
  }
data/lib/skylight/api.rb CHANGED
@@ -4,13 +4,19 @@ require "skylight/util/http"
4
4
  module Skylight
5
5
  # @api private
6
6
  class Api
7
- include Core::Util::Logging
7
+ include Util::Logging
8
8
 
9
9
  attr_reader :config
10
10
 
11
- class Error < StandardError; end
12
- class Unauthorized < Error; end
13
- class Conflict < Error; end
11
+ class Error < StandardError
12
+ end
13
+
14
+ class Unauthorized < Error
15
+ end
16
+
17
+ class Conflict < Error
18
+ end
19
+
14
20
  class CreateFailed < Error
15
21
  attr_reader :res
16
22
 
@@ -21,6 +27,7 @@ module Skylight
21
27
 
22
28
  def errors
23
29
  return unless res.respond_to?(:body) && res.body.is_a?(Hash)
30
+
24
31
  res.body["errors"]
25
32
  end
26
33
 
@@ -36,7 +43,7 @@ module Skylight
36
43
  end
37
44
 
38
45
  class ConfigValidationResults
39
- include Core::Util::Logging
46
+ include Util::Logging
40
47
 
41
48
  attr_reader :raw_response
42
49
 
@@ -67,6 +74,7 @@ module Skylight
67
74
  def token_valid?
68
75
  # Don't prevent boot if it's an error response, so assume token is valid
69
76
  return true if error_response?
77
+
70
78
  # A 2xx response means everything is good!
71
79
  return true if raw_response.success?
72
80
  return false if status == 401
@@ -87,11 +95,13 @@ module Skylight
87
95
 
88
96
  def validation_errors
89
97
  return {} if config_valid? || !body
98
+
90
99
  body["errors"]
91
100
  end
92
101
 
93
102
  def corrected_config
94
- return {} if config_valid? || !body
103
+ return nil if config_valid? || !body
104
+
95
105
  body["corrected"]
96
106
  end
97
107
  end
@@ -107,6 +117,7 @@ module Skylight
107
117
  res = http_request(:app_create, :post, params)
108
118
 
109
119
  raise CreateFailed, res unless res.success?
120
+
110
121
  res
111
122
  end
112
123
 
@@ -132,22 +143,22 @@ module Skylight
132
143
 
133
144
  private
134
145
 
135
- # TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
136
- def http_request(service, method, *args)
137
- http = Util::HTTP.new(config, service)
138
- uri = URI.parse(config.get("#{service}_url"))
139
- http.send(method, uri.path, *args)
140
- end
146
+ # TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
147
+ def http_request(service, method, *args)
148
+ http = Util::HTTP.new(config, service)
149
+ uri = URI.parse(config.get("#{service}_url"))
150
+ http.send(method, uri.path, *args)
151
+ end
141
152
 
142
- def error_for_status(code)
143
- case code
144
- when 401
145
- Unauthorized
146
- when 409
147
- Conflict
148
- else
149
- Error
150
- end
153
+ def error_for_status(code)
154
+ case code
155
+ when 401
156
+ Unauthorized
157
+ when 409
158
+ Conflict
159
+ else
160
+ Error
151
161
  end
162
+ end
152
163
  end
153
164
  end