Class: Datadog::Tracing::TraceOperation

Inherits:
Object
  • Object
show all
Includes:
Metadata::Tagging
Defined in:
lib/datadog/tracing/trace_operation.rb,
sig/datadog/tracing/trace_operation.rbs

Overview

Represents the act of tracing a series of operations, by generating and collecting span measurements. When completed, it yields a trace.

Supports synchronous code flow only. Usage across multiple threads will result in incorrect relationships. For async support, a TraceOperation should be employed per execution context (e.g. Thread, etc.)

Constant Summary collapse

DEFAULT_MAX_LENGTH =

Returns:

  • (::Integer)
100_000
AUTO_SAMPLING_PRIORITIES =

Returns:

  • (::Array[::Integer])
[Sampling::Ext::Priority::AUTO_KEEP, Sampling::Ext::Priority::AUTO_REJECT].freeze
RECONSIDERABLE_DECISIONS =

Returns:

  • (::Array[::String])
[Sampling::Ext::Decision::DEFAULT, Sampling::Ext::Decision::AGENT_RATE].freeze

Constants included from Metadata::Tagging

Metadata::Tagging::ENSURE_AGENT_TAGS, Metadata::Tagging::NUMERIC_TAG_SIZE_RANGE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Metadata::Tagging

#clear_metric, #clear_tag, #has_tag?, #meta, #metrics, #set_metric, #set_tag, #set_tags

Constructor Details

#initialize(logger: Datadog.logger, agent_sample_rate: nil, events: nil, hostname: nil, id: nil, max_length: DEFAULT_MAX_LENGTH, name: nil, origin: nil, parent_span_id: nil, span_links: nil, rate_limiter_rate: nil, resource: nil, rule_sample_rate: nil, sample_rate: nil, sampled: nil, sampling_priority: nil, service: nil, profiling_enabled: nil, apm_tracing_enabled: nil, tags: nil, metrics: nil, trace_state: nil, remote_parent: false, distributed_sampling_priority: false, tracer: nil, baggage: nil, auto_finish: true) ⇒ Object

Creates a new TraceOperation.

Parameters:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/datadog/tracing/trace_operation.rb', line 66

def initialize(
  logger: Datadog.logger,
  agent_sample_rate: nil,
  events: nil,
  hostname: nil,
  id: nil,
  max_length: DEFAULT_MAX_LENGTH,
  name: nil,
  origin: nil,
  parent_span_id: nil,
  span_links: nil,
  rate_limiter_rate: nil,
  resource: nil,
  rule_sample_rate: nil,
  sample_rate: nil,
  sampled: nil,
  sampling_priority: nil,
  service: nil,
  profiling_enabled: nil,
  apm_tracing_enabled: nil,
  tags: nil,
  metrics: nil,
  trace_state: nil,
  remote_parent: false,
  distributed_sampling_priority: false,
  tracer: nil, # DEV-3.0: deprecated, remove in 3.0
  baggage: nil,
  auto_finish: true
)
  @logger = logger

  # Attributes
  @id = id || Tracing::Utils::TraceId.next_id
  @max_length = max_length || DEFAULT_MAX_LENGTH
  @parent_span_id = parent_span_id
  @sampled = sampled.nil? || sampled
  @remote_parent = remote_parent
  @distributed_sampling_priority = distributed_sampling_priority
  @span_links = span_links
  # Tags
  @agent_sample_rate = agent_sample_rate
  @hostname = hostname
  @name = name
  @origin = origin
  @rate_limiter_rate = rate_limiter_rate
  @resource = resource
  @rule_sample_rate = rule_sample_rate
  @sample_rate = sample_rate
  @sampling_priority = sampling_priority
  @service = service
  @profiling_enabled = profiling_enabled
  @apm_tracing_enabled = apm_tracing_enabled
  @trace_state = trace_state || Distributed::TraceState.new
  @baggage = baggage

  # Generic tags
  set_tags(tags) if tags
  set_tags(metrics) if metrics

  # State
  @root_span = nil
  @active_span = nil
  @active_span_count = 0
  @events = events || Events.new
  @finished = false
  @spans = []
  @auto_finish = !!auto_finish
  @flushed = false
  @propagated = false
end

Instance Attribute Details

#active_span ⇒ Object (readonly)

Returns the value of attribute active_span.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def active_span
  @active_span
end

#active_span_count ⇒ Object (readonly)

Returns the value of attribute active_span_count.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def active_span_count
  @active_span_count
end

#agent_sample_rate ⇒ Object

Returns the value of attribute agent_sample_rate.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def agent_sample_rate
  @agent_sample_rate
end

#baggage ⇒ Object

Returns the value of attribute baggage.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def baggage
  @baggage
end

#events ⇒ Object (readonly)

Returns the value of attribute events.



545
546
547
# File 'lib/datadog/tracing/trace_operation.rb', line 545

def events
  @events
end

#hostname ⇒ Object

Returns the value of attribute hostname.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def hostname
  @hostname
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def id
  @id
end

#logger ⇒ Object (readonly)

Returns the value of attribute logger.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def logger
  @logger
end

#max_length ⇒ Object (readonly)

Returns the value of attribute max_length.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def max_length
  @max_length
end

#name ⇒ Object

Returns:

  • (Object)


189
190
191
# File 'lib/datadog/tracing/trace_operation.rb', line 189

def name
  @name || root_span&.name
end

#origin ⇒ Object

Returns the value of attribute origin.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def origin
  @origin
end

#parent_span_id ⇒ Object (readonly)

Returns the value of attribute parent_span_id.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def parent_span_id
  @parent_span_id
end

#rate_limiter_rate ⇒ Object

Returns the value of attribute rate_limiter_rate.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def rate_limiter_rate
  @rate_limiter_rate
end

#remote_parent ⇒ Object

Returns the value of attribute remote_parent.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def remote_parent
  @remote_parent
end

#resource ⇒ Object

Returns:

  • (Object)


193
194
195
# File 'lib/datadog/tracing/trace_operation.rb', line 193

def resource
  @resource || root_span&.resource
end

#root_span ⇒ Object (readonly)

Returns the value of attribute root_span.



545
546
547
# File 'lib/datadog/tracing/trace_operation.rb', line 545

def root_span
  @root_span
end

#rule_sample_rate ⇒ Object

Returns the value of attribute rule_sample_rate.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def rule_sample_rate
  @rule_sample_rate
end

#sample_rate ⇒ Object

Returns the value of attribute sample_rate.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def sample_rate
  @sample_rate
end

#sampled=(value) ⇒ Object (writeonly)

Sets the attribute sampled

Parameters:

  • value —

    the value to set the attribute sampled to.



54
55
56
# File 'lib/datadog/tracing/trace_operation.rb', line 54

def sampled=(value)
  @sampled = value
end

#sampling_priority ⇒ Object

Returns the value of attribute sampling_priority.



34
35
36
# File 'lib/datadog/tracing/trace_operation.rb', line 34

def sampling_priority
  @sampling_priority
end

#service ⇒ Object

Returns:

  • (Object)


233
234
235
# File 'lib/datadog/tracing/trace_operation.rb', line 233

def service
  @service || root_span&.service
end

#trace_state ⇒ Object (readonly)

Returns the value of attribute trace_state.



45
46
47
# File 'lib/datadog/tracing/trace_operation.rb', line 45

def trace_state
  @trace_state
end

Instance Method Details

#activate_span!(span_op) ⇒ Object

Parameters:

  • span_op (Object)

Returns:

  • (Object)


549
550
551
552
553
554
555
556
557
# File 'lib/datadog/tracing/trace_operation.rb', line 549

def activate_span!(span_op)
  parent = @active_span

  span_op.send(:parent=, parent) unless parent.nil?

  @active_span = span_op

  set_local_root_span!(span_op)
end

#before_finish_span(span_op) ⇒ Object

Parameters:

  • span_op (Object)

Returns:

  • (Object)


579
580
581
582
583
584
# File 'lib/datadog/tracing/trace_operation.rb', line 579

def before_finish_span(span_op)
  # Publish :span_before_finish event
  events.span_before_finish.publish(span_op, self)
rescue => e
  logger.debug { "Error in before_finish_span on trace: #{e.class}: #{e.message} Backtrace: #{e.backtrace.first(3)}" }
end

#build_span(op_name, logger: Datadog.logger, events: nil, on_error: nil, resource: nil, service: nil, start_time: nil, tags: nil, type: nil, id: nil) ⇒ Object

Parameters:

  • op_name (Object)
  • events: (Object, nil) (defaults to: nil)
  • on_error: (on_error) (defaults to: nil)
  • resource: (Object, nil) (defaults to: nil)
  • service: (Object, nil) (defaults to: nil)
  • start_time: (Object, nil) (defaults to: nil)
  • tags: (Object, nil) (defaults to: nil)
  • type: (Object, nil) (defaults to: nil)

Returns:

  • (Object)


276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/datadog/tracing/trace_operation.rb', line 276

def build_span(
  op_name,
  logger: Datadog.logger,
  events: nil,
  on_error: nil,
  resource: nil,
  service: nil,
  start_time: nil,
  tags: nil,
  type: nil,
  id: nil
)
  # Resolve span options:
  # Parent, service name, etc.
  # Add default options
  trace_id = @id
  parent = @active_span

  # Use active span's span ID if available. Otherwise, the parent span ID.
  # Necessary when this trace continues from another, e.g. distributed trace.
  parent_id = parent ? parent.id : @parent_span_id || 0

  # Build events
  span_events = events || SpanOperation::Events.new(logger: logger)

  # Before start: activate the span, publish events.
  span_events.before_start.subscribe do |span_op|
    start_span(span_op)
  end

  # Before finish: allow enrichment before the span is finalized, publish events.
  span_events.before_finish.subscribe do |span_op|
    before_finish_span(span_op)
  end

  # After finish: deactivate the span, record, publish events.
  span_events.after_finish.subscribe do |span, span_op|
    finish_span(span, span_op, parent)
  end

  # Build a new span operation
  SpanOperation.new(
    op_name,
    logger: logger,
    events: span_events,
    on_error: on_error,
    parent_id: parent_id,
    links: (@root_span.nil? ? @span_links : nil),
    resource: resource || op_name,
    service: service,
    start_time: start_time,
    tags: tags,
    trace_id: trace_id,
    type: type,
    id: id
  )
rescue => e
  logger.debug { "Failed to build new span: #{e.class}: #{e.message}" }

  # Return dummy span
  SpanOperation.new(op_name, logger: logger)
end

#build_trace(spans, partial = false) ⇒ Object

Parameters:

  • spans (Object)
  • partial (Boolean) (defaults to: false)

Returns:

  • (Object)


622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# File 'lib/datadog/tracing/trace_operation.rb', line 622

def build_trace(spans, partial = false)
  TraceSegment.new(
    spans,
    agent_sample_rate: @agent_sample_rate,
    hostname: @hostname,
    id: @id,
    lang: Core::Environment::Identity.lang,
    origin: @origin,
    process_id: Core::Environment::Identity.pid,
    rate_limiter_rate: @rate_limiter_rate,
    rule_sample_rate: @rule_sample_rate,
    runtime_id: Core::Environment::Identity.id,
    sample_rate: @sample_rate,
    sampling_priority: @sampling_priority,
    name: name,
    resource: resource,
    service: service,
    tags: meta,
    metrics: metrics,
    root_span_id: (!partial) ? root_span&.id : nil,
    profiling_enabled: @profiling_enabled,
    apm_tracing_enabled: @apm_tracing_enabled
  )
end

#deactivate_span!(span_op) ⇒ Object

Parameters:

  • span_op (Object)

Returns:

  • (Object)


559
560
561
562
563
564
565
# File 'lib/datadog/tracing/trace_operation.rb', line 559

def deactivate_span!(span_op)
  # Set parent to closest unfinished ancestor span.
  # Prevents wrong span from being set as the active span
  # when spans finish out of order.
  span_op = span_op.send(:parent) while !span_op.nil? && span_op.finished?
  @active_span = span_op
end

#distributed_tags ⇒ Hash

Returns tracer tags that will be propagated if this span's context is exported through #to_digest.

Returns:

  • (Hash) —

    key value pairs of distributed tags



650
651
652
# File 'lib/datadog/tracing/trace_operation.rb', line 650

def distributed_tags
  meta.select { |name, _| name.start_with?(Metadata::Ext::Distributed::TAGS_PREFIX) }
end

#finish_span(span, span_op, parent) ⇒ Object

For traces with automatic context management (auto_finish), when the local root span finishes, the trace also finishes. The trace cannot receive new spans after finished.

Without auto_finish, the trace can still receive spans until explicitly finished.



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/datadog/tracing/trace_operation.rb', line 592

def finish_span(span, span_op, parent)
  # Save finished span & root span
  @spans << span unless span.nil?

  # Deactivate the span, re-activate parent.
  deactivate_span!(span_op)

  # Finish if the local root span is finished and automatic
  # context management is enabled.
  @finished = true if span_op == root_span && @auto_finish

  # Update active span count
  @active_span_count -= 1

  # Publish :span_finished event
  events.span_finished.publish(span, self)

  # Publish :trace_finished event
  events.trace_finished.publish(self) if finished?
rescue => e
  logger.debug { "Error finishing span on trace: #{e.class}: #{e.message} Backtrace: #{e.backtrace.first(3)}" }
end

#finished? ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/datadog/tracing/trace_operation.rb', line 145

def finished?
  @finished == true
end

#finished_span_count ⇒ Object

Returns:

  • (Object)


141
142
143
# File 'lib/datadog/tracing/trace_operation.rb', line 141

def finished_span_count
  @spans.length
end

#flush! {|spans| ... } ⇒ TraceSegment

Returns a Datadog::Tracing::TraceSegment with all finished spans that can be flushed at invocation time. All other finished spans are discarded.

Yields:

  • (spans) —

    spans that will be returned as part of the trace segment returned

Returns:



344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/datadog/tracing/trace_operation.rb', line 344

def flush!
  finished = finished?

  # Copy out completed spans
  spans = @spans.dup
  @spans = []
  @flushed = true

  spans = yield(spans) if block_given?

  # Use them to build a trace
  build_trace(spans, !finished)
end

#fork_clone ⇒ Object

Returns a copy of this trace suitable for forks (w/o spans.) Used for continuation of traces across forks.



442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/datadog/tracing/trace_operation.rb', line 442

def fork_clone
  self.class.new(
    agent_sample_rate: @agent_sample_rate,
    events: @events&.dup,
    hostname: @hostname&.dup,
    id: @id,
    max_length: @max_length,
    name: name&.dup,
    origin: @origin&.dup,
    parent_span_id: @active_span&.id || @parent_span_id,
    rate_limiter_rate: @rate_limiter_rate,
    resource: resource&.dup,
    rule_sample_rate: @rule_sample_rate,
    sample_rate: @sample_rate,
    sampled: @sampled,
    sampling_priority: @sampling_priority,
    service: service&.dup,
    trace_state: @trace_state,
    tags: meta.dup,
    metrics: metrics.dup,
    remote_parent: @remote_parent,
    distributed_sampling_priority: @distributed_sampling_priority
  )
end

#full? ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/datadog/tracing/trace_operation.rb', line 137

def full?
  @max_length > 0 && @active_span_count >= @max_length
end

#get_metric(key) ⇒ Object



202
203
204
# File 'lib/datadog/tracing/trace_operation.rb', line 202

def get_metric(key)
  super || root_span&.get_metric(key)
end

#get_tag(key) ⇒ Object

When retrieving tags or metrics we need to include root span tags for sampling purposes



198
199
200
# File 'lib/datadog/tracing/trace_operation.rb', line 198

def get_tag(key)
  super || root_span&.get_tag(key)
end

#keep! ⇒ Object

Returns:

  • (Object)


167
168
169
170
171
# File 'lib/datadog/tracing/trace_operation.rb', line 167

def keep!
  self.sampling_priority = Sampling::Ext::Priority::USER_KEEP
  set_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER, Tracing::Sampling::Ext::Decision::MANUAL)
  self.sampled = true # Just in case the in-app sampler had decided to drop this span, we revert that decision.
end

#measure(op_name, logger: Datadog.logger, events: nil, on_error: nil, resource: nil, service: nil, start_time: nil, tags: nil, type: nil, id: nil) {|arg0, arg1| ... } ⇒ Object

Parameters:

  • op_name (Object)
  • events: (Object, nil) (defaults to: nil)
  • on_error: (on_error) (defaults to: nil)
  • resource: (Object, nil) (defaults to: nil)
  • service: (Object, nil) (defaults to: nil)
  • start_time: (Object, nil) (defaults to: nil)
  • tags: (Object, nil) (defaults to: nil)
  • type: (Object, nil) (defaults to: nil)

Yields:

Yield Parameters:

  • arg0 (Object)
  • arg1 (Object)

Yield Returns:

  • (Object)

Returns:

  • (Object)


237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/datadog/tracing/trace_operation.rb', line 237

def measure(
  op_name,
  logger: Datadog.logger,
  events: nil,
  on_error: nil,
  resource: nil,
  service: nil,
  start_time: nil,
  tags: nil,
  type: nil,
  id: nil,
  &block
)
  # Don't allow more span measurements if the
  # trace is already completed. Prevents multiple
  # root spans with parent_span_id = 0.
  if finished? || full?
    return yield(
      SpanOperation.new(op_name, logger: logger),
      TraceOperation.new(logger: logger))
  end

  # Create new span
  span_op = build_span(
    op_name,
    events: events,
    on_error: on_error,
    resource: resource,
    service: service,
    start_time: start_time,
    tags: tags,
    type: type,
    id: id
  )

  # Start span measurement
  span_op.measure { |s| yield(s, self) }
end

#priority_sampled? ⇒ Boolean

Has the priority sampling chosen to keep this span?

Returns:

  • (Boolean)


163
164
165
# File 'lib/datadog/tracing/trace_operation.rb', line 163

def priority_sampled?
  !@sampling_priority.nil? && @sampling_priority > 0
end

#reconsider_resource_sample? ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
230
231
# File 'lib/datadog/tracing/trace_operation.rb', line 227

def reconsider_resource_sample?
  return false if @resource.nil?

  reconsider_rule_sample?
end

#reject! ⇒ Object

Returns:

  • (Object)


173
174
175
176
# File 'lib/datadog/tracing/trace_operation.rb', line 173

def reject!
  self.sampling_priority = Sampling::Ext::Priority::USER_REJECT
  set_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER, Tracing::Sampling::Ext::Decision::MANUAL)
end

#resource_override? ⇒ Boolean

Returns true if the resource has been explicitly set

Returns:

  • (Boolean)


223
224
225
# File 'lib/datadog/tracing/trace_operation.rb', line 223

def resource_override?
  !@resource.nil?
end

#sampled? ⇒ Boolean

Will this trace be flushed by the tracer transport? This includes cases where the span is kept solely due to priority sampling.

This is not the ultimate Datadog App sampling decision. Downstream systems can decide to reject this trace, especially for cases where priority sampling is set to AUTO_KEEP.

Returns:

  • (Boolean)


157
158
159
# File 'lib/datadog/tracing/trace_operation.rb', line 157

def sampled?
  @sampled == true || priority_sampled?
end

#set_distributed_source(product_bit) ⇒ void

This method returns an undefined value.

Parameters:

  • product_bit (Integer)


206
207
208
209
210
# File 'lib/datadog/tracing/trace_operation.rb', line 206

def set_distributed_source(product_bit)
  source = get_tag(Metadata::Ext::Distributed::TAG_TRACE_SOURCE)&.to_i(16) || 0
  source |= product_bit
  set_tag(Metadata::Ext::Distributed::TAG_TRACE_SOURCE, format("%02X", source))
end

#set_root_span! ⇒ nil, untyped

Parameters:

  • span (Object)

Returns:

  • (nil, untyped)


138
# File 'sig/datadog/tracing/trace_operation.rbs', line 138

def set_root_span!: (untyped span) -> (nil | untyped)

#start_span(span_op) ⇒ Object

Parameters:

  • span_op (Object)

Returns:

  • (Object)


567
568
569
570
571
572
573
574
575
576
577
# File 'lib/datadog/tracing/trace_operation.rb', line 567

def start_span(span_op)
  activate_span!(span_op)

  # Update active span count
  @active_span_count += 1

  # Publish :span_before_start event
  events.span_before_start.publish(span_op, self)
rescue => e
  logger.debug { "Error starting span on trace: #{e.class}: #{e.message} Backtrace: #{e.backtrace.first(3)}" }
end

#tags ⇒ Object



212
213
214
215
216
217
218
# File 'lib/datadog/tracing/trace_operation.rb', line 212

def tags
  all_tags = {}
  all_tags.merge!(root_span&.tags || {}) if root_span
  all_tags.merge!(super)

  all_tags
end

#to_correlation ⇒ Object



429
430
431
432
433
434
435
436
437
438
# File 'lib/datadog/tracing/trace_operation.rb', line 429

def to_correlation
  # Resolve current span ID
  span_id = @active_span&.id
  span_id ||= @parent_span_id unless finished?

  Correlation::Identifier.new(
    trace_id: @id,
    span_id: span_id
  )
end

#to_digest ⇒ Object

Returns a set of trace headers used for continuing traces. Used for propagation across execution contexts. Data should reflect the active state of the trace. DEV-3.0: Sampling is a side effect of generating the digest. We should move the sample call to inject and right before moving to new contexts(threads, forking etc.)



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/datadog/tracing/trace_operation.rb', line 386

def to_digest
  # Resolve current span ID
  span_id = @active_span&.id
  span_id ||= @parent_span_id unless finished?
  # sample the trace_operation with the tracer
  @propagated = true
  events.trace_propagated.publish(self)

  open_telemetry = @trace_state.open_telemetry.outbound(
    trace_id: @id,
    sampling_priority: @sampling_priority,
    decision_maker: get_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER),
    applied_rate: @rule_sample_rate || @agent_sample_rate,
    rate_limiter_rate: @rate_limiter_rate,
    distributed_sampling_priority: @distributed_sampling_priority,
  )

  TraceDigest.new(
    span_id: span_id,
    span_name: @active_span && @active_span.name,
    span_resource: @active_span && @active_span.resource,
    span_service: @active_span && @active_span.service,
    span_type: @active_span && @active_span.type,
    trace_distributed_tags: distributed_tags,
    trace_hostname: @hostname,
    trace_id: @id,
    trace_name: name,
    trace_origin: @origin,
    trace_process_id: Core::Environment::Identity.pid,
    trace_resource: resource,
    trace_runtime_id: Core::Environment::Identity.id,
    trace_sampling_priority: @sampling_priority,
    trace_service: service,
    trace_state: @trace_state.unknown_vendors,
    trace_state_unknown_fields: @trace_state.datadog.unknown_fields,
    trace_otel_random_value: open_telemetry.random_value,
    trace_otel_threshold: open_telemetry.threshold,
    trace_otel_unknown_fields: open_telemetry.unknown_fields,
    span_remote: @remote_parent && @active_span.nil?,
    baggage: (@baggage.nil? || @baggage.empty?) ? nil : @baggage
  ).freeze
end