[deploy] Honeycomb instrumentation: distinguish between literal vs prefix matching for sampling (#7936)

This commit is contained in:
Liz Fong-Jones 2020-05-19 10:49:41 -04:00 committed by GitHub
parent 6a4a99f162
commit a6305fd0a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -7,19 +7,24 @@ module Honeycomb
"TIME",
"BEGIN",
"COMMIT",
].freeze
NOISY_PREFIXES = [
"INCRBY",
"TTL",
"GET rack:",
"SET rack:",
"GET views/shell",
].freeze
def self.sample(fields)
if NOISY_COMMANDS.include?(fields["redis.command"]) || NOISY_COMMANDS.include?(fields["sql.active_record.sql"])
if (NOISY_COMMANDS & [fields["redis.command"], fields["sql.active_record.sql"]]).any?
rate = 100
[should_sample(rate, fields["trace.trace_id"]), rate]
elsif fields["redis.command"]&.start_with?("BRPOP")
rate = 1000
[should_sample(rate, fields["trace.trace_id"]), rate]
elsif fields["redis.command"]&.start_with?("INCRBY") || fields["redis.command"]&.start_with?("TTL")
elsif fields["redis.command"]&.start_with?(*NOISY_PREFIXES)
rate = 100
[should_sample(rate, fields["trace.trace_id"]), rate]
else

View file

@ -28,6 +28,16 @@ RSpec.describe Honeycomb::NoiseCancellingSampler do
described_class.sample({ "redis.command" => "TTL this and that", "trace.trace_id" => trace_id })
expect(described_class).to have_received(:should_sample).with(100, trace_id)
end
it "samples if the command starts with GET rack:" do
described_class.sample({ "redis.command" => "GET rack::something", "trace.trace_id" => trace_id })
expect(described_class).to have_received(:should_sample).with(100, trace_id)
end
it "samples if the command starts with SET rack:" do
described_class.sample({ "redis.command" => "SET rack::something", "trace.trace_id" => trace_id })
expect(described_class).to have_received(:should_sample).with(100, trace_id)
end
end
context "with a active_record SQL command" do