Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add analytics_sample_rate to all integrations #697

Merged
merged 27 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1eff662
Changed: Don't set sample rate if span is nil.
delner Mar 8, 2019
b1c46d6
Added: analytics_sample_rate tag to ActiveModelSerializers integration.
delner Feb 11, 2019
2a24284
Added: analytics_sample_rate tag to ActiveRecord integration.
delner Feb 14, 2019
181dde1
Added: analytics_sample_rate tag to AWS integration.
delner Feb 14, 2019
f21b7a6
Added: analytics_sample_rate tag to Dalli integration.
delner Feb 14, 2019
3dc56ef
Added: analytics_sample_rate tag to Elasticsearch integration.
delner Feb 20, 2019
7379f07
Added: analytics_sample_rate tag to Excon integration.
delner Feb 20, 2019
2ed7f2e
Added: analytics_sample_rate tag to Faraday integration.
delner Feb 22, 2019
61a67a9
Added: analytics_sample_rate tag to Grape integration.
delner Feb 26, 2019
ba89cd6
Added: analytics_sample_rate tag to GraphQL integration.
delner Feb 26, 2019
349954b
Added: analytics_sample_rate tag to GRPC integration.
delner Feb 27, 2019
179297b
Added: analytics_sample_rate tag to HTTP integration.
delner Feb 27, 2019
87fc380
Added: analytics_sample_rate tag to MongoDB integration.
delner Feb 27, 2019
16855df
Added: analytics_sample_rate tag to mysql2 integration.
delner Feb 28, 2019
f6d161f
Added: analytics_sample_rate tag to Rails integration.
delner Mar 8, 2019
3fc85ab
Added: analytics_sample_rate tag to Redis integration.
delner Mar 8, 2019
175fcc0
Added: analytics_sample_rate tag to RestClient integration.
delner Mar 8, 2019
9ede108
Added: analytics_sample_rate tag to Sequel integration.
delner Mar 8, 2019
6dcb205
Added: analytics_sample_rate tag to Sinatra integration.
delner Mar 8, 2019
fa10272
Changed: DelayedJob analytics to off by default.
delner Mar 11, 2019
f63b2b8
Changed: Racecar analytics to off by default.
delner Mar 11, 2019
8da76e2
Fixed: Rack analytics flag name.
delner Mar 11, 2019
12a8b94
Changed: Rake analytics to off by default.
delner Mar 11, 2019
3cc73ed
Changed: Resque analytics to off by default.
delner Mar 11, 2019
c8f5f1a
Changed: Shoryuken analytics to off by default.
delner Mar 11, 2019
9b3b4b9
Changed: Sidekiq analytics to off by default.
delner Mar 11, 2019
b7660eb
Changed: SuckerPunch analytics to off by default.
delner Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions docs/GettingStarted.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ module ActiveModelSerializers
module Configuration
# Custom settings for the ActiveModelSerializers integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :service_name, default: Ext::SERVICE_NAME
option :tracer, default: Datadog.tracer do |value|
(value || Datadog.tracer).tap do |v|
Expand Down
6 changes: 6 additions & 0 deletions lib/ddtrace/contrib/active_model_serializers/event.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ddtrace/ext/http'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_support/notifications/event'
require 'ddtrace/contrib/active_model_serializers/ext'

Expand Down Expand Up @@ -30,6 +31,11 @@ def configuration
def process(span, event, _id, payload)
span.service = configuration[:service_name]

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

# Set the resource name and serializer name
res = resource(payload[:serializer])
span.resource = res
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/active_model_serializers/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ module ActiveModelSerializers
# ActiveModelSerializers integration constants
module Ext
APP = 'active_model_serializers'.freeze
ENV_ANALYTICS_ENABLED = 'DD_ACTIVE_MODEL_SERIALIZERS_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTIVE_MODEL_SERIALIZERS_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'active_model_serializers'.freeze

SPAN_RENDER = 'active_model_serializers.render'.freeze
SPAN_SERIALIZE = 'active_model_serializers.serialize'.freeze

TAG_ADAPTER = 'active_model_serializers.adapter'.freeze
TAG_SERIALIZER = 'active_model_serializers.serializer'.freeze
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/active_record/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ module ActiveRecord
module Configuration
# Custom settings for the ActiveRecord integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :orm_service_name
option :service_name, depends_on: [:tracer] do |value|
(value || Utils.adapter_name).tap do |service_name|
Expand Down
7 changes: 7 additions & 0 deletions lib/ddtrace/contrib/active_record/events/instantiation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_record/ext'
require 'ddtrace/contrib/active_record/event'

Expand Down Expand Up @@ -38,6 +39,12 @@ def process(span, event, _id, payload)

span.resource = payload.fetch(:class_name)
span.span_type = Ext::SPAN_TYPE_INSTANTIATION

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

span.set_tag(Ext::TAG_INSTANTIATION_CLASS_NAME, payload.fetch(:class_name))
span.set_tag(Ext::TAG_INSTANTIATION_RECORD_COUNT, payload.fetch(:record_count))
rescue StandardError => e
Expand Down
6 changes: 6 additions & 0 deletions lib/ddtrace/contrib/active_record/events/sql.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ddtrace/ext/net'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/active_record/ext'
require 'ddtrace/contrib/active_record/event'

Expand Down Expand Up @@ -38,6 +39,11 @@ def process(span, event, _id, payload)
span.resource = payload.fetch(:sql)
span.span_type = Datadog::Ext::SQL::TYPE

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

# Find out if the SQL query has been cached in this request. This meta is really
# helpful to users because some spans may have 0ns of duration because the query
# is simply cached from memory, so the notification is fired with start == finish.
Expand Down
5 changes: 2 additions & 3 deletions lib/ddtrace/contrib/active_record/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ module ActiveRecord
# ActiveRecord integration constants
module Ext
APP = 'active_record'.freeze
ENV_ANALYTICS_ENABLED = 'DD_ACTIVE_RECORD_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ACTIVE_RECORD_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'active_record'.freeze

SPAN_INSTANTIATION = 'active_record.instantiation'.freeze
SPAN_SQL = 'active_record.sql'.freeze

SPAN_TYPE_INSTANTIATION = 'custom'.freeze

TAG_DB_CACHED = 'active_record.db.cached'.freeze
TAG_DB_NAME = 'active_record.db.name'.freeze
TAG_DB_VENDOR = 'active_record.db.vendor'.freeze
Expand Down
3 changes: 2 additions & 1 deletion lib/ddtrace/contrib/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def enabled?(flag = nil)
end

def set_sample_rate(span, sample_rate)
span.set_metric(Datadog::Ext::Analytics::TAG_SAMPLE_RATE, sample_rate) unless sample_rate.nil?
return if span.nil? || sample_rate.nil?
span.set_metric(Datadog::Ext::Analytics::TAG_SAMPLE_RATE, sample_rate)
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/aws/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ module Aws
module Configuration
# Custom settings for the AWS integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :service_name, default: Ext::SERVICE_NAME
end
end
Expand Down
11 changes: 5 additions & 6 deletions lib/ddtrace/contrib/aws/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ module Aws
# AWS integration constants
module Ext
APP = 'aws'.freeze
ENV_ANALYTICS_ENABLED = 'DD_AWS_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_AWS_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'aws'.freeze

SPAN_COMMAND = 'aws.command'.freeze

TAG_AGENT = 'aws.agent'.freeze
TAG_DEFAULT_AGENT = 'aws-sdk-ruby'.freeze
TAG_HOST = 'host'.freeze
TAG_OPERATION = 'aws.operation'.freeze
TAG_REGION = 'aws.region'.freeze
TAG_PATH = 'path'.freeze
TAG_HOST = 'host'.freeze

TAG_DEFAULT_AGENT = 'aws-sdk-ruby'.freeze
TAG_REGION = 'aws.region'.freeze
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/ddtrace/contrib/aws/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/aws/ext'

module Datadog
Expand Down Expand Up @@ -27,6 +28,12 @@ def annotate!(span, context)
span.span_type = Datadog::Ext::AppTypes::WEB
span.name = Ext::SPAN_COMMAND
span.resource = context.safely(:resource)

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

span.set_tag(Ext::TAG_AGENT, Ext::TAG_DEFAULT_AGENT)
span.set_tag(Ext::TAG_OPERATION, context.safely(:operation))
span.set_tag(Ext::TAG_REGION, context.safely(:region))
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/dalli/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ module Dalli
module Configuration
# Custom settings for the Dalli integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :service_name, default: Ext::SERVICE_NAME
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/ddtrace/contrib/dalli/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module Dalli
# Dalli integration constants
module Ext
APP = 'dalli'.freeze
SERVICE_NAME = 'memcached'.freeze

ENV_ANALYTICS_ENABLED = 'DD_DALLI_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_DALLI_ANALYTICS_SAMPLE_RATE'.freeze
QUANTIZE_MAX_CMD_LENGTH = 100
SERVICE_NAME = 'memcached'.freeze
SPAN_COMMAND = 'memcached.command'.freeze
TAG_COMMAND = 'memcached.command'.freeze
end
Expand Down
7 changes: 7 additions & 0 deletions lib/ddtrace/contrib/dalli/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'ddtrace/ext/app_types'
require 'ddtrace/ext/net'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/dalli/quantize'

module Datadog
Expand Down Expand Up @@ -35,6 +36,12 @@ def request(op, *args)
span.resource = op.to_s.upcase
span.service = datadog_configuration[:service_name]
span.span_type = Datadog::Ext::AppTypes::CACHE

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

span.set_tag(Datadog::Ext::NET::TARGET_HOST, hostname)
span.set_tag(Datadog::Ext::NET::TARGET_PORT, port)
cmd = Datadog::Contrib::Dalli::Quantize.format_command(op, args)
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/delayed_job/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Configuration
# Custom settings for the DelayedJob integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENALBED, nil) },
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/delayed_job/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module DelayedJob
# DelayedJob integration constants
module Ext
APP = 'delayed_job'.freeze
ENV_ANALYTICS_ENALBED = 'DD_DELAYED_JOB_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_ENABLED = 'DD_DELAYED_JOB_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_DELAYED_JOB_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'delayed_job'.freeze
SPAN_JOB = 'delayed_job'.freeze
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/elasticsearch/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ module Elasticsearch
module Configuration
# Custom settings for the Elasticsearch integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :quantize, default: {}
option :service_name, default: Ext::SERVICE_NAME
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/elasticsearch/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Elasticsearch
# Elasticsearch integration constants
module Ext
APP = 'elasticsearch'.freeze
ENV_ANALYTICS_ENABLED = 'DD_ELASTICSEARCH_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_ELASTICSEARCH_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'elasticsearch'.freeze

SPAN_QUERY = 'elasticsearch.query'.freeze

TAG_BODY = 'elasticsearch.body'.freeze
TAG_METHOD = 'elasticsearch.method'.freeze
TAG_PARAMS = 'elasticsearch.params'.freeze
Expand Down
12 changes: 11 additions & 1 deletion lib/ddtrace/contrib/elasticsearch/patcher.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'ddtrace/contrib/patcher'
require 'ddtrace/ext/app_types'
require 'ddtrace/ext/net'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/elasticsearch/ext'

module Datadog
Expand Down Expand Up @@ -83,11 +84,16 @@ def perform_request(*args)
params = JSON.generate(params) if params && !params.is_a?(String)
body = JSON.generate(body) if body && !body.is_a?(String)

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

span.set_tag(Datadog::Contrib::Elasticsearch::Ext::TAG_METHOD, method)
span.set_tag(Datadog::Contrib::Elasticsearch::Ext::TAG_URL, url)
span.set_tag(Datadog::Contrib::Elasticsearch::Ext::TAG_PARAMS, params) if params
if body
quantize_options = Datadog.configuration[:elasticsearch][:quantize]
quantize_options = datadog_configuration[:quantize]
quantized_body = Datadog::Contrib::Elasticsearch::Quantize.format_body(body, quantize_options)
span.set_tag(Datadog::Contrib::Elasticsearch::Ext::TAG_BODY, quantized_body)
end
Expand All @@ -106,6 +112,10 @@ def perform_request(*args)
end
response
end

def datadog_configuration
Datadog.configuration[:elasticsearch]
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/excon/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ module Excon
module Configuration
# Custom settings for the Excon integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :distributed_tracing, default: true
option :error_handler, default: nil
option :service_name, default: Ext::SERVICE_NAME
Expand Down
3 changes: 2 additions & 1 deletion lib/ddtrace/contrib/excon/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Excon
# Excon integration constants
module Ext
APP = 'excon'.freeze
ENV_ANALYTICS_ENABLED = 'DD_EXCON_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_EXCON_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'excon'.freeze

SPAN_REQUEST = 'excon.request'.freeze
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/ddtrace/contrib/excon/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'ddtrace/ext/net'
require 'ddtrace/ext/distributed'
require 'ddtrace/propagation/http_propagator'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/excon/ext'

module Datadog
Expand Down Expand Up @@ -82,6 +83,14 @@ def tracer
@options[:tracer]
end

def analytics_enabled?
Contrib::Analytics.enabled?(@options[:analytics_enabled])
end

def analytics_sample_rate
@options[:analytics_sample_rate]
end

def distributed_tracing?
@options[:distributed_tracing] == true && tracer.enabled
end
Expand All @@ -98,6 +107,12 @@ def annotate!(span, datum)
span.resource = datum[:method].to_s.upcase
span.service = service_name(datum)
span.span_type = Datadog::Ext::HTTP::TYPE

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

span.set_tag(Datadog::Ext::HTTP::URL, datum[:path])
span.set_tag(Datadog::Ext::HTTP::METHOD, datum[:method].to_s.upcase)
span.set_tag(Datadog::Ext::NET::TARGET_HOST, datum[:host])
Expand Down
8 changes: 8 additions & 0 deletions lib/ddtrace/contrib/faraday/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class Settings < Contrib::Configuration::Settings
Datadog::Ext::HTTP::ERROR_RANGE.cover?(env[:status])
end

option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
lazy: true

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true

option :distributed_tracing, default: true
option :error_handler, default: DEFAULT_ERROR_HANDLER
option :service_name, default: Ext::SERVICE_NAME
Expand Down
3 changes: 2 additions & 1 deletion lib/ddtrace/contrib/faraday/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Faraday
# Faraday integration constants
module Ext
APP = 'faraday'.freeze
ENV_ANALYTICS_ENABLED = 'DD_FARADAY_ANALYTICS_ENABLED'.freeze
ENV_ANALYTICS_SAMPLE_RATE = 'DD_FARADAY_ANALYTICS_SAMPLE_RATE'.freeze
SERVICE_NAME = 'faraday'.freeze

SPAN_REQUEST = 'faraday.request'.freeze
end
end
Expand Down
Loading