ORE Studio 0.0.4
Loading...
Searching...
No Matches
trace_id_generator.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TELEMETRY_GENERATORS_TRACE_ID_GENERATOR_HPP
21#define ORES_TELEMETRY_GENERATORS_TRACE_ID_GENERATOR_HPP
22
23#include <cstdint>
24#include <mutex>
25#include <random>
26#include "ores.telemetry/domain/trace_id.hpp"
27
29
44class trace_id_generator final {
45public:
53
59 explicit trace_id_generator(std::uint16_t machine_id);
60
69
73 std::uint16_t machine_id() const;
74
75private:
76 std::uint16_t machine_id_;
77 std::mt19937_64 random_engine_;
78 mutable std::mutex mutex_;
79
80 static std::uint16_t derive_machine_id();
81};
82
83}
84
85#endif
ID generators for telemetry types.
Definition ores.telemetry.generators.hpp:28
A 128-bit trace identifier, compatible with OpenTelemetry.
Definition trace_id.hpp:42
Generator for 128-bit trace IDs with embedded metadata.
Definition trace_id_generator.hpp:44
std::uint16_t machine_id() const
Gets the machine ID being used by this generator.
Definition trace_id_generator.cpp:76
trace_id_generator()
Constructs the generator with locally derived machine ID.
Definition trace_id_generator.cpp:32
domain::trace_id operator()()
Generates a new trace_id.
Definition trace_id_generator.cpp:40