Sha256: c37703ed9dc7a69d3252084233b224f019d89632046f9c115d5590587c044985

Contents?: true

Size: 1.45 KB

Versions: 14

Compression:

Stored size: 1.45 KB

Contents

# 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 # rubocop:disable Style/AccessModifierDeclarations

        # 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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
opentelemetry-api-1.0.2 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-1.0.1 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-1.0.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-1.0.0.rc3 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-1.0.0.rc2 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-1.0.0.rc1 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.17.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.16.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.15.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.14.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.13.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.12.1 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.12.0 lib/opentelemetry/trace/trace_flags.rb
opentelemetry-api-0.11.0 lib/opentelemetry/trace/trace_flags.rb