Method: Datadog::Tracer#start_span
- Defined in:
- lib/ddtrace/tracer.rb
#start_span(name, options = {}) ⇒ Object
Return a span that will trace an operation called name. This method allows parenting passing child_of as an option. If it’s missing, the newly created span is a root span. Available options are:
-
service: the service name for this span -
resource: the resource this span refers, or name if it’s missing -
span_type: the type of the span (such as http, db and so on) -
child_of: a Span or a Context instance representing the parent for this span. -
start_time: when the span actually starts (defaults to now) -
tags: extra tags which should be added to the span.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/ddtrace/tracer.rb', line 195 def start_span(name, = {}) start_time = .fetch(:start_time, Time.now.utc) = .fetch(:tags, {}) opts = .select do |k, _v| # Filter options, we want no side effects with unexpected args. # Plus, this documents the code (Ruby 2 named args would be better but we're Ruby 1.9 compatible) [:service, :resource, :span_type].include?(k) end ctx, parent = guess_context_and_parent() opts[:context] = ctx unless ctx.nil? span = Span.new(self, name, opts) if parent.nil? # root span @sampler.sample(span) span.set_tag('system.pid', Process.pid) else # child span span.parent = parent # sets service, trace_id, parent_id, sampled end .each { |k, v| span.set_tag(k, v) } unless .empty? .each { |k, v| span.set_tag(k, v) } unless .empty? span.start_time = start_time # this could at some point be optional (start_active_span vs start_manual_span) ctx.add_span(span) unless ctx.nil? span end |