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
data/lib/ddtrace/span.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'time'
|
4
|
-
require 'thread'
|
5
|
-
|
6
4
|
require 'ddtrace/utils'
|
7
5
|
require 'ddtrace/ext/errors'
|
8
6
|
require 'ddtrace/ext/priority'
|
@@ -38,14 +36,16 @@ module Datadog
|
|
38
36
|
EXTERNAL_MAX_ID = 1 << 64
|
39
37
|
|
40
38
|
# This limit is for numeric tags because uint64 could end up rounded.
|
41
|
-
NUMERIC_TAG_SIZE_RANGE = (-1 << 53..1 << 53)
|
39
|
+
NUMERIC_TAG_SIZE_RANGE = (-1 << 53..1 << 53).freeze
|
42
40
|
|
43
41
|
attr_accessor :name, :service, :resource, :span_type,
|
44
42
|
:span_id, :trace_id, :parent_id,
|
45
43
|
:status, :sampled,
|
46
|
-
:tracer, :context
|
44
|
+
:tracer, :context
|
45
|
+
|
46
|
+
attr_reader :parent, :start_time, :end_time
|
47
47
|
|
48
|
-
|
48
|
+
attr_writer :duration
|
49
49
|
|
50
50
|
# Create a new span linked to the given tracer. Call the \Tracer method <tt>start_span()</tt>
|
51
51
|
# and then <tt>finish()</tt> once the tracer operation is over.
|
@@ -180,7 +180,7 @@ module Datadog
|
|
180
180
|
# behavior and so we maintain it for backward compatibility for those
|
181
181
|
# who are using async manual instrumentation that may rely on this
|
182
182
|
|
183
|
-
@start_time = start_time || Time.now.utc
|
183
|
+
@start_time = start_time || Utils::Time.now.utc
|
184
184
|
@duration_start = start_time.nil? ? duration_marker : nil
|
185
185
|
|
186
186
|
self
|
@@ -206,7 +206,7 @@ module Datadog
|
|
206
206
|
|
207
207
|
@allocation_count_finish = now_allocations
|
208
208
|
|
209
|
-
now = Time.now.utc
|
209
|
+
now = Utils::Time.now.utc
|
210
210
|
|
211
211
|
# Provide a default start_time if unset.
|
212
212
|
# Using `now` here causes duration to be 0; this is expected
|
data/lib/ddtrace/sync_writer.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
require 'ddtrace/ext/net'
|
2
2
|
require 'ddtrace/runtime/socket'
|
3
3
|
require 'ddtrace/runtime/metrics'
|
4
|
+
require 'ddtrace/utils/only_once'
|
4
5
|
|
5
6
|
module Datadog
|
6
7
|
# SyncWriter flushes both services and traces synchronously
|
7
8
|
# DEV: To be replaced by Datadog::Workers::TraceWriter.
|
9
|
+
#
|
10
|
+
# Note: If you're wondering if this class is used at all, since there are no other references to it on the codebase,
|
11
|
+
# the separate `datadog-lambda` uses it as of February 2021:
|
12
|
+
# <https://github.com/DataDog/datadog-lambda-rb/blob/c15f0f0916c90123416dc44e7d6800ef4a7cfdbf/lib/datadog/lambda.rb#L38>
|
8
13
|
class SyncWriter
|
14
|
+
DEPRECATION_WARN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
|
15
|
+
|
9
16
|
attr_reader \
|
10
17
|
:priority_sampler,
|
11
18
|
:transport
|
@@ -21,17 +28,15 @@ module Datadog
|
|
21
28
|
|
22
29
|
def write(trace, services = nil)
|
23
30
|
unless services.nil?
|
24
|
-
|
31
|
+
DEPRECATION_WARN_ONLY_ONCE.run do
|
25
32
|
Datadog.logger.warn(%(
|
26
33
|
write: Writing services has been deprecated and no longer need to be provided.
|
27
|
-
write(traces, services) can be
|
34
|
+
write(traces, services) can be updated to write(traces)
|
28
35
|
))
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
|
33
|
-
proc { flush_trace(trace) }
|
34
|
-
)
|
39
|
+
flush_trace(trace)
|
35
40
|
rescue => e
|
36
41
|
Datadog.logger.debug(e)
|
37
42
|
end
|
@@ -44,13 +49,10 @@ module Datadog
|
|
44
49
|
|
45
50
|
private
|
46
51
|
|
47
|
-
def perform_concurrently(*tasks)
|
48
|
-
tasks.map { |task| Thread.new(&task) }.each(&:join)
|
49
|
-
end
|
50
|
-
|
51
52
|
def flush_trace(trace)
|
52
53
|
processed_traces = Pipeline.process!([trace])
|
53
54
|
return if processed_traces.empty?
|
55
|
+
|
54
56
|
inject_hostname!(processed_traces.first) if Datadog.configuration.report_hostname
|
55
57
|
transport.send_traces(processed_traces)
|
56
58
|
end
|
@@ -58,9 +60,7 @@ module Datadog
|
|
58
60
|
def inject_hostname!(trace)
|
59
61
|
unless trace.first.nil?
|
60
62
|
hostname = Datadog::Runtime::Socket.hostname
|
61
|
-
unless hostname.nil? || hostname.empty?
|
62
|
-
trace.first.set_tag(Ext::NET::TAG_HOSTNAME, hostname)
|
63
|
-
end
|
63
|
+
trace.first.set_tag(Ext::NET::TAG_HOSTNAME, hostname) unless hostname.nil? || hostname.empty?
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
data/lib/ddtrace/tracer.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'thread'
|
2
1
|
require 'logger'
|
3
2
|
require 'pathname'
|
4
3
|
|
@@ -11,6 +10,7 @@ require 'ddtrace/runtime/identity'
|
|
11
10
|
require 'ddtrace/sampler'
|
12
11
|
require 'ddtrace/sampling'
|
13
12
|
require 'ddtrace/correlation'
|
13
|
+
require 'ddtrace/utils/only_once'
|
14
14
|
|
15
15
|
# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
|
16
16
|
module Datadog
|
@@ -20,6 +20,9 @@ module Datadog
|
|
20
20
|
# of these function calls and sub-requests would be encapsulated within a single trace.
|
21
21
|
# rubocop:disable Metrics/ClassLength
|
22
22
|
class Tracer
|
23
|
+
SERVICES_DEPRECATION_WARN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
|
24
|
+
SET_SERVICE_INFO_DEPRECATION_WARN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
|
25
|
+
|
23
26
|
attr_reader :sampler, :tags, :provider, :context_flush
|
24
27
|
attr_accessor :enabled, :writer
|
25
28
|
attr_writer :default_service
|
@@ -28,8 +31,7 @@ module Datadog
|
|
28
31
|
DEFAULT_ON_ERROR = proc { |span, error| span.set_error(error) unless span.nil? }
|
29
32
|
|
30
33
|
def services
|
31
|
-
|
32
|
-
Datadog::Patcher.do_once('Tracer#set_service_info') do
|
34
|
+
SERVICES_DEPRECATION_WARN_ONLY_ONCE.run do
|
33
35
|
Datadog.logger.warn('services: Usage of Tracer.services has been deprecated')
|
34
36
|
end
|
35
37
|
|
@@ -130,8 +132,7 @@ module Datadog
|
|
130
132
|
#
|
131
133
|
# set_service_info is deprecated, no service information needs to be tracked
|
132
134
|
def set_service_info(service, app, app_type)
|
133
|
-
|
134
|
-
Datadog::Patcher.do_once('Tracer#set_service_info') do
|
135
|
+
SET_SERVICE_INFO_DEPRECATION_WARN_ONLY_ONCE.run do
|
135
136
|
Datadog.logger.warn(%(
|
136
137
|
set_service_info: Usage of set_service_info has been deprecated,
|
137
138
|
service information no longer needs to be reported to the trace agent.
|
@@ -144,6 +145,7 @@ module Datadog
|
|
144
145
|
# a service would be invalid and rejected.
|
145
146
|
def default_service
|
146
147
|
return @default_service if instance_variable_defined?(:@default_service) && @default_service
|
148
|
+
|
147
149
|
begin
|
148
150
|
@default_service = File.basename($PROGRAM_NAME, '.*')
|
149
151
|
rescue StandardError => e
|
@@ -27,7 +27,7 @@ module Datadog
|
|
27
27
|
# Pass a block to override any settings.
|
28
28
|
def default(options = {})
|
29
29
|
new do |transport|
|
30
|
-
transport.adapter
|
30
|
+
transport.adapter default_adapter, default_hostname, default_port, timeout: 1
|
31
31
|
transport.headers default_headers
|
32
32
|
|
33
33
|
apis = API.defaults
|
@@ -39,10 +39,15 @@ module Datadog
|
|
39
39
|
# Apply any settings given by options
|
40
40
|
unless options.empty?
|
41
41
|
# Change hostname/port
|
42
|
-
if
|
43
|
-
hostname = options
|
44
|
-
port = options
|
45
|
-
|
42
|
+
if [:hostname, :port, :timeout, :ssl].any? { |key| options.key?(key) }
|
43
|
+
hostname = options[:hostname] || default_hostname
|
44
|
+
port = options[:port] || default_port
|
45
|
+
|
46
|
+
adapter_options = { timeout: 1 }
|
47
|
+
adapter_options[:timeout] = options[:timeout] if options.key?(:timeout)
|
48
|
+
adapter_options[:ssl] = options[:ssl] if options.key?(:ssl)
|
49
|
+
|
50
|
+
transport.adapter default_adapter, hostname, port, adapter_options
|
46
51
|
end
|
47
52
|
|
48
53
|
# Change default API
|
@@ -69,12 +74,14 @@ module Datadog
|
|
69
74
|
}.tap do |headers|
|
70
75
|
# Add container ID, if present.
|
71
76
|
container_id = Datadog::Runtime::Container.container_id
|
72
|
-
unless container_id.nil?
|
73
|
-
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id
|
74
|
-
end
|
77
|
+
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
75
78
|
end
|
76
79
|
end
|
77
80
|
|
81
|
+
def default_adapter
|
82
|
+
:net_http
|
83
|
+
end
|
84
|
+
|
78
85
|
def default_hostname
|
79
86
|
return default_url.hostname if default_url
|
80
87
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'ddtrace/transport/response'
|
2
|
+
require 'ddtrace/vendor/multipart-post/net/http/post/multipart'
|
2
3
|
|
3
4
|
module Datadog
|
4
5
|
module Transport
|
@@ -9,27 +10,28 @@ module Datadog
|
|
9
10
|
attr_reader \
|
10
11
|
:hostname,
|
11
12
|
:port,
|
12
|
-
:timeout
|
13
|
+
:timeout,
|
14
|
+
:ssl
|
13
15
|
|
14
|
-
DEFAULT_TIMEOUT =
|
16
|
+
DEFAULT_TIMEOUT = 30
|
15
17
|
|
16
18
|
def initialize(hostname, port, options = {})
|
17
19
|
@hostname = hostname
|
18
20
|
@port = port
|
19
21
|
@timeout = options[:timeout] || DEFAULT_TIMEOUT
|
22
|
+
@ssl = options.key?(:ssl) ? options[:ssl] == true : false
|
20
23
|
end
|
21
24
|
|
22
|
-
def open
|
25
|
+
def open(&block)
|
23
26
|
# DEV Initializing +Net::HTTP+ directly help us avoid expensive
|
24
27
|
# options processing done in +Net::HTTP.start+:
|
25
28
|
# https://github.com/ruby/ruby/blob/b2d96abb42abbe2e01f010ffc9ac51f0f9a50002/lib/net/http.rb#L614-L618
|
26
29
|
req = ::Net::HTTP.new(hostname, port, nil)
|
27
30
|
|
31
|
+
req.use_ssl = ssl
|
28
32
|
req.open_timeout = req.read_timeout = timeout
|
29
33
|
|
30
|
-
req.start
|
31
|
-
yield(http)
|
32
|
-
end
|
34
|
+
req.start(&block)
|
33
35
|
end
|
34
36
|
|
35
37
|
def call(env)
|
@@ -41,8 +43,18 @@ module Datadog
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def post(env)
|
44
|
-
post =
|
45
|
-
|
46
|
+
post = nil
|
47
|
+
|
48
|
+
if env.form.nil? || env.form.empty?
|
49
|
+
post = ::Net::HTTP::Post.new(env.path, env.headers)
|
50
|
+
post.body = env.body
|
51
|
+
else
|
52
|
+
post = ::Datadog::Vendor::Net::HTTP::Post::Multipart.new(
|
53
|
+
env.path,
|
54
|
+
env.form,
|
55
|
+
env.headers
|
56
|
+
)
|
57
|
+
end
|
46
58
|
|
47
59
|
# Connect and send the request
|
48
60
|
http_response = open do |http|
|
@@ -82,36 +94,43 @@ module Datadog
|
|
82
94
|
|
83
95
|
def payload
|
84
96
|
return super if http_response.nil?
|
97
|
+
|
85
98
|
http_response.body
|
86
99
|
end
|
87
100
|
|
88
101
|
def code
|
89
102
|
return super if http_response.nil?
|
103
|
+
|
90
104
|
http_response.code.to_i
|
91
105
|
end
|
92
106
|
|
93
107
|
def ok?
|
94
108
|
return super if http_response.nil?
|
109
|
+
|
95
110
|
code.between?(200, 299)
|
96
111
|
end
|
97
112
|
|
98
113
|
def unsupported?
|
99
114
|
return super if http_response.nil?
|
115
|
+
|
100
116
|
code == 415
|
101
117
|
end
|
102
118
|
|
103
119
|
def not_found?
|
104
120
|
return super if http_response.nil?
|
121
|
+
|
105
122
|
code == 404
|
106
123
|
end
|
107
124
|
|
108
125
|
def client_error?
|
109
126
|
return super if http_response.nil?
|
127
|
+
|
110
128
|
code.between?(400, 499)
|
111
129
|
end
|
112
130
|
|
113
131
|
def server_error?
|
114
132
|
return super if http_response.nil?
|
133
|
+
|
115
134
|
code.between?(500, 599)
|
116
135
|
end
|
117
136
|
|
@@ -18,7 +18,7 @@ module Datadog
|
|
18
18
|
@timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
|
19
19
|
end
|
20
20
|
|
21
|
-
def open
|
21
|
+
def open(&block)
|
22
22
|
# Open connection
|
23
23
|
connection = HTTP.new(
|
24
24
|
filepath,
|
@@ -26,9 +26,7 @@ module Datadog
|
|
26
26
|
continue_timeout: timeout
|
27
27
|
)
|
28
28
|
|
29
|
-
connection.start
|
30
|
-
yield(http)
|
31
|
-
end
|
29
|
+
connection.start(&block)
|
32
30
|
end
|
33
31
|
|
34
32
|
def url
|
@@ -36,6 +36,7 @@ module Datadog
|
|
36
36
|
@default_adapter = if type.is_a?(Symbol)
|
37
37
|
registry_klass = REGISTRY.get(type)
|
38
38
|
raise UnknownAdapterError, type if registry_klass.nil?
|
39
|
+
|
39
40
|
registry_klass.new(*args)
|
40
41
|
else
|
41
42
|
type
|
@@ -67,6 +68,7 @@ module Datadog
|
|
67
68
|
|
68
69
|
def default_api=(key)
|
69
70
|
raise UnknownApiError, key unless @apis.key?(key)
|
71
|
+
|
70
72
|
@default_api = key
|
71
73
|
end
|
72
74
|
|
@@ -93,7 +95,7 @@ module Datadog
|
|
93
95
|
api_options[:headers] = @default_headers.merge((api_options[:headers] || {}))
|
94
96
|
|
95
97
|
# Add API::Instance with all settings
|
96
|
-
instances[key] =
|
98
|
+
instances[key] = api_instance_class.new(
|
97
99
|
spec,
|
98
100
|
adapter,
|
99
101
|
api_options
|
@@ -105,6 +107,10 @@ module Datadog
|
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
110
|
+
def api_instance_class
|
111
|
+
API::Instance
|
112
|
+
end
|
113
|
+
|
108
114
|
# Raised when the API key does not match known APIs.
|
109
115
|
class UnknownApiError < StandardError
|
110
116
|
attr_reader :key
|
@@ -41,6 +41,7 @@ module Datadog
|
|
41
41
|
|
42
42
|
def send_traces(env, &block)
|
43
43
|
raise NoTraceEndpointDefinedError, self if traces.nil?
|
44
|
+
|
44
45
|
traces.call(env, &block)
|
45
46
|
end
|
46
47
|
|
@@ -121,9 +122,7 @@ module Datadog
|
|
121
122
|
# Parse service rates, if configured to do so.
|
122
123
|
if service_rates? && !http_response.payload.to_s.empty?
|
123
124
|
body = JSON.parse(http_response.payload)
|
124
|
-
if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
|
125
|
-
options[:service_rates] = body[SERVICE_RATE_KEY]
|
126
|
-
end
|
125
|
+
options[:service_rates] = body[SERVICE_RATE_KEY] if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
data/lib/ddtrace/transport/io.rb
CHANGED
@@ -6,14 +6,12 @@ module Datadog
|
|
6
6
|
# Response from HTTP transport for traces
|
7
7
|
class Response
|
8
8
|
include Transport::Response
|
9
|
-
include Transport::Traces::Response
|
10
9
|
|
11
10
|
attr_reader \
|
12
11
|
:result
|
13
12
|
|
14
|
-
def initialize(result
|
13
|
+
def initialize(result)
|
15
14
|
@result = result
|
16
|
-
@trace_count = trace_count
|
17
15
|
end
|
18
16
|
|
19
17
|
def ok?
|
@@ -10,6 +10,12 @@ module Datadog
|
|
10
10
|
module Traces
|
11
11
|
# Response from HTTP transport for traces
|
12
12
|
class Response < IO::Response
|
13
|
+
include Transport::Traces::Response
|
14
|
+
|
15
|
+
def initialize(result, trace_count = 1)
|
16
|
+
super(result)
|
17
|
+
@trace_count = trace_count
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
# Extensions for HTTP client
|