ddtrace 0.45.0 → 0.47.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +131 -12
- data/.circleci/images/primary/{Dockerfile-jruby-9.2 → Dockerfile-jruby-9.2-latest} +2 -1
- data/.circleci/images/primary/Dockerfile-jruby-9.2.0.0 +73 -0
- data/.circleci/images/primary/Dockerfile-truffleruby-21.0.0 +73 -0
- data/.github/workflows/create-next-milestone.yml +2 -2
- data/.rubocop.yml +250 -7
- data/.rubocop_todo.yml +397 -0
- data/.simplecov +6 -0
- data/Appraisals +16 -1
- data/CHANGELOG.md +150 -1
- data/Gemfile +53 -3
- data/LICENSE-3rdparty.csv +2 -0
- data/Rakefile +5 -23
- data/ddtrace.gemspec +6 -36
- data/docker-compose.yml +75 -7
- data/docs/DevelopmentGuide.md +28 -0
- data/docs/GettingStarted.md +69 -17
- data/integration/README.md +68 -0
- data/integration/apps/rack/.dockerignore +1 -0
- data/integration/apps/rack/.envrc.sample +1 -0
- data/integration/apps/rack/.gitignore +4 -0
- data/integration/apps/rack/.rspec +1 -0
- data/integration/apps/rack/Dockerfile +25 -0
- data/integration/apps/rack/Dockerfile-ci +11 -0
- data/integration/apps/rack/Gemfile +24 -0
- data/integration/apps/rack/README.md +93 -0
- data/integration/apps/rack/app/acme.rb +80 -0
- data/integration/apps/rack/app/datadog.rb +17 -0
- data/integration/apps/rack/bin/run +22 -0
- data/integration/apps/rack/bin/setup +17 -0
- data/integration/apps/rack/bin/test +24 -0
- data/integration/apps/rack/config.ru +6 -0
- data/integration/apps/rack/config/puma.rb +14 -0
- data/integration/apps/rack/config/unicorn.rb +23 -0
- data/integration/apps/rack/docker-compose.ci.yml +62 -0
- data/integration/apps/rack/docker-compose.yml +78 -0
- data/integration/apps/rack/script/build-images +38 -0
- data/integration/apps/rack/script/ci +50 -0
- data/integration/apps/rack/spec/integration/basic_spec.rb +10 -0
- data/integration/apps/rack/spec/spec_helper.rb +16 -0
- data/integration/apps/rack/spec/support/integration_helper.rb +22 -0
- data/integration/apps/rails-five/.dockerignore +1 -0
- data/integration/apps/rails-five/.env +3 -0
- data/integration/apps/rails-five/.envrc.sample +1 -0
- data/integration/apps/rails-five/.gitignore +30 -0
- data/integration/apps/rails-five/Dockerfile +25 -0
- data/integration/apps/rails-five/Dockerfile-ci +11 -0
- data/integration/apps/rails-five/Gemfile +104 -0
- data/integration/apps/rails-five/README.md +94 -0
- data/integration/apps/rails-five/Rakefile +6 -0
- data/integration/apps/rails-five/app/channels/application_cable/channel.rb +4 -0
- data/integration/apps/rails-five/app/channels/application_cable/connection.rb +4 -0
- data/integration/apps/rails-five/app/controllers/application_controller.rb +2 -0
- data/integration/apps/rails-five/app/controllers/basic_controller.rb +36 -0
- data/integration/apps/rails-five/app/controllers/concerns/.keep +0 -0
- data/integration/apps/rails-five/app/controllers/health_controller.rb +9 -0
- data/integration/apps/rails-five/app/controllers/jobs_controller.rb +12 -0
- data/integration/apps/rails-five/app/jobs/application_job.rb +2 -0
- data/integration/apps/rails-five/app/jobs/test_job.rb +12 -0
- data/integration/apps/rails-five/app/mailers/application_mailer.rb +4 -0
- data/integration/apps/rails-five/app/models/application_record.rb +3 -0
- data/integration/apps/rails-five/app/models/concerns/.keep +0 -0
- data/integration/apps/rails-five/app/models/test.rb +2 -0
- data/integration/apps/rails-five/app/views/layouts/mailer.html.erb +13 -0
- data/integration/apps/rails-five/app/views/layouts/mailer.text.erb +1 -0
- data/integration/apps/rails-five/bin/bundle +3 -0
- data/integration/apps/rails-five/bin/rails +9 -0
- data/integration/apps/rails-five/bin/rake +9 -0
- data/integration/apps/rails-five/bin/run +24 -0
- data/integration/apps/rails-five/bin/setup +27 -0
- data/integration/apps/rails-five/bin/spring +17 -0
- data/integration/apps/rails-five/bin/test +21 -0
- data/integration/apps/rails-five/bin/update +28 -0
- data/integration/apps/rails-five/config.ru +5 -0
- data/integration/apps/rails-five/config/application.rb +97 -0
- data/integration/apps/rails-five/config/boot.rb +4 -0
- data/integration/apps/rails-five/config/cable.yml +10 -0
- data/integration/apps/rails-five/config/credentials.yml.enc +1 -0
- data/integration/apps/rails-five/config/database.yml +28 -0
- data/integration/apps/rails-five/config/environment.rb +5 -0
- data/integration/apps/rails-five/config/environments/development.rb +51 -0
- data/integration/apps/rails-five/config/environments/production.rb +82 -0
- data/integration/apps/rails-five/config/environments/test.rb +43 -0
- data/integration/apps/rails-five/config/initializers/datadog.rb +18 -0
- data/integration/apps/rails-five/config/initializers/filter_parameter_logging.rb +4 -0
- data/integration/apps/rails-five/config/initializers/resque.rb +4 -0
- data/integration/apps/rails-five/config/initializers/rollbar.rb +5 -0
- data/integration/apps/rails-five/config/initializers/wrap_parameters.rb +14 -0
- data/integration/apps/rails-five/config/locales/en.yml +33 -0
- data/integration/apps/rails-five/config/puma.rb +24 -0
- data/integration/apps/rails-five/config/routes.rb +11 -0
- data/integration/apps/rails-five/config/spring.rb +6 -0
- data/integration/apps/rails-five/config/unicorn.rb +29 -0
- data/integration/apps/rails-five/db/migrate/20190927215052_create_tests.rb +11 -0
- data/integration/apps/rails-five/db/schema.rb +23 -0
- data/integration/apps/rails-five/db/seeds.rb +7 -0
- data/integration/apps/rails-five/docker-compose.ci.yml +98 -0
- data/integration/apps/rails-five/docker-compose.yml +100 -0
- data/integration/apps/rails-five/lib/tasks/.keep +0 -0
- data/integration/apps/rails-five/log/.keep +0 -0
- data/integration/apps/rails-five/public/robots.txt +1 -0
- data/integration/apps/rails-five/script/build-images +35 -0
- data/integration/apps/rails-five/script/ci +50 -0
- data/integration/apps/rails-five/spec/integration/basic_spec.rb +10 -0
- data/integration/apps/rails-five/spec/spec_helper.rb +16 -0
- data/integration/apps/rails-five/spec/support/integration_helper.rb +22 -0
- data/integration/apps/rails-five/storage/.keep +0 -0
- data/integration/apps/rails-five/tmp/.keep +0 -0
- data/integration/apps/rails-five/vendor/.keep +0 -0
- data/integration/apps/ruby/.dockerignore +1 -0
- data/integration/apps/ruby/.envrc.sample +1 -0
- data/integration/apps/ruby/.gitignore +2 -0
- data/integration/apps/ruby/Dockerfile +25 -0
- data/integration/apps/ruby/Dockerfile-ci +11 -0
- data/integration/apps/ruby/Gemfile +11 -0
- data/integration/apps/ruby/README.md +70 -0
- data/integration/apps/ruby/agent.yaml +3 -0
- data/integration/apps/ruby/app/datadog.rb +13 -0
- data/integration/apps/ruby/app/fibonacci.rb +58 -0
- data/integration/apps/ruby/bin/run +20 -0
- data/integration/apps/ruby/bin/setup +17 -0
- data/integration/apps/ruby/bin/test +21 -0
- data/integration/apps/ruby/docker-compose.ci.yml +51 -0
- data/integration/apps/ruby/docker-compose.yml +63 -0
- data/integration/apps/ruby/script/build-images +38 -0
- data/integration/apps/ruby/script/ci +50 -0
- data/integration/images/agent/Dockerfile +2 -0
- data/integration/images/agent/agent.yaml +3 -0
- data/integration/images/include/datadog/analyzer.rb +71 -0
- data/integration/images/include/datadog/demo_env.rb +101 -0
- data/integration/images/include/http-health-check +33 -0
- data/integration/images/ruby/2.0/Dockerfile +54 -0
- data/integration/images/ruby/2.1/Dockerfile +54 -0
- data/integration/images/ruby/2.2/Dockerfile +54 -0
- data/integration/images/ruby/2.3/Dockerfile +70 -0
- data/integration/images/ruby/2.4/Dockerfile +54 -0
- data/integration/images/ruby/2.5/Dockerfile +54 -0
- data/integration/images/ruby/2.6/Dockerfile +54 -0
- data/integration/images/ruby/2.7/Dockerfile +54 -0
- data/integration/images/ruby/3.0/Dockerfile +54 -0
- data/integration/images/wrk/Dockerfile +33 -0
- data/integration/images/wrk/scripts/entrypoint.sh +17 -0
- data/integration/images/wrk/scripts/scenarios/basic/default.lua +1 -0
- data/integration/images/wrk/scripts/scenarios/basic/fibonacci.lua +1 -0
- data/integration/script/build-images +43 -0
- data/lib/ddtrace.rb +0 -5
- data/lib/ddtrace/analytics.rb +2 -0
- data/lib/ddtrace/buffer.rb +4 -4
- data/lib/ddtrace/configuration.rb +92 -23
- data/lib/ddtrace/configuration/base.rb +1 -1
- data/lib/ddtrace/configuration/components.rb +2 -2
- data/lib/ddtrace/configuration/option_definition.rb +1 -3
- data/lib/ddtrace/configuration/options.rb +4 -7
- data/lib/ddtrace/configuration/settings.rb +17 -3
- data/lib/ddtrace/context.rb +5 -6
- data/lib/ddtrace/context_provider.rb +0 -1
- data/lib/ddtrace/contrib/action_cable/event.rb +1 -0
- data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +1 -3
- data/lib/ddtrace/contrib/action_view/event.rb +1 -1
- data/lib/ddtrace/contrib/action_view/utils.rb +1 -1
- data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +101 -18
- data/lib/ddtrace/contrib/active_record/utils.rb +1 -0
- data/lib/ddtrace/contrib/active_support/notifications/event.rb +2 -1
- data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +1 -0
- data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +9 -5
- data/lib/ddtrace/contrib/auto_instrument.rb +1 -0
- data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
- data/lib/ddtrace/contrib/aws/services.rb +2 -0
- data/lib/ddtrace/contrib/configurable.rb +63 -39
- data/lib/ddtrace/contrib/configuration/resolver.rb +70 -5
- data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +19 -20
- data/lib/ddtrace/contrib/configuration/settings.rb +7 -6
- data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +0 -10
- data/lib/ddtrace/contrib/cucumber/ext.rb +0 -2
- data/lib/ddtrace/contrib/cucumber/formatter.rb +5 -11
- data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -1
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -0
- data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +5 -5
- data/lib/ddtrace/contrib/excon/middleware.rb +2 -6
- data/lib/ddtrace/contrib/extensions.rb +27 -3
- data/lib/ddtrace/contrib/faraday/middleware.rb +1 -3
- data/lib/ddtrace/contrib/faraday/patcher.rb +0 -36
- data/lib/ddtrace/contrib/grape/endpoint.rb +8 -15
- data/lib/ddtrace/contrib/grape/patcher.rb +0 -42
- data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +8 -8
- data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +1 -0
- data/lib/ddtrace/contrib/grpc/patcher.rb +0 -36
- data/lib/ddtrace/contrib/http/circuit_breaker.rb +1 -3
- data/lib/ddtrace/contrib/http/instrumentation.rb +5 -5
- data/lib/ddtrace/contrib/httpclient/instrumentation.rb +14 -19
- data/lib/ddtrace/contrib/httpclient/patcher.rb +5 -2
- data/lib/ddtrace/contrib/httprb/instrumentation.rb +14 -20
- data/lib/ddtrace/contrib/httprb/patcher.rb +5 -2
- data/lib/ddtrace/contrib/mongodb/instrumentation.rb +2 -0
- data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -3
- data/lib/ddtrace/contrib/patcher.rb +9 -6
- data/lib/ddtrace/contrib/presto/patcher.rb +5 -2
- data/lib/ddtrace/contrib/qless/qless_job.rb +1 -0
- data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +1 -0
- data/lib/ddtrace/contrib/que/ext.rb +19 -19
- data/lib/ddtrace/contrib/que/tracer.rb +1 -1
- data/lib/ddtrace/contrib/racecar/event.rb +1 -0
- data/lib/ddtrace/contrib/rack/configuration/settings.rb +3 -3
- data/lib/ddtrace/contrib/rack/middlewares.rb +5 -10
- data/lib/ddtrace/contrib/rack/patcher.rb +1 -3
- data/lib/ddtrace/contrib/rails/patcher.rb +6 -2
- data/lib/ddtrace/contrib/rake/instrumentation.rb +4 -2
- data/lib/ddtrace/contrib/redis/configuration/resolver.rb +11 -4
- data/lib/ddtrace/contrib/redis/quantize.rb +1 -0
- data/lib/ddtrace/contrib/redis/vendor/LICENSE +20 -0
- data/lib/ddtrace/contrib/redis/vendor/resolver.rb +6 -7
- data/lib/ddtrace/contrib/registry.rb +2 -2
- data/lib/ddtrace/contrib/resque/integration.rb +1 -1
- data/lib/ddtrace/contrib/resque/resque_job.rb +2 -0
- data/lib/ddtrace/contrib/rest_client/request_patch.rb +1 -3
- data/lib/ddtrace/contrib/rspec/configuration/settings.rb +0 -10
- data/lib/ddtrace/contrib/rspec/example.rb +24 -10
- data/lib/ddtrace/contrib/rspec/ext.rb +0 -3
- data/lib/ddtrace/contrib/rspec/integration.rb +1 -1
- data/lib/ddtrace/contrib/rspec/patcher.rb +0 -2
- data/lib/ddtrace/contrib/sequel/utils.rb +5 -6
- data/lib/ddtrace/contrib/shoryuken/tracer.rb +0 -1
- data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +2 -7
- data/lib/ddtrace/contrib/sidekiq/tracing.rb +0 -1
- data/lib/ddtrace/contrib/sinatra/env.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/headers.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/tracer.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +3 -3
- data/lib/ddtrace/contrib/sneakers/ext.rb +11 -11
- data/lib/ddtrace/contrib/sneakers/tracer.rb +2 -4
- data/lib/ddtrace/contrib/status_code_matcher.rb +5 -3
- data/lib/ddtrace/correlation.rb +1 -0
- data/lib/ddtrace/diagnostics/environment_logger.rb +2 -1
- data/lib/ddtrace/distributed_tracing/headers/headers.rb +1 -0
- data/lib/ddtrace/distributed_tracing/headers/helpers.rb +1 -3
- data/lib/ddtrace/ext/ci.rb +2 -2
- data/lib/ddtrace/ext/distributed.rb +1 -1
- data/lib/ddtrace/ext/http.rb +1 -1
- data/lib/ddtrace/ext/runtime.rb +3 -1
- data/lib/ddtrace/forced_tracing.rb +2 -0
- data/lib/ddtrace/logger.rb +1 -1
- data/lib/ddtrace/metrics.rb +10 -6
- data/lib/ddtrace/opentracer/distributed_headers.rb +3 -0
- data/lib/ddtrace/opentracer/span.rb +2 -6
- data/lib/ddtrace/opentracer/thread_local_scope.rb +1 -0
- data/lib/ddtrace/patcher.rb +25 -4
- data/lib/ddtrace/pin.rb +8 -61
- data/lib/ddtrace/pipeline/span_filter.rb +1 -1
- data/lib/ddtrace/propagation/grpc_propagator.rb +1 -0
- data/lib/ddtrace/quantization/http.rb +1 -0
- data/lib/ddtrace/runtime/cgroup.rb +2 -2
- data/lib/ddtrace/runtime/container.rb +27 -29
- data/lib/ddtrace/runtime/identity.rb +8 -0
- data/lib/ddtrace/sampler.rb +1 -1
- data/lib/ddtrace/sampling/rule_sampler.rb +1 -0
- data/lib/ddtrace/span.rb +7 -7
- data/lib/ddtrace/sync_writer.rb +12 -12
- data/lib/ddtrace/tracer.rb +7 -5
- data/lib/ddtrace/transport/http.rb +15 -8
- data/lib/ddtrace/transport/http/adapters/net.rb +27 -8
- data/lib/ddtrace/transport/http/adapters/registry.rb +1 -0
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +2 -4
- data/lib/ddtrace/transport/http/builder.rb +7 -1
- data/lib/ddtrace/transport/http/env.rb +8 -0
- data/lib/ddtrace/transport/http/traces.rb +2 -3
- data/lib/ddtrace/transport/io.rb +1 -1
- data/lib/ddtrace/transport/io/response.rb +1 -3
- data/lib/ddtrace/transport/io/traces.rb +6 -0
- data/lib/ddtrace/transport/traces.rb +18 -1
- data/lib/ddtrace/utils/compression.rb +27 -0
- data/lib/ddtrace/utils/object_set.rb +41 -0
- data/lib/ddtrace/utils/only_once.rb +40 -0
- data/lib/ddtrace/utils/sequence.rb +17 -0
- data/lib/ddtrace/utils/string_table.rb +45 -0
- data/lib/ddtrace/utils/time.rb +32 -1
- data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
- data/lib/ddtrace/vendor/multipart-post/LICENSE +11 -0
- data/lib/ddtrace/vendor/multipart-post/multipart.rb +12 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post.rb +8 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/composite_read_io.rb +116 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/multipartable.rb +57 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/parts.rb +135 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/version.rb +9 -0
- data/lib/ddtrace/vendor/multipart-post/net/http/post/multipart.rb +32 -0
- data/lib/ddtrace/version.rb +1 -1
- data/lib/ddtrace/workers.rb +5 -0
- data/lib/ddtrace/workers/async.rb +11 -3
- data/lib/ddtrace/workers/loop.rb +17 -3
- data/lib/ddtrace/workers/polling.rb +1 -0
- data/lib/ddtrace/workers/queue.rb +1 -0
- data/lib/ddtrace/workers/trace_writer.rb +10 -10
- data/lib/ddtrace/writer.rb +7 -4
- metadata +152 -402
- data/lib/ddtrace/augmentation.rb +0 -13
- data/lib/ddtrace/augmentation/method_wrapper.rb +0 -20
- data/lib/ddtrace/augmentation/method_wrapping.rb +0 -38
- data/lib/ddtrace/augmentation/shim.rb +0 -102
- data/lib/ddtrace/contrib/rspec/example_group.rb +0 -61
- data/lib/ddtrace/monkey.rb +0 -58
@@ -123,7 +123,21 @@ module Datadog
|
|
123
123
|
return send_traces(traces)
|
124
124
|
end
|
125
125
|
end
|
126
|
-
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Force resolution of lazy enumerator.
|
129
|
+
#
|
130
|
+
# The "correct" method to call here would be `#force`,
|
131
|
+
# as this method was created to force the eager loading
|
132
|
+
# of a lazy enumerator.
|
133
|
+
#
|
134
|
+
# Unfortunately, JRuby < 9.2.9.0 erroneously eagerly loads
|
135
|
+
# the lazy Enumerator during intermediate steps.
|
136
|
+
# This forces us to use `#to_a`, as this method works for both
|
137
|
+
# lazy and regular Enumerators.
|
138
|
+
# Using `#to_a` can mask the fact that we expect a lazy
|
139
|
+
# Enumerator.
|
140
|
+
responses = responses.to_a
|
127
141
|
|
128
142
|
Datadog.health_metrics.transport_chunked(responses.size)
|
129
143
|
|
@@ -142,17 +156,20 @@ module Datadog
|
|
142
156
|
|
143
157
|
def downgrade?(response)
|
144
158
|
return false unless apis.fallbacks.key?(@current_api_id)
|
159
|
+
|
145
160
|
response.not_found? || response.unsupported?
|
146
161
|
end
|
147
162
|
|
148
163
|
def downgrade!
|
149
164
|
downgrade_api_id = apis.fallbacks[@current_api_id]
|
150
165
|
raise NoDowngradeAvailableError, @current_api_id if downgrade_api_id.nil?
|
166
|
+
|
151
167
|
change_api!(downgrade_api_id)
|
152
168
|
end
|
153
169
|
|
154
170
|
def change_api!(api_id)
|
155
171
|
raise UnknownApiVersionError, api_id unless apis.key?(api_id)
|
172
|
+
|
156
173
|
@current_api_id = api_id
|
157
174
|
@client = HTTP::Client.new(current_api)
|
158
175
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Utils
|
5
|
+
# Common database-related utility functions.
|
6
|
+
module Compression
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def gzip(string, level: nil, strategy: nil)
|
10
|
+
sio = StringIO.new
|
11
|
+
sio.binmode
|
12
|
+
gz = Zlib::GzipWriter.new(sio, level, strategy)
|
13
|
+
gz.write(string)
|
14
|
+
gz.close
|
15
|
+
sio.string
|
16
|
+
end
|
17
|
+
|
18
|
+
def gunzip(string, encoding = ::Encoding::ASCII_8BIT)
|
19
|
+
sio = StringIO.new(string)
|
20
|
+
gz = Zlib::GzipReader.new(sio, encoding: encoding)
|
21
|
+
gz.read
|
22
|
+
ensure
|
23
|
+
gz && gz.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'ddtrace/utils/sequence'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Utils
|
5
|
+
# Acts as a unique dictionary of objects
|
6
|
+
class ObjectSet
|
7
|
+
# You can provide a block that defines how the key
|
8
|
+
# for this message type is resolved.
|
9
|
+
def initialize(seed = 0, &block)
|
10
|
+
@sequence = Utils::Sequence.new(seed)
|
11
|
+
@items = {}
|
12
|
+
@key_block = block
|
13
|
+
end
|
14
|
+
|
15
|
+
# Submit an array of arguments that define the message.
|
16
|
+
# If they match an existing message, it will return the
|
17
|
+
# matching object. If it doesn't match, it will yield to
|
18
|
+
# the block with the next ID & args given.
|
19
|
+
def fetch(*args, &block)
|
20
|
+
key = @key_block ? @key_block.call(*args) : args.hash
|
21
|
+
# TODO: Ruby 2.0 doesn't like yielding here... switch when 2.0 is dropped.
|
22
|
+
# rubocop:disable Performance/RedundantBlockCall
|
23
|
+
@items[key] ||= block.call(@sequence.next, *args)
|
24
|
+
# rubocop:enable Performance/RedundantBlockCall
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
@items.length
|
29
|
+
end
|
30
|
+
|
31
|
+
def objects
|
32
|
+
@items.values
|
33
|
+
end
|
34
|
+
|
35
|
+
def freeze
|
36
|
+
super
|
37
|
+
@items.freeze
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Utils
|
5
|
+
# Helper class to execute something only once such as not repeating warning logs, and instrumenting classes
|
6
|
+
# only once.
|
7
|
+
#
|
8
|
+
# Thread-safe when used correctly (e.g. be careful of races when lazily initializing instances of this class).
|
9
|
+
#
|
10
|
+
# Note: In its current state, this class is not Ractor-safe.
|
11
|
+
# In https://github.com/DataDog/dd-trace-rb/pull/1398#issuecomment-797378810 we have a discussion of alternatives,
|
12
|
+
# including an alternative implementation that is Ractor-safe once spent.
|
13
|
+
class OnlyOnce
|
14
|
+
def initialize
|
15
|
+
@mutex = Mutex.new
|
16
|
+
@ran_once = false
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
@mutex.synchronize do
|
21
|
+
return if @ran_once
|
22
|
+
|
23
|
+
@ran_once = true
|
24
|
+
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ran?
|
30
|
+
@mutex.synchronize { @ran_once }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def reset_ran_once_state_for_tests
|
36
|
+
@mutex.synchronize { @ran_once = false }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Utils
|
3
|
+
# Generates values from a consistent sequence
|
4
|
+
class Sequence
|
5
|
+
def initialize(seed = 0, &block)
|
6
|
+
@current = seed
|
7
|
+
@next_item = block
|
8
|
+
end
|
9
|
+
|
10
|
+
def next
|
11
|
+
next_item = @next_item ? @next_item.call(@current) : @current
|
12
|
+
@current += 1
|
13
|
+
next_item
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'ddtrace/utils/sequence'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Utils
|
5
|
+
# Tracks strings and returns IDs
|
6
|
+
class StringTable
|
7
|
+
def initialize
|
8
|
+
@sequence = Sequence.new
|
9
|
+
@ids = { ''.freeze => @sequence.next }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns an ID for the string
|
13
|
+
def fetch(string)
|
14
|
+
@ids[string.to_s] ||= @sequence.next
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the canonical copy of this string
|
18
|
+
# Typically used for psuedo interning; reduce
|
19
|
+
# identical copies of a string to one object.
|
20
|
+
def fetch_string(string)
|
21
|
+
return nil if string.nil?
|
22
|
+
|
23
|
+
# Co-erce to string
|
24
|
+
string = string.to_s
|
25
|
+
|
26
|
+
# Add to string table if no match
|
27
|
+
@ids[string] = @sequence.next unless @ids.key?(string)
|
28
|
+
|
29
|
+
# Get and return matching string in table
|
30
|
+
# NOTE: Have to resolve the key and retrieve from table again
|
31
|
+
# because "string" argument is not same object as string key.
|
32
|
+
id = @ids[string]
|
33
|
+
@ids.key(id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def [](id)
|
37
|
+
@ids.key(id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def strings
|
41
|
+
@ids.keys
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/ddtrace/utils/time.rb
CHANGED
@@ -6,8 +6,39 @@ module Datadog
|
|
6
6
|
|
7
7
|
module_function
|
8
8
|
|
9
|
+
# Current monotonic time.
|
10
|
+
# Falls back to `now` if monotonic clock
|
11
|
+
# is not available.
|
12
|
+
#
|
13
|
+
# @return [Float] in seconds, since some unspecified starting point
|
9
14
|
def get_time
|
10
|
-
PROCESS_TIME_SUPPORTED ? Process.clock_gettime(Process::CLOCK_MONOTONIC) :
|
15
|
+
PROCESS_TIME_SUPPORTED ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : now.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
# Current wall time.
|
19
|
+
#
|
20
|
+
# @return [Time] current time object
|
21
|
+
def now
|
22
|
+
::Time.now
|
23
|
+
end
|
24
|
+
|
25
|
+
# Overrides the implementation of `#now
|
26
|
+
# with the provided callable.
|
27
|
+
#
|
28
|
+
# Overriding the method `#now` instead of
|
29
|
+
# indirectly calling `block` removes
|
30
|
+
# one level of method call overhead.
|
31
|
+
#
|
32
|
+
# @param block [Proc] block that returns a `Time` object representing the current wall time
|
33
|
+
def now_provider=(block)
|
34
|
+
define_singleton_method(:now, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def measure
|
38
|
+
before = get_time
|
39
|
+
yield
|
40
|
+
after = get_time
|
41
|
+
after - before
|
11
42
|
end
|
12
43
|
end
|
13
44
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2005-2018 David Heinemeier Hansson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Released under the MIT license.
|
2
|
+
|
3
|
+
Copyright, 2007-2013, by Nick Sieger.
|
4
|
+
Copyright, 2017, by Samuel G. D. Williams.
|
5
|
+
Copyright, 2019, by Patrick Davey.
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,116 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2012 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
# Concatenate together multiple IO objects into a single, composite IO object
|
8
|
+
# for purposes of reading as a single stream.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# crio = CompositeReadIO.new(StringIO.new('one'),
|
12
|
+
# StringIO.new('two'),
|
13
|
+
# StringIO.new('three'))
|
14
|
+
# puts crio.read # => "onetwothree"
|
15
|
+
module Datadog
|
16
|
+
module Vendor
|
17
|
+
module Multipart
|
18
|
+
module Post
|
19
|
+
class CompositeReadIO
|
20
|
+
# Create a new composite-read IO from the arguments, all of which should
|
21
|
+
# respond to #read in a manner consistent with IO.
|
22
|
+
def initialize(*ios)
|
23
|
+
@ios = ios.flatten
|
24
|
+
@index = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
# Read from IOs in order until `length` bytes have been received.
|
28
|
+
def read(length = nil, outbuf = nil)
|
29
|
+
got_result = false
|
30
|
+
outbuf = outbuf ? outbuf.replace("") : ""
|
31
|
+
|
32
|
+
while io = current_io
|
33
|
+
if result = io.read(length)
|
34
|
+
got_result ||= !result.nil?
|
35
|
+
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
36
|
+
outbuf << result
|
37
|
+
length -= result.length if length
|
38
|
+
break if length == 0
|
39
|
+
end
|
40
|
+
advance_io
|
41
|
+
end
|
42
|
+
(!got_result && length) ? nil : outbuf
|
43
|
+
end
|
44
|
+
|
45
|
+
def rewind
|
46
|
+
@ios.each { |io| io.rewind }
|
47
|
+
@index = 0
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def current_io
|
53
|
+
@ios[@index]
|
54
|
+
end
|
55
|
+
|
56
|
+
def advance_io
|
57
|
+
@index += 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Convenience methods for dealing with files and IO that are to be uploaded.
|
62
|
+
class UploadIO
|
63
|
+
attr_reader :content_type, :original_filename, :local_path, :io, :opts
|
64
|
+
|
65
|
+
# Create an upload IO suitable for including in the params hash of a
|
66
|
+
# Net::HTTP::Post::Multipart.
|
67
|
+
#
|
68
|
+
# Can take two forms. The first accepts a filename and content type, and
|
69
|
+
# opens the file for reading (to be closed by finalizer).
|
70
|
+
#
|
71
|
+
# The second accepts an already-open IO, but also requires a third argument,
|
72
|
+
# the filename from which it was opened (particularly useful/recommended if
|
73
|
+
# uploading directly from a form in a framework, which often save the file to
|
74
|
+
# an arbitrarily named RackMultipart file in /tmp).
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# UploadIO.new("file.txt", "text/plain")
|
78
|
+
# UploadIO.new(file_io, "text/plain", "file.txt")
|
79
|
+
def initialize(filename_or_io, content_type, filename = nil, opts = {})
|
80
|
+
io = filename_or_io
|
81
|
+
local_path = ""
|
82
|
+
if io.respond_to? :read
|
83
|
+
# in Ruby 1.9.2, StringIOs no longer respond to path
|
84
|
+
# (since they respond to :length, so we don't need their local path, see parts.rb:41)
|
85
|
+
local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : "local.path"
|
86
|
+
else
|
87
|
+
io = File.open(filename_or_io)
|
88
|
+
local_path = filename_or_io
|
89
|
+
end
|
90
|
+
filename ||= local_path
|
91
|
+
|
92
|
+
@content_type = content_type
|
93
|
+
@original_filename = File.basename(filename)
|
94
|
+
@local_path = local_path
|
95
|
+
@io = io
|
96
|
+
@opts = opts
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.convert!(io, content_type, original_filename, local_path)
|
100
|
+
raise ArgumentError, "convert! has been removed. You must now wrap IOs " \
|
101
|
+
"using:\nUploadIO.new(filename_or_io, content_type, " \
|
102
|
+
"filename=nil)\nPlease update your code."
|
103
|
+
end
|
104
|
+
|
105
|
+
def method_missing(*args)
|
106
|
+
@io.send(*args)
|
107
|
+
end
|
108
|
+
|
109
|
+
def respond_to?(meth, include_all = false)
|
110
|
+
@io.respond_to?(meth, include_all) || super(meth, include_all)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007-2013 Nick Sieger.
|
3
|
+
# See the file README.txt included with the distribution for
|
4
|
+
# software license details.
|
5
|
+
#++
|
6
|
+
|
7
|
+
require 'ddtrace/vendor/multipart-post/multipart/post/parts'
|
8
|
+
require 'ddtrace/vendor/multipart-post/multipart/post/composite_read_io'
|
9
|
+
require 'securerandom'
|
10
|
+
|
11
|
+
module Datadog
|
12
|
+
module Vendor
|
13
|
+
module Multipart
|
14
|
+
module Post
|
15
|
+
module Multipartable
|
16
|
+
def self.secure_boundary
|
17
|
+
# https://tools.ietf.org/html/rfc7230
|
18
|
+
# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
|
19
|
+
# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
|
20
|
+
# / DIGIT / ALPHA
|
21
|
+
|
22
|
+
# https://tools.ietf.org/html/rfc2046
|
23
|
+
# bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
|
24
|
+
# "+" / "_" / "," / "-" / "." /
|
25
|
+
# "/" / ":" / "=" / "?"
|
26
|
+
|
27
|
+
"--#{SecureRandom.uuid}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(path, params, headers={}, boundary = Multipartable.secure_boundary)
|
31
|
+
headers = headers.clone # don't want to modify the original variable
|
32
|
+
parts_headers = headers.delete(:parts) || {}
|
33
|
+
super(path, headers)
|
34
|
+
parts = params.map do |k,v|
|
35
|
+
case v
|
36
|
+
when Array
|
37
|
+
v.map {|item| Parts::Part.new(boundary, "#{k}[]", item, parts_headers[k]) }
|
38
|
+
else
|
39
|
+
Parts::Part.new(boundary, k, v, parts_headers[k])
|
40
|
+
end
|
41
|
+
end.flatten
|
42
|
+
parts << Parts::EpiloguePart.new(boundary)
|
43
|
+
ios = parts.map {|p| p.to_io }
|
44
|
+
self.set_content_type(headers["Content-Type"] || "multipart/form-data",
|
45
|
+
{ "boundary" => boundary })
|
46
|
+
self.content_length = parts.inject(0) {|sum,i| sum + i.length }
|
47
|
+
self.body_stream = CompositeReadIO.new(*ios)
|
48
|
+
|
49
|
+
@boundary = boundary
|
50
|
+
end
|
51
|
+
|
52
|
+
attr :boundary
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|