Class: Datadog::Tracing::TraceSegment
- Inherits:
-
Object
- Object
- Datadog::Tracing::TraceSegment
- Defined in:
- lib/datadog/tracing/trace_segment.rb,
sig/datadog/tracing/trace_segment.rbs
Overview
Serializable construct representing a trace
Constant Summary collapse
- TAG_NAME =
'name'- TAG_RESOURCE =
'resource'- TAG_SERVICE =
'service'
Instance Attribute Summary collapse
-
#agent_sample_rate ⇒ Object
Returns the value of attribute agent_sample_rate.
-
#apm_tracing_enabled ⇒ Object
readonly
Returns the value of attribute apm_tracing_enabled.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
-
#name ⇒ Object
Returns the value of attribute name.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#process_id ⇒ Object
Returns the value of attribute process_id.
-
#profiling_enabled ⇒ Object
readonly
Returns the value of attribute profiling_enabled.
-
#rate_limiter_rate ⇒ Object
Returns the value of attribute rate_limiter_rate.
-
#resource ⇒ Object
Returns the value of attribute resource.
-
#root_span_id ⇒ Object
readonly
Returns the value of attribute root_span_id.
-
#rule_sample_rate ⇒ Object
Returns the value of attribute rule_sample_rate.
-
#runtime_id ⇒ Object
Returns the value of attribute runtime_id.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#sampling_decision_maker ⇒ Object
readonly
Returns the value of attribute sampling_decision_maker.
-
#sampling_priority ⇒ Object
Returns the value of attribute sampling_priority.
-
#service ⇒ Object
Returns the value of attribute service.
-
#spans ⇒ Object
readonly
Returns the value of attribute spans.
Instance Method Summary collapse
- #agent_sample_rate_tag ⇒ Object
- #any? ⇒ Object
- #count ⇒ Object
- #empty? ⇒ Boolean
-
#high_order_tid ⇒ Object
Returns the high order part of the trace id as a hexadecimal string; the most significant 64 bits.
- #hostname_tag ⇒ Object
- #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, profiling_enabled: nil, apm_tracing_enabled: nil) ⇒ Object constructor
-
#keep! ⇒ void
If an active trace is present, forces it to be retained by the Datadog backend.
- #lang_tag ⇒ Object
- #length ⇒ Object
- #name_tag ⇒ Object
- #origin_tag ⇒ Object
- #process_id_tag ⇒ Object
- #rate_limiter_rate_tag ⇒ Object
-
#reject! ⇒ void
If an active trace is present, forces it to be dropped and not stored by the Datadog backend.
- #resource_tag ⇒ Object
- #rule_sample_rate_tag ⇒ Object
- #runtime_id_tag ⇒ Object
- #sample_rate_tag ⇒ Object
- #sampled? ⇒ Boolean
- #sampling_decision_maker_tag ⇒ Object
- #sampling_priority_tag ⇒ Object
- #service_tag ⇒ Object
- #size ⇒ Object
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, profiling_enabled: nil, apm_tracing_enabled: nil) ⇒ Object
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 85 86 87 88 89 90 91 |
# File 'lib/datadog/tracing/trace_segment.rb', line 43 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, profiling_enabled: nil, apm_tracing_enabled: 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 = &.dup || {} @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) @profiling_enabled = profiling_enabled @apm_tracing_enabled = apm_tracing_enabled end |
Instance Attribute Details
#agent_sample_rate ⇒ Object
Returns the value of attribute agent_sample_rate.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def agent_sample_rate @agent_sample_rate end |
#apm_tracing_enabled ⇒ Object (readonly)
Returns the value of attribute apm_tracing_enabled.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def apm_tracing_enabled @apm_tracing_enabled end |
#hostname ⇒ Object
Returns the value of attribute hostname.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def hostname @hostname end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def id @id end |
#lang ⇒ Object
Returns the value of attribute lang.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def lang @lang end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
148 149 150 |
# File 'lib/datadog/tracing/trace_segment.rb', line 148 def @meta end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
148 149 150 |
# File 'lib/datadog/tracing/trace_segment.rb', line 148 def metrics @metrics end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def name @name end |
#origin ⇒ Object
Returns the value of attribute origin.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def origin @origin end |
#process_id ⇒ Object
Returns the value of attribute process_id.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def process_id @process_id end |
#profiling_enabled ⇒ Object (readonly)
Returns the value of attribute profiling_enabled.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def profiling_enabled @profiling_enabled end |
#rate_limiter_rate ⇒ Object
Returns the value of attribute rate_limiter_rate.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def rate_limiter_rate @rate_limiter_rate end |
#resource ⇒ Object
Returns the value of attribute resource.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def resource @resource end |
#root_span_id ⇒ Object (readonly)
Returns the value of attribute root_span_id.
148 149 150 |
# File 'lib/datadog/tracing/trace_segment.rb', line 148 def root_span_id @root_span_id end |
#rule_sample_rate ⇒ Object
Returns the value of attribute rule_sample_rate.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def rule_sample_rate @rule_sample_rate end |
#runtime_id ⇒ Object
Returns the value of attribute runtime_id.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def runtime_id @runtime_id end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def sample_rate @sample_rate end |
#sampling_decision_maker ⇒ Object (readonly)
Returns the value of attribute sampling_decision_maker.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def sampling_decision_maker @sampling_decision_maker end |
#sampling_priority ⇒ Object
Returns the value of attribute sampling_priority.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def sampling_priority @sampling_priority end |
#service ⇒ Object
Returns the value of attribute service.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def service @service end |
#spans ⇒ Object (readonly)
Returns the value of attribute spans.
20 21 22 |
# File 'lib/datadog/tracing/trace_segment.rb', line 20 def spans @spans end |
Instance Method Details
#agent_sample_rate_tag ⇒ Object
170 171 172 |
# File 'lib/datadog/tracing/trace_segment.rb', line 170 def agent_sample_rate_tag metrics[Metadata::Ext::Sampling::TAG_AGENT_RATE] end |
#any? ⇒ Object
95 96 97 |
# File 'lib/datadog/tracing/trace_segment.rb', line 95 def any? @spans.any? end |
#count ⇒ Object
99 100 101 |
# File 'lib/datadog/tracing/trace_segment.rb', line 99 def count @spans.count end |
#empty? ⇒ Boolean
103 104 105 |
# File 'lib/datadog/tracing/trace_segment.rb', line 103 def empty? @spans.empty? end |
#high_order_tid ⇒ Object
Returns the high order part of the trace id as a hexadecimal string; the most significant 64 bits. The String returned is padded with zeros, having a fixed length of 16 characters. If the high order part is zero, it returns nil.
140 141 142 143 144 |
# File 'lib/datadog/tracing/trace_segment.rb', line 140 def high_order_tid high_order = Tracing::Utils::TraceId.to_high_order(@id) format('%016x', high_order) if high_order != 0 end |
#hostname_tag ⇒ Object
174 175 176 |
# File 'lib/datadog/tracing/trace_segment.rb', line 174 def hostname_tag [Metadata::Ext::NET::TAG_HOSTNAME] 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.
120 121 122 |
# File 'lib/datadog/tracing/trace_segment.rb', line 120 def keep! self.sampling_priority = Sampling::Ext::Priority::USER_KEEP end |
#lang_tag ⇒ Object
178 179 180 |
# File 'lib/datadog/tracing/trace_segment.rb', line 178 def lang_tag [Core::Runtime::Ext::TAG_LANG] end |
#length ⇒ Object
107 108 109 |
# File 'lib/datadog/tracing/trace_segment.rb', line 107 def length @spans.length end |
#name_tag ⇒ Object
182 183 184 |
# File 'lib/datadog/tracing/trace_segment.rb', line 182 def name_tag [TAG_NAME] end |
#origin_tag ⇒ Object
186 187 188 |
# File 'lib/datadog/tracing/trace_segment.rb', line 186 def origin_tag [Metadata::Ext::Distributed::TAG_ORIGIN] end |
#process_id_tag ⇒ Object
190 191 192 |
# File 'lib/datadog/tracing/trace_segment.rb', line 190 def process_id_tag [Core::Runtime::Ext::TAG_PROCESS_ID] end |
#rate_limiter_rate_tag ⇒ Object
194 195 196 |
# File 'lib/datadog/tracing/trace_segment.rb', line 194 def rate_limiter_rate_tag metrics[Metadata::Ext::Sampling::TAG_RATE_LIMITER_RATE] 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.
129 130 131 |
# File 'lib/datadog/tracing/trace_segment.rb', line 129 def reject! self.sampling_priority = Sampling::Ext::Priority::USER_REJECT end |
#resource_tag ⇒ Object
198 199 200 |
# File 'lib/datadog/tracing/trace_segment.rb', line 198 def resource_tag [TAG_RESOURCE] end |
#rule_sample_rate_tag ⇒ Object
202 203 204 |
# File 'lib/datadog/tracing/trace_segment.rb', line 202 def rule_sample_rate_tag metrics[Metadata::Ext::Sampling::TAG_RULE_SAMPLE_RATE] end |
#runtime_id_tag ⇒ Object
206 207 208 |
# File 'lib/datadog/tracing/trace_segment.rb', line 206 def runtime_id_tag [Core::Runtime::Ext::TAG_ID] end |
#sample_rate_tag ⇒ Object
210 211 212 |
# File 'lib/datadog/tracing/trace_segment.rb', line 210 def sample_rate_tag metrics[Metadata::Ext::Sampling::TAG_SAMPLE_RATE] end |
#sampled? ⇒ Boolean
133 134 135 |
# File 'lib/datadog/tracing/trace_segment.rb', line 133 def sampled? [Sampling::Ext::Priority::AUTO_KEEP, Sampling::Ext::Priority::USER_KEEP].include?(sampling_priority) end |
#sampling_decision_maker_tag ⇒ Object
214 215 216 |
# File 'lib/datadog/tracing/trace_segment.rb', line 214 def sampling_decision_maker_tag [Metadata::Ext::Distributed::TAG_DECISION_MAKER] end |
#sampling_priority_tag ⇒ Object
218 219 220 |
# File 'lib/datadog/tracing/trace_segment.rb', line 218 def sampling_priority_tag [Metadata::Ext::Distributed::TAG_SAMPLING_PRIORITY] end |
#service_tag ⇒ Object
222 223 224 |
# File 'lib/datadog/tracing/trace_segment.rb', line 222 def service_tag [TAG_SERVICE] end |
#size ⇒ Object
111 112 113 |
# File 'lib/datadog/tracing/trace_segment.rb', line 111 def size @spans.size end |