Class: Datadog::Tracing::TraceSegment

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/trace_segment.rb

Overview

Serializable construct representing a trace

Constant Summary collapse

TAG_NAME =
'name'.freeze
TAG_RESOURCE =
'resource'.freeze
TAG_SERVICE =
'service'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spans, agent_sample_rate: nil, hostname: nil, id: nil, lang: nil, name: nil, origin: nil, process_id: nil, rate_limiter_rate: nil, resource: nil, root_span_id: nil, rule_sample_rate: nil, runtime_id: nil, sample_rate: nil, sampling_priority: nil, service: nil, tags: nil, metrics: nil) ⇒ Object

Parameters:

  • spans (Array<Datadog::Span>)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/datadog/tracing/trace_segment.rb', line 40

def initialize(
  spans,
  agent_sample_rate: nil,
  hostname: nil,
  id: nil,
  lang: nil,
  name: nil,
  origin: nil,
  process_id: nil,
  rate_limiter_rate: nil,
  resource: nil,
  root_span_id: nil,
  rule_sample_rate: nil,
  runtime_id: nil,
  sample_rate: nil,
  sampling_priority: nil,
  service: nil,
  tags: nil,
  metrics: nil
)
  @id = id
  @root_span_id = root_span_id
  @spans = spans || []

  # Does not make an effort to move metrics out of tags
  # The caller is expected to have done that
  @meta = (tags && tags.dup) || {}
  @metrics = (metrics && metrics.dup) || {}

  # Set well-known tags, defaulting to getting the values from tags
  @agent_sample_rate = agent_sample_rate || agent_sample_rate_tag
  @hostname = hostname || hostname_tag
  @lang = lang || lang_tag
  @name = Core::Utils::SafeDup.frozen_or_dup(name || name_tag)
  @origin = Core::Utils::SafeDup.frozen_or_dup(origin || origin_tag)
  @process_id = process_id || process_id_tag
  @rate_limiter_rate = rate_limiter_rate || rate_limiter_rate_tag
  @resource = Core::Utils::SafeDup.frozen_or_dup(resource || resource_tag)
  @rule_sample_rate = rule_sample_rate_tag || rule_sample_rate
  @runtime_id = runtime_id || runtime_id_tag
  @sample_rate = sample_rate || sample_rate_tag
  @sampling_decision_maker = sampling_decision_maker_tag
  @sampling_priority = sampling_priority || sampling_priority_tag
  @service = Core::Utils::SafeDup.frozen_or_dup(service || service_tag)
end

Instance Attribute Details

#agent_sample_rateObject

Returns the value of attribute agent_sample_rate.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def agent_sample_rate
  @agent_sample_rate
end

#hostnameObject

Returns the value of attribute hostname.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def hostname
  @hostname
end

#idObject (readonly)

Returns the value of attribute id.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def id
  @id
end

#langObject

Returns the value of attribute lang.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def lang
  @lang
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def name
  @name
end

#originObject

Returns the value of attribute origin.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def origin
  @origin
end

#process_idObject

Returns the value of attribute process_id.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def process_id
  @process_id
end

#rate_limiter_rateObject

Returns the value of attribute rate_limiter_rate.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def rate_limiter_rate
  @rate_limiter_rate
end

#resourceObject

Returns the value of attribute resource.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def resource
  @resource
end

#rule_sample_rateObject

Returns the value of attribute rule_sample_rate.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def rule_sample_rate
  @rule_sample_rate
end

#runtime_idObject

Returns the value of attribute runtime_id.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def runtime_id
  @runtime_id
end

#sample_rateObject

Returns the value of attribute sample_rate.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def sample_rate
  @sample_rate
end

#sampling_decision_makerObject (readonly)

Returns the value of attribute sampling_decision_maker.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def sampling_decision_maker
  @sampling_decision_maker
end

#sampling_priorityObject

Returns the value of attribute sampling_priority.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def sampling_priority
  @sampling_priority
end

#serviceObject

Returns the value of attribute service.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def service
  @service
end

#spansObject (readonly)

Returns the value of attribute spans.



19
20
21
# File 'lib/datadog/tracing/trace_segment.rb', line 19

def spans
  @spans
end

Instance Method Details

#any?Object



88
89
90
# File 'lib/datadog/tracing/trace_segment.rb', line 88

def any?
  @spans.any?
end

#countObject



92
93
94
# File 'lib/datadog/tracing/trace_segment.rb', line 92

def count
  @spans.count
end

#empty?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/datadog/tracing/trace_segment.rb', line 96

def empty?
  @spans.empty?
end

#keep!void

This method returns an undefined value.

If an active trace is present, forces it to be retained by the Datadog backend.

Any sampling logic will not be able to change this decision.



113
114
115
# File 'lib/datadog/tracing/trace_segment.rb', line 113

def keep!
  self.sampling_priority = Sampling::Ext::Priority::USER_KEEP
end

#lengthObject



100
101
102
# File 'lib/datadog/tracing/trace_segment.rb', line 100

def length
  @spans.length
end

#reject!void

This method returns an undefined value.

If an active trace is present, forces it to be dropped and not stored by the Datadog backend.

Any sampling logic will not be able to change this decision.



122
123
124
# File 'lib/datadog/tracing/trace_segment.rb', line 122

def reject!
  self.sampling_priority = Sampling::Ext::Priority::USER_REJECT
end

#sampled?Boolean

Returns:

  • (Boolean)


126
127
128
129
# File 'lib/datadog/tracing/trace_segment.rb', line 126

def sampled?
  sampling_priority == Sampling::Ext::Priority::AUTO_KEEP \
    || sampling_priority == Sampling::Ext::Priority::USER_KEEP
end

#sizeObject



104
105
106
# File 'lib/datadog/tracing/trace_segment.rb', line 104

def size
  @spans.size
end