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

Enable priority sampling by default #654

Merged
merged 3 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 1 addition & 9 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,15 +1356,7 @@ The sampler can set the priority to the following values:
- `Datadog::Ext::Priority::AUTO_REJECT`: the sampler automatically decided to reject the trace.
- `Datadog::Ext::Priority::AUTO_KEEP`: the sampler automatically decided to keep the trace.

For now, priority sampling is disabled by default. Enabling it ensures that your sampled distributed traces will be complete. To enable the priority sampling:

```ruby
Datadog.configure do |c|
c.tracer priority_sampling: true
end
```

Once enabled, the sampler will automatically assign a priority of 0 or 1 to traces, depending on their service and volume.
Priority sampling is enabled by default. Enabling it ensures that your sampled distributed traces will be complete. Once enabled, the sampler will automatically assign a priority of 0 or 1 to traces, depending on their service and volume.

You can also set this priority manually to either drop a non-interesting trace or to keep an important one. For that, set the `context#sampling_priority` to:

Expand Down
10 changes: 8 additions & 2 deletions lib/ddtrace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,23 @@ def configure(options = {})

# Those are rare "power-user" options.
sampler = options.fetch(:sampler, nil)
priority_sampling = options[:priority_sampling]
priority_sampling = options.fetch(:priority_sampling, nil)
max_spans_before_partial_flush = options.fetch(:max_spans_before_partial_flush, nil)
min_spans_before_partial_flush = options.fetch(:min_spans_before_partial_flush, nil)
partial_flush_timeout = options.fetch(:partial_flush_timeout, nil)

@enabled = enabled unless enabled.nil?
@sampler = sampler unless sampler.nil?

if priority_sampling
# Re-build the sampler and writer if priority sampling is enabled,
# but neither are configured. Verify the sampler isn't already a
# priority sampler too, so we don't wrap one with another.
if priority_sampling != false && [email protected]_a?(PrioritySampler)
@sampler = PrioritySampler.new(base_sampler: @sampler)
@writer = Writer.new(priority_sampler: @sampler)
elsif priority_sampling == false
@sampler = sampler || Datadog::AllSampler.new if @sampler.is_a?(PrioritySampler)
@writer = Writer.new
end

@writer.transport.hostname = hostname unless hostname.nil?
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/configuration/pin_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
end

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

it do
expect(target.datadog_pin.service).to eq('my-service')
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Datadog::Context do
subject(:context) { described_class.new(options) }
let(:options) { {} }
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

describe '#current_root_span' do
subject(:current_root_span) { context.current_root_span }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RSpec.describe 'ActiveModelSerializers patcher' do
include_context 'AMS serializer'

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def all_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/active_record/multi_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'sqlite3'

RSpec.describe 'ActiveRecord multi-database implementation' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer, service_name: default_db_service_name } }
let(:default_db_service_name) { 'default-db' }

Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/active_record/performance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'sqlite3'

RSpec.describe 'ActiveRecord tracing performance' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:options) { { tracer: tracer } }
let(:spans) { tracer.writer.spans }

Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/active_record/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require_relative 'app'

RSpec.describe 'ActiveRecord instrumentation' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer } }

before(:each) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
RSpec.describe Datadog::Contrib::ActiveSupport::Notifications::Subscription do
describe 'instance' do
subject(:subscription) { described_class.new(tracer, span_name, options, &block) }
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, 👍 for encapsulating this somewhere.

let(:span_name) { double('span_name') }
let(:options) { {} }
let(:payload) { {} }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/aws/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'ddtrace/ext/http'

RSpec.describe 'AWS instrumentation' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:client) { ::Aws::S3::Client.new(stub_responses: responses) }
let(:responses) { true }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/concurrent_ruby/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
remove_patch!(:concurrent_ruby)
end

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer } }

subject(:deferred_execution) do
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/dalli/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:test_port) { ENV.fetch('TEST_MEMCACHED_PORT', '11211') }

let(:client) { ::Dalli::Client.new("#{test_host}:#{test_port}") }
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:pin) { ::Dalli.datadog_pin }

def all_spans
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/delayed_job/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def job_data
end)
end

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

before do
Datadog.configure { |c| c.use :delayed_job, tracer: tracer }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/elasticsearch/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

let(:client) { Elasticsearch::Client.new(url: server) }
let(:pin) { Datadog::Pin.get_from(client) }
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

before do
Datadog.configure do |c|
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/elasticsearch/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
let(:server) { "http://#{host}:#{port}" }

let(:client) { Elasticsearch::Client.new(url: server) }
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:spans) { tracer.writer.spans }
let(:span) { spans.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/excon/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'ddtrace/contrib/excon/middleware'

RSpec.describe Datadog::Contrib::Excon::Middleware do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:connection_options) { { mock: true } }
let(:middleware_options) { {} }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/faraday/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'ddtrace/ext/distributed'

RSpec.describe 'Faraday middleware' do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:client) do
::Faraday.new('http://example.com') do |builder|
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/graphql/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end
end

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def pop_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/http/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'net/http'

RSpec.describe 'net/http patcher' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:host) { 'example.com' }

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/mongodb/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'mongo'

RSpec.describe 'Mongo::Client instrumentation' do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:client) { Mongo::Client.new(*client_options) }
let(:client_options) { [["#{host}:#{port}"], { database: database }] }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/mysql2/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'mysql2'

RSpec.describe 'Mysql2::Client patcher' do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:client) do
Mysql2::Client.new(
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/racecar/patcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'active_support'
require 'ddtrace'
RSpec.describe 'Racecar patcher' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def all_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rack/distributed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RSpec.describe 'Rack integration distributed tracing' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rack_options) { { tracer: tracer } }

let(:spans) { tracer.writer.spans }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rack/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RSpec.describe 'Rack integration tests' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rack_options) { { tracer: tracer } }

let(:spans) { tracer.writer.spans }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rack/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
subject(:middleware) { described_class.new(app) }
let(:app) { instance_double(Rack::Builder) }

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer } }

before(:each) do
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rack/request_queuing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RSpec.describe 'Rack integration request queuing' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rack_options) { { tracer: tracer } }

let(:spans) { tracer.writer.spans }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rack/resource_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RSpec.describe 'Rack integration with other middleware' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rack_options) do
{
application: app,
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rails/action_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'ddtrace/contrib/rails/rails_helper'

RSpec.describe 'ActionController tracing' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rails_options) { { tracer: tracer } }

before(:each) do
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rails/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def index
end)
end

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def all_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before(:each) { skip 'Test not compatible with Rails < 4.0' if Rails.version < '4.0' }
include_context 'Rails test application'

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

let(:routes) { { '/' => 'test#index' } }
let(:controllers) { [controller] }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rake/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'ddtrace/contrib/rake/patcher'

RSpec.describe Datadog::Contrib::Rake::Instrumentation do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer, enabled: true } }
let(:spans) { tracer.writer.spans }
let(:span) { spans.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/redis/miniapp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'ddtrace'

RSpec.describe 'Redis mini app test' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def all_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/redis/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'ddtrace'

RSpec.describe 'Redis test' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }

def all_spans
tracer.writer.spans(:keep)
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/resque/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
RSpec.describe 'Resque instrumentation' do
include_context 'Resque job'

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:pin) { ::Resque.datadog_pin }
let(:spans) { tracer.writer.spans }
let(:span) { spans.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/rest_client/request_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'restclient/request'

RSpec.describe Datadog::Contrib::RestClient::RequestPatch do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rest_client_options) { {} }

before do
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/sequel/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'ddtrace/contrib/sequel/patcher'

RSpec.describe 'Sequel configuration' do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:spans) { tracer.writer.spans }
let(:span) { spans.first }

Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/sequel/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'ddtrace/contrib/sequel/integration'

RSpec.describe 'Sequel instrumentation' do
let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:configuration_options) { { tracer: tracer } }
let(:sequel) do
Sequel.sqlite(':memory:').tap do |s|
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/shoryuken/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'shoryuken'

RSpec.describe Datadog::Contrib::Shoryuken::Tracer do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:options) { { tracer: tracer } }
let(:spans) { tracer.writer.spans }
let(:span) { spans.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/sinatra/activerecord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RSpec.describe 'Sinatra instrumentation with ActiveRecord' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:options) { { tracer: tracer } }

let(:span) { spans.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/ddtrace/contrib/sinatra/multi_app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RSpec.describe 'Sinatra instrumentation for multi-apps' do
include Rack::Test::Methods

let(:tracer) { Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:options) { { tracer: tracer } }

let(:span) { spans.first }
Expand Down
Loading