Skip to content

Commit

Permalink
[httprb] resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmustin committed Jul 9, 2020
2 parents 04e431d + 8f575a1 commit 24d2036
Show file tree
Hide file tree
Showing 37 changed files with 1,643 additions and 283 deletions.
7 changes: 7 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ elsif Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel', '~> 4.0', '< 4.37'
gem 'shoryuken'
gem 'sidekiq', '~> 3.5.4'
Expand Down Expand Up @@ -356,6 +357,7 @@ elsif Gem::Version.new('2.2.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down Expand Up @@ -517,6 +519,7 @@ elsif Gem::Version.new('2.3.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down Expand Up @@ -597,6 +600,7 @@ elsif Gem::Version.new('2.4.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down Expand Up @@ -710,6 +714,7 @@ elsif Gem::Version.new('2.5.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down Expand Up @@ -823,6 +828,7 @@ elsif Gem::Version.new('2.6.0') <= Gem::Version.new(RUBY_VERSION) \
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down Expand Up @@ -938,6 +944,7 @@ elsif Gem::Version.new('2.7.0') <= Gem::Version.new(RUBY_VERSION)
gem 'redis', '< 4.0'
gem 'rest-client'
gem 'resque', '< 2.0'
gem 'ruby-kafka', '>= 0.7.10'
gem 'sequel'
gem 'shoryuken'
gem 'sidekiq'
Expand Down
12 changes: 2 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace :spec do
:grpc,
:http,
:httprb,
:kafka,
:mongodb,
:mysql2,
:presto,
Expand All @@ -122,7 +123,7 @@ end
namespace :test do
task all: [:main,
:rails,
:sidekiq, :monkey]
:monkey]

Rake::TestTask.new(:main) do |t|
t.libs << %w[test lib]
Expand All @@ -141,7 +142,6 @@ namespace :test do

[
:grape,
:sidekiq,
:sucker_punch
].each do |contrib|
Rake::TestTask.new(contrib) do |t|
Expand Down Expand Up @@ -200,7 +200,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib-old rake test:monkey'
sh 'bundle exec appraisal contrib-old rake test:sidekiq'
sh 'bundle exec appraisal contrib-old rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib-old rake spec:active_model_serializers'
Expand Down Expand Up @@ -258,7 +257,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib-old rake test:monkey'
sh 'bundle exec appraisal contrib-old rake test:sidekiq'
sh 'bundle exec appraisal contrib-old rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib-old rake spec:active_model_serializers'
Expand Down Expand Up @@ -323,7 +321,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down Expand Up @@ -399,7 +396,6 @@ task :ci do
if RUBY_PLATFORM != 'java'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down Expand Up @@ -480,7 +476,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down Expand Up @@ -546,7 +541,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down Expand Up @@ -622,7 +616,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down Expand Up @@ -697,7 +690,6 @@ task :ci do
sh 'bundle exec rake benchmark'
# Contrib minitests
sh 'bundle exec appraisal contrib rake test:grape'
sh 'bundle exec appraisal contrib rake test:sidekiq'
sh 'bundle exec appraisal contrib rake test:sucker_punch'
# Contrib specs
sh 'bundle exec appraisal contrib rake spec:action_pack'
Expand Down
29 changes: 26 additions & 3 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ For a list of available integrations, and their configuration options, please re
| Grape | `grape` | `>= 1.0` | *[Link](#grape)* | *[Link](https://github.com/ruby-grape/grape)* |
| GraphQL | `graphql` | `>= 1.7.9` | *[Link](#graphql)* | *[Link](https://github.com/rmosolgo/graphql-ruby)* |
| gRPC | `grpc` | `>= 1.7` | *[Link](#grpc)* | *[Link](https://github.com/grpc/grpc/tree/master/src/rubyc)* |
| http.rb | `httprb` | `>= 2.0` | *[Link](#http.rb)* | *[Link](https://github.com/httprb/http)* |
| http.rb | `httprb` | `>= 2.0` | *[Link](#http.rb)* | *[Link](https://github.com/httprb/http)* |
| Kafka | `ruby-kafka` | `>= 0.7.10` | *[Link](#kafka)* | |
| MongoDB | `mongo` | `>= 2.1` | *[Link](#mongodb)* | *[Link](https://github.com/mongodb/mongo-ruby-driver)* |
| MySQL2 | `mysql2` | `>= 0.3.21` | *[Link](#mysql2)* | *[Link](https://github.com/brianmario/mysql2)* |
| Net/HTTP | `http` | *(Any supported Ruby)* | *[Link](#nethttp)* | *[Link](https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html)* |
Expand Down Expand Up @@ -938,10 +939,8 @@ The http.rb integration will trace any HTTP call using the Http.rb gem.
```ruby
require 'http'
require 'ddtrace'
Datadog.configure do |c|
c.use :httprb, options
# optionally, specify a different service name for hostnames matching a regex
c.use :httprb, describes: /user-[^.]+\.example\.com/ do |httprb|
httprb.service_name = 'user.example.com'
Expand All @@ -959,6 +958,30 @@ Where `options` is an optional `Hash` that accepts the following parameters:
| `service_name` | Service name for `httprb` instrumentation. | `'httprb'` |
| `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
### Kafka
The Kafka integration provides tracing of the `ruby-kafka` gem:
You can enable it through `Datadog.configure`:
```ruby
require 'active_support/notifications' # required to enable 'ruby-kafka' instrumentation
require 'kafka'
require 'ddtrace'
Datadog.configure do |c|
c.use :kafka, options
end
```
Where `options` is an optional `Hash` that accepts the following parameters:
| Key | Description | Default |
| --- | ----------- | ------- |
| `analytics_enabled` | Enable analytics for spans produced by this integration. `true` for on, `nil` to defer to global setting, `false` for off. | `false` |
| `service_name` | Service name used for `kafka` instrumentation | `'kafka'` |
| `tracer` | `Datadog::Tracer` used to perform instrumentation. Usually you don't need to set this. | `Datadog.tracer` |

### MongoDB

The integration traces any `Command` that is sent from the [MongoDB Ruby Driver](https://github.com/mongodb/mongo-ruby-driver) to a MongoDB cluster. By extension, Object Document Mappers (ODM) such as Mongoid are automatically instrumented if they use the official Ruby driver. To activate the integration, simply:
Expand Down
1 change: 1 addition & 0 deletions lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Datadog
require 'ddtrace/contrib/http/integration'
require 'ddtrace/contrib/httprb/integration'
require 'ddtrace/contrib/integration'
require 'ddtrace/contrib/kafka/integration'
require 'ddtrace/contrib/presto/integration'
require 'ddtrace/contrib/mysql2/integration'
require 'ddtrace/contrib/mongodb/integration'
Expand Down
25 changes: 25 additions & 0 deletions lib/ddtrace/contrib/kafka/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'ddtrace/contrib/configuration/settings'
require 'ddtrace/contrib/kafka/ext'

module Datadog
module Contrib
module Kafka
module Configuration
# Custom settings for the Kafka integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled do |o|
o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
o.lazy
end

option :analytics_sample_rate do |o|
o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
o.lazy
end

option :service_name, default: Ext::SERVICE_NAME
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/ddtrace/contrib/kafka/consumer_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Datadog
module Contrib
module Kafka
# Defines basic behaviors for an event for a consumer.
module ConsumerEvent
def process(span, _event, _id, payload)
super

span.set_tag(Ext::TAG_GROUP, payload[:group_id])
end
end
end
end
end
14 changes: 14 additions & 0 deletions lib/ddtrace/contrib/kafka/consumer_group_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Datadog
module Contrib
module Kafka
# Defines basic behaviors for an event for a consumer group.
module ConsumerGroupEvent
def process(span, _event, _id, payload)
super

span.resource = payload[:group_id]
end
end
end
end
end
51 changes: 51 additions & 0 deletions lib/ddtrace/contrib/kafka/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_support/notifications/event'
require 'ddtrace/contrib/kafka/ext'

module Datadog
module Contrib
module Kafka
# Defines basic behaviors for an ActiveSupport event.
module Event
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
end

# Class methods for Kafka events.
module ClassMethods
def event_name
self::EVENT_NAME
end

def span_options
{ service: configuration[:service_name] }
end

def tracer
-> { configuration[:tracer] }
end

def configuration
Datadog.configuration[:kafka]
end

def process(span, _event, _id, payload)
span.service = configuration[:service_name]
span.set_tag(Ext::TAG_CLIENT, payload[:client_id])

# Set analytics sample rate
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
end

# Measure service stats
Contrib::Analytics.set_measured(span)

span.set_error(payload[:exception_object]) if payload[:exception_object]
end
end
end
end
end
end
44 changes: 44 additions & 0 deletions lib/ddtrace/contrib/kafka/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'ddtrace/contrib/kafka/events/connection/request'
require 'ddtrace/contrib/kafka/events/consumer/process_batch'
require 'ddtrace/contrib/kafka/events/consumer/process_message'
require 'ddtrace/contrib/kafka/events/consumer_group/heartbeat'
require 'ddtrace/contrib/kafka/events/consumer_group/join_group'
require 'ddtrace/contrib/kafka/events/consumer_group/leave_group'
require 'ddtrace/contrib/kafka/events/consumer_group/sync_group'
require 'ddtrace/contrib/kafka/events/produce_operation/send_messages'
require 'ddtrace/contrib/kafka/events/producer/deliver_messages'

module Datadog
module Contrib
module Kafka
# Defines collection of instrumented Kafka events
module Events
ALL = [
Events::Connection::Request,
Events::Consumer::ProcessBatch,
Events::Consumer::ProcessMessage,
Events::ConsumerGroup::Heartbeat,
Events::ConsumerGroup::JoinGroup,
Events::ConsumerGroup::LeaveGroup,
Events::ConsumerGroup::SyncGroup,
Events::ProduceOperation::SendMessages,
Events::Producer::DeliverMessages
].freeze

module_function

def all
self::ALL
end

def subscriptions
all.collect(&:subscriptions).collect(&:to_a).flatten
end

def subscribe!
all.each(&:subscribe!)
end
end
end
end
end
34 changes: 34 additions & 0 deletions lib/ddtrace/contrib/kafka/events/connection/request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'ddtrace/contrib/kafka/ext'
require 'ddtrace/contrib/kafka/event'

module Datadog
module Contrib
module Kafka
module Events
module Connection
# Defines instrumentation for request.connection.kafka event
module Request
include Kafka::Event

EVENT_NAME = 'request.connection.kafka'.freeze

def self.process(span, _event, _id, payload)
super

span.resource = payload[:api]

span.set_tag(Ext::TAG_REQUEST_SIZE, payload[:request_size]) if payload.key?(:request_size)
span.set_tag(Ext::TAG_RESPONSE_SIZE, payload[:response_size]) if payload.key?(:response_size)
end

module_function

def span_name
Ext::SPAN_CONNECTION_REQUEST
end
end
end
end
end
end
end
Loading

0 comments on commit 24d2036

Please sign in to comment.