Skip to content

Commit

Permalink
[core] Add Span.set_tag('force.keep') support
Browse files Browse the repository at this point in the history
  • Loading branch information
brettlangdon committed Mar 16, 2019
1 parent b70c87b commit 69ea4ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/ddtrace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require 'ddtrace/utils'
require 'ddtrace/ext/errors'
require 'ddtrace/ext/priority'

module Datadog
# Represents a logical unit of work in the system. Each trace consists of one or more spans.
Expand Down Expand Up @@ -68,7 +69,15 @@ def initialize(tracer, name, options = {})
# must be strings. A valid example is:
#
# span.set_tag('http.method', request.method)
def set_tag(key, value)
def set_tag(key, value = nil)
# 'force.keep' is an alias for setting the sampling priority to USER_KEEP
if key == 'force.keep'
return if @context.nil?

@context.sampling_priority = Datadog::Ext::Priority::USER_KEEP
return
end

@meta[key] = value.to_s
rescue StandardError => e
Datadog::Tracer.log.debug("Unable to set the tag #{key}, ignoring it. Caused by: #{e}")
Expand Down
19 changes: 19 additions & 0 deletions spec/ddtrace/span_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'

require 'ddtrace'

RSpec.describe Datadog::Span do
subject(:span) { described_class.new(tracer, 'test.span', options) }
let(:options) { { context: context } }
let(:tracer) { get_test_tracer }
let(:context) { Datadog::Context.new }

describe '#set_tag' do
context 'with \'force.keep\' key' do
before(:each) { span.set_tag('force.keep') }

it { expect(span.get_tag('force.keep')).to be_nil }
it { expect(context.sampling_priority).to eq(2) }
end
end
end

0 comments on commit 69ea4ff

Please sign in to comment.