LCOV - code coverage report
Current view: top level - include/hpactor/tracing - sampler.hpp (source / functions) Coverage Total Hit
Test: HPActor Coverage Lines: 100.0 % 2 2
Test Date: 2026-05-20 02:24:49 Functions: 66.7 % 3 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #pragma once
       2                 :             : 
       3                 :             : #include <hpactor/types/types.hpp>
       4                 :             : 
       5                 :             : #include <atomic>
       6                 :             : #include <cstdint>
       7                 :             : 
       8                 :             : namespace hpactor::tracing {
       9                 :             : 
      10                 :             : struct SamplingParameters {
      11                 :             :     TraceId trace_id;
      12                 :             :     bool has_parent{false};
      13                 :             :     bool parent_sampled{false};
      14                 :             : };
      15                 :             : 
      16                 :             : struct SamplingDecision {
      17                 :             :     bool sampled{false};
      18                 :             : };
      19                 :             : 
      20                 :             : class Sampler {
      21                 :             :   public:
      22                 :          12 :     virtual ~Sampler() = default;
      23                 :             :     virtual SamplingDecision
      24                 :             :     should_sample(const SamplingParameters& params) const noexcept = 0;
      25                 :             : };
      26                 :             : 
      27                 :             : class AlwaysOnSampler final : public Sampler {
      28                 :             :   public:
      29                 :             :     SamplingDecision
      30                 :             :     should_sample(const SamplingParameters& params) const noexcept override;
      31                 :             : };
      32                 :             : 
      33                 :             : class AlwaysOffSampler final : public Sampler {
      34                 :             :   public:
      35                 :             :     SamplingDecision
      36                 :             :     should_sample(const SamplingParameters& params) const noexcept override;
      37                 :             : };
      38                 :             : 
      39                 :             : class TraceIdRatioSampler final : public Sampler {
      40                 :             :   public:
      41                 :             :     explicit TraceIdRatioSampler(double ratio);
      42                 :             :     SamplingDecision
      43                 :             :     should_sample(const SamplingParameters& params) const noexcept override;
      44                 :             : 
      45                 :             :   private:
      46                 :             :     double ratio_{0.0};
      47                 :             : };
      48                 :             : 
      49                 :             : class ParentBasedSampler final : public Sampler {
      50                 :             :   public:
      51                 :             :     explicit ParentBasedSampler(double root_ratio);
      52                 :             :     SamplingDecision
      53                 :             :     should_sample(const SamplingParameters& params) const noexcept override;
      54                 :             : 
      55                 :             :   private:
      56                 :             :     TraceIdRatioSampler root_sampler_;
      57                 :             : };
      58                 :             : 
      59                 :             : class TraceIdGenerator {
      60                 :             :   public:
      61                 :           5 :     TraceIdGenerator() = default;
      62                 :             :     TraceId next_trace_id() noexcept;
      63                 :             :     SpanId next_span_id() noexcept;
      64                 :             : 
      65                 :             :   private:
      66                 :             :     std::atomic<uint64_t> counter_{1};
      67                 :             : };
      68                 :             : 
      69                 :             : } // namespace hpactor::tracing
        

Generated by: LCOV version 2.0-1