-
Notifications
You must be signed in to change notification settings - Fork 230
/
trace_flags.rb
50 lines (43 loc) · 1.4 KB
/
trace_flags.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
module Trace
# TraceFlags contain details about the trace. Unlike Tracestate values,
# TraceFlags are present in all traces. Currently, the only TraceFlag is a
# boolean {sampled?} {https://www.w3.org/TR/trace-context/#trace-flags flag}.
class TraceFlags
class << self
private :new
# Returns a newly created {TraceFlags} with the specified flags.
#
# @param [Integer] flags 8-bit byte of bit flags
# @return [TraceFlags]
def from_byte(flags)
flags = 0 unless flags & ~0xFF == 0 # rubocop:disable Style/NumericPredicate
new(flags)
end
end
# @api private
# The constructor is private and only for use internally by the class.
# Users should use the {from_byte} factory method to obtain a {TraceFlags}
# instance.
#
# @param [Integer] flags 8-bit byte of bit flags
# @return [TraceFlags]
def initialize(flags)
@flags = flags
end
# Returns whether the caller may have recorded trace data. When false,
# the caller did not record trace data out-of-band.
#
# @return [Boolean]
def sampled?
(@flags & 1) != 0
end
DEFAULT = from_byte(0)
SAMPLED = from_byte(1)
end
end
end