ddtrace 0.37.0 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Appraisals +15 -0
  4. data/CHANGELOG.md +33 -1
  5. data/Rakefile +11 -10
  6. data/docker-compose.yml +2 -2
  7. data/docs/GettingStarted.md +55 -0
  8. data/lib/ddtrace.rb +2 -0
  9. data/lib/ddtrace/configuration/settings.rb +18 -0
  10. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +1 -1
  11. data/lib/ddtrace/contrib/extensions.rb +10 -0
  12. data/lib/ddtrace/contrib/faraday/middleware.rb +5 -3
  13. data/lib/ddtrace/contrib/faraday/patcher.rb +3 -0
  14. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +1 -3
  15. data/lib/ddtrace/contrib/httprb/configuration/settings.rb +27 -0
  16. data/lib/ddtrace/contrib/httprb/ext.rb +14 -0
  17. data/lib/ddtrace/contrib/httprb/instrumentation.rb +163 -0
  18. data/lib/ddtrace/contrib/httprb/integration.rb +43 -0
  19. data/lib/ddtrace/contrib/httprb/patcher.rb +35 -0
  20. data/lib/ddtrace/contrib/kafka/configuration/settings.rb +25 -0
  21. data/lib/ddtrace/contrib/kafka/consumer_event.rb +14 -0
  22. data/lib/ddtrace/contrib/kafka/consumer_group_event.rb +14 -0
  23. data/lib/ddtrace/contrib/kafka/event.rb +51 -0
  24. data/lib/ddtrace/contrib/kafka/events.rb +44 -0
  25. data/lib/ddtrace/contrib/kafka/events/connection/request.rb +34 -0
  26. data/lib/ddtrace/contrib/kafka/events/consumer/process_batch.rb +41 -0
  27. data/lib/ddtrace/contrib/kafka/events/consumer/process_message.rb +39 -0
  28. data/lib/ddtrace/contrib/kafka/events/consumer_group/heartbeat.rb +39 -0
  29. data/lib/ddtrace/contrib/kafka/events/consumer_group/join_group.rb +29 -0
  30. data/lib/ddtrace/contrib/kafka/events/consumer_group/leave_group.rb +29 -0
  31. data/lib/ddtrace/contrib/kafka/events/consumer_group/sync_group.rb +29 -0
  32. data/lib/ddtrace/contrib/kafka/events/produce_operation/send_messages.rb +32 -0
  33. data/lib/ddtrace/contrib/kafka/events/producer/deliver_messages.rb +35 -0
  34. data/lib/ddtrace/contrib/kafka/ext.rb +38 -0
  35. data/lib/ddtrace/contrib/kafka/integration.rb +39 -0
  36. data/lib/ddtrace/contrib/kafka/patcher.rb +26 -0
  37. data/lib/ddtrace/contrib/rack/middlewares.rb +15 -12
  38. data/lib/ddtrace/contrib/rest_client/request_patch.rb +2 -2
  39. data/lib/ddtrace/contrib/sidekiq/ext.rb +1 -0
  40. data/lib/ddtrace/contrib/sidekiq/patcher.rb +8 -1
  41. data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +1 -0
  42. data/lib/ddtrace/diagnostics/environment_logger.rb +278 -0
  43. data/lib/ddtrace/environment.rb +5 -1
  44. data/lib/ddtrace/ext/diagnostics.rb +2 -0
  45. data/lib/ddtrace/ext/environment.rb +2 -0
  46. data/lib/ddtrace/pipeline/span_filter.rb +15 -15
  47. data/lib/ddtrace/sampler.rb +2 -0
  48. data/lib/ddtrace/span.rb +10 -0
  49. data/lib/ddtrace/tracer.rb +13 -6
  50. data/lib/ddtrace/transport/http/adapters/net.rb +8 -0
  51. data/lib/ddtrace/transport/http/adapters/test.rb +4 -0
  52. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +4 -0
  53. data/lib/ddtrace/transport/response.rb +11 -0
  54. data/lib/ddtrace/version.rb +1 -1
  55. data/lib/ddtrace/workers/trace_writer.rb +3 -0
  56. data/lib/ddtrace/writer.rb +33 -12
  57. metadata +27 -3
@@ -0,0 +1,44 @@
1
+ require 'ddtrace/contrib/kafka/events/connection/request'
2
+ require 'ddtrace/contrib/kafka/events/consumer/process_batch'
3
+ require 'ddtrace/contrib/kafka/events/consumer/process_message'
4
+ require 'ddtrace/contrib/kafka/events/consumer_group/heartbeat'
5
+ require 'ddtrace/contrib/kafka/events/consumer_group/join_group'
6
+ require 'ddtrace/contrib/kafka/events/consumer_group/leave_group'
7
+ require 'ddtrace/contrib/kafka/events/consumer_group/sync_group'
8
+ require 'ddtrace/contrib/kafka/events/produce_operation/send_messages'
9
+ require 'ddtrace/contrib/kafka/events/producer/deliver_messages'
10
+
11
+ module Datadog
12
+ module Contrib
13
+ module Kafka
14
+ # Defines collection of instrumented Kafka events
15
+ module Events
16
+ ALL = [
17
+ Events::Connection::Request,
18
+ Events::Consumer::ProcessBatch,
19
+ Events::Consumer::ProcessMessage,
20
+ Events::ConsumerGroup::Heartbeat,
21
+ Events::ConsumerGroup::JoinGroup,
22
+ Events::ConsumerGroup::LeaveGroup,
23
+ Events::ConsumerGroup::SyncGroup,
24
+ Events::ProduceOperation::SendMessages,
25
+ Events::Producer::DeliverMessages
26
+ ].freeze
27
+
28
+ module_function
29
+
30
+ def all
31
+ self::ALL
32
+ end
33
+
34
+ def subscriptions
35
+ all.collect(&:subscriptions).collect(&:to_a).flatten
36
+ end
37
+
38
+ def subscribe!
39
+ all.each(&:subscribe!)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+
4
+ module Datadog
5
+ module Contrib
6
+ module Kafka
7
+ module Events
8
+ module Connection
9
+ # Defines instrumentation for request.connection.kafka event
10
+ module Request
11
+ include Kafka::Event
12
+
13
+ EVENT_NAME = 'request.connection.kafka'.freeze
14
+
15
+ def self.process(span, _event, _id, payload)
16
+ super
17
+
18
+ span.resource = payload[:api]
19
+
20
+ span.set_tag(Ext::TAG_REQUEST_SIZE, payload[:request_size]) if payload.key?(:request_size)
21
+ span.set_tag(Ext::TAG_RESPONSE_SIZE, payload[:response_size]) if payload.key?(:response_size)
22
+ end
23
+
24
+ module_function
25
+
26
+ def span_name
27
+ Ext::SPAN_CONNECTION_REQUEST
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+
5
+ module Datadog
6
+ module Contrib
7
+ module Kafka
8
+ module Events
9
+ module Consumer
10
+ # Defines instrumentation for process_batch.consumer.kafka event
11
+ module ProcessBatch
12
+ include Kafka::Event
13
+ extend Kafka::ConsumerEvent
14
+
15
+ EVENT_NAME = 'process_batch.consumer.kafka'.freeze
16
+
17
+ def self.process(span, _event, _id, payload)
18
+ super
19
+
20
+ span.resource = payload[:topic]
21
+
22
+ span.set_tag(Ext::TAG_TOPIC, payload[:topic]) if payload.key?(:topic)
23
+ span.set_tag(Ext::TAG_MESSAGE_COUNT, payload[:message_count]) if payload.key?(:message_count)
24
+ span.set_tag(Ext::TAG_PARTITION, payload[:partition]) if payload.key?(:partition)
25
+ if payload.key?(:highwater_mark_offset)
26
+ span.set_tag(Ext::TAG_HIGHWATER_MARK_OFFSET, payload[:highwater_mark_offset])
27
+ end
28
+ span.set_tag(Ext::TAG_OFFSET_LAG, payload[:offset_lag]) if payload.key?(:offset_lag)
29
+ end
30
+
31
+ module_function
32
+
33
+ def span_name
34
+ Ext::SPAN_PROCESS_BATCH
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+
5
+ module Datadog
6
+ module Contrib
7
+ module Kafka
8
+ module Events
9
+ module Consumer
10
+ # Defines instrumentation for process_message.consumer.kafka event
11
+ module ProcessMessage
12
+ include Kafka::Event
13
+ extend Kafka::ConsumerEvent
14
+
15
+ EVENT_NAME = 'process_message.consumer.kafka'.freeze
16
+
17
+ def self.process(span, _event, _id, payload)
18
+ super
19
+
20
+ span.resource = payload[:topic]
21
+
22
+ span.set_tag(Ext::TAG_TOPIC, payload[:topic]) if payload.key?(:topic)
23
+ span.set_tag(Ext::TAG_MESSAGE_KEY, payload[:key]) if payload.key?(:key)
24
+ span.set_tag(Ext::TAG_PARTITION, payload[:partition]) if payload.key?(:partition)
25
+ span.set_tag(Ext::TAG_OFFSET, payload[:offset]) if payload.key?(:offset)
26
+ span.set_tag(Ext::TAG_OFFSET_LAG, payload[:offset_lag]) if payload.key?(:offset_lag)
27
+ end
28
+
29
+ module_function
30
+
31
+ def span_name
32
+ Ext::SPAN_PROCESS_MESSAGE
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+ require 'ddtrace/contrib/kafka/consumer_group_event'
5
+
6
+ module Datadog
7
+ module Contrib
8
+ module Kafka
9
+ module Events
10
+ module ConsumerGroup
11
+ # Defines instrumentation for heartbeat.consumer.kafka event
12
+ module Heartbeat
13
+ include Kafka::Event
14
+ extend Kafka::ConsumerEvent
15
+ extend Kafka::ConsumerGroupEvent
16
+
17
+ EVENT_NAME = 'heartbeat.consumer.kafka'.freeze
18
+
19
+ def self.process(span, _event, _id, payload)
20
+ super
21
+
22
+ if payload.key?(:topic_partitions)
23
+ payload[:topic_partitions].each do |topic, partitions|
24
+ span.set_tag("#{Ext::TAG_TOPIC_PARTITIONS}.#{topic}", partitions)
25
+ end
26
+ end
27
+ end
28
+
29
+ module_function
30
+
31
+ def span_name
32
+ Ext::SPAN_CONSUMER_HEARTBEAT
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+ require 'ddtrace/contrib/kafka/consumer_group_event'
5
+
6
+ module Datadog
7
+ module Contrib
8
+ module Kafka
9
+ module Events
10
+ module ConsumerGroup
11
+ # Defines instrumentation for join_group.consumer.kafka event
12
+ module JoinGroup
13
+ include Kafka::Event
14
+ extend Kafka::ConsumerEvent
15
+ extend Kafka::ConsumerGroupEvent
16
+
17
+ EVENT_NAME = 'join_group.consumer.kafka'.freeze
18
+
19
+ module_function
20
+
21
+ def span_name
22
+ Ext::SPAN_CONSUMER_JOIN_GROUP
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+ require 'ddtrace/contrib/kafka/consumer_group_event'
5
+
6
+ module Datadog
7
+ module Contrib
8
+ module Kafka
9
+ module Events
10
+ module ConsumerGroup
11
+ # Defines instrumentation for leave_group.consumer.kafka event
12
+ module LeaveGroup
13
+ include Kafka::Event
14
+ extend Kafka::ConsumerEvent
15
+ extend Kafka::ConsumerGroupEvent
16
+
17
+ EVENT_NAME = 'leave_group.consumer.kafka'.freeze
18
+
19
+ module_function
20
+
21
+ def span_name
22
+ Ext::SPAN_CONSUMER_LEAVE_GROUP
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+ require 'ddtrace/contrib/kafka/consumer_event'
4
+ require 'ddtrace/contrib/kafka/consumer_group_event'
5
+
6
+ module Datadog
7
+ module Contrib
8
+ module Kafka
9
+ module Events
10
+ module ConsumerGroup
11
+ # Defines instrumentation for sync_group.consumer.kafka event
12
+ module SyncGroup
13
+ include Kafka::Event
14
+ extend Kafka::ConsumerEvent
15
+ extend Kafka::ConsumerGroupEvent
16
+
17
+ EVENT_NAME = 'sync_group.consumer.kafka'.freeze
18
+
19
+ module_function
20
+
21
+ def span_name
22
+ Ext::SPAN_CONSUMER_SYNC_GROUP
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+
4
+ module Datadog
5
+ module Contrib
6
+ module Kafka
7
+ module Events
8
+ module ProduceOperation
9
+ # Defines instrumentation for send_messages.producer.kafka event
10
+ module SendMessages
11
+ include Kafka::Event
12
+
13
+ EVENT_NAME = 'send_messages.producer.kafka'.freeze
14
+
15
+ def self.process(span, _event, _id, payload)
16
+ super
17
+
18
+ span.set_tag(Ext::TAG_MESSAGE_COUNT, payload[:message_count]) if payload.key?(:message_count)
19
+ span.set_tag(Ext::TAG_SENT_MESSAGE_COUNT, payload[:sent_message_count]) if payload.key?(:sent_message_count)
20
+ end
21
+
22
+ module_function
23
+
24
+ def span_name
25
+ Ext::SPAN_SEND_MESSAGES
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require 'ddtrace/contrib/kafka/ext'
2
+ require 'ddtrace/contrib/kafka/event'
3
+
4
+ module Datadog
5
+ module Contrib
6
+ module Kafka
7
+ module Events
8
+ module Producer
9
+ # Defines instrumentation for deliver_messages.producer.kafka event
10
+ module DeliverMessages
11
+ include Kafka::Event
12
+
13
+ EVENT_NAME = 'deliver_messages.producer.kafka'.freeze
14
+
15
+ def self.process(span, _event, _id, payload)
16
+ super
17
+
18
+ span.set_tag(Ext::TAG_ATTEMPTS, payload[:attempts]) if payload.key?(:attempts)
19
+ span.set_tag(Ext::TAG_MESSAGE_COUNT, payload[:message_count]) if payload.key?(:message_count)
20
+ if payload.key?(:delivered_message_count)
21
+ span.set_tag(Ext::TAG_DELIVERED_MESSAGE_COUNT, payload[:delivered_message_count])
22
+ end
23
+ end
24
+
25
+ module_function
26
+
27
+ def span_name
28
+ Ext::SPAN_DELIVER_MESSAGES
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ module Datadog
2
+ module Contrib
3
+ module Kafka
4
+ # Kafka integration constants
5
+ module Ext
6
+ APP = 'kafka'.freeze
7
+ ENV_ANALYTICS_ENABLED = 'DD_KAFKA_ANALYTICS_ENABLED'.freeze
8
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_KAFKA_ANALYTICS_SAMPLE_RATE'.freeze
9
+ SERVICE_NAME = 'kafka'.freeze
10
+ SPAN_CONNECTION_REQUEST = 'kafka.connection.request'.freeze
11
+ SPAN_CONSUMER_HEARTBEAT = 'kafka.consumer.heartbeat'.freeze
12
+ SPAN_CONSUMER_JOIN_GROUP = 'kafka.consumer.join_group'.freeze
13
+ SPAN_CONSUMER_LEAVE_GROUP = 'kafka.consumer.leave_group'.freeze
14
+ SPAN_CONSUMER_SYNC_GROUP = 'kafka.consumer.sync_group'.freeze
15
+ SPAN_DELIVER_MESSAGES = 'kafka.producer.deliver_messages'.freeze
16
+ SPAN_PROCESS_BATCH = 'kafka.consumer.process_batch'.freeze
17
+ SPAN_PROCESS_MESSAGE = 'kafka.consumer.process_message'.freeze
18
+ SPAN_SEND_MESSAGES = 'kafka.producer.send_messages'.freeze
19
+ TAG_ATTEMPTS = 'kafka.attempts'.freeze
20
+ TAG_API = 'kafka.api'.freeze
21
+ TAG_CLIENT = 'kafka.client'.freeze
22
+ TAG_GROUP = 'kafka.group'.freeze
23
+ TAG_HIGHWATER_MARK_OFFSET = 'kafka.highwater_mark_offset'.freeze
24
+ TAG_MESSAGE_COUNT = 'kafka.message_count'.freeze
25
+ TAG_MESSAGE_KEY = 'kafka.message_key'.freeze
26
+ TAG_DELIVERED_MESSAGE_COUNT = 'kafka.delivered_message_count'.freeze
27
+ TAG_OFFSET = 'kafka.offset'.freeze
28
+ TAG_OFFSET_LAG = 'kafka.offset_lag'.freeze
29
+ TAG_PARTITION = 'kafka.partition'.freeze
30
+ TAG_REQUEST_SIZE = 'kafka.request_size'.freeze
31
+ TAG_RESPONSE_SIZE = 'kafka.response_size'.freeze
32
+ TAG_SENT_MESSAGE_COUNT = 'kafka.sent_message_count'.freeze
33
+ TAG_TOPIC = 'kafka.topic'.freeze
34
+ TAG_TOPIC_PARTITIONS = 'kafka.topic_partitions'.freeze
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'ddtrace/contrib/integration'
2
+ require 'ddtrace/contrib/kafka/configuration/settings'
3
+ require 'ddtrace/contrib/kafka/patcher'
4
+
5
+ module Datadog
6
+ module Contrib
7
+ module Kafka
8
+ # Description of Kafka integration
9
+ class Integration
10
+ include Contrib::Integration
11
+
12
+ MINIMUM_VERSION = Gem::Version.new('0.7.10')
13
+
14
+ register_as :kafka, auto_patch: false
15
+
16
+ def self.version
17
+ Gem.loaded_specs['ruby-kafka'] && Gem.loaded_specs['ruby-kafka'].version
18
+ end
19
+
20
+ def self.loaded?
21
+ !defined?(::Kafka).nil? \
22
+ && !defined?(::ActiveSupport::Notifications).nil?
23
+ end
24
+
25
+ def self.compatible?
26
+ super && version >= MINIMUM_VERSION
27
+ end
28
+
29
+ def default_configuration
30
+ Configuration::Settings.new
31
+ end
32
+
33
+ def patcher
34
+ Patcher
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ require 'ddtrace/contrib/patcher'
2
+ require 'ddtrace/ext/app_types'
3
+ require 'ddtrace/contrib/kafka/ext'
4
+ require 'ddtrace/contrib/kafka/events'
5
+
6
+ module Datadog
7
+ module Contrib
8
+ module Kafka
9
+ # Patcher enables patching of 'kafka' module.
10
+ module Patcher
11
+ include Contrib::Patcher
12
+
13
+ module_function
14
+
15
+ def target_version
16
+ Integration.version
17
+ end
18
+
19
+ def patch
20
+ # Subscribe to Kafka events
21
+ Events.subscribe!
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end