Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : // Licensed under the Apache License, Version 2.0
3 : :
4 : : #include <hpactor/config/toml_config_parser.hpp>
5 : : #include <hpactor/config/toml_parser_registry.hpp>
6 : : #include <hpactor/tracing/trace_config.hpp>
7 : :
8 : : namespace hpactor::config {
9 : : namespace {
10 : :
11 : : class TracingConfigParser final : public ITomlSystemConfigParser {
12 : : public:
13 : : static constexpr std::string_view kName = "system.tracing";
14 : : static constexpr int kOrder = 90;
15 : :
16 : 0 : std::string_view name() const noexcept override {
17 : 0 : return kName;
18 : : }
19 : 0 : int order() const noexcept override {
20 : 0 : return kOrder;
21 : : }
22 : :
23 : 35 : result<void> parse(const TomlTableView& st, SystemDef& out,
24 : : TomlParseContext& /*ctx*/) const override {
25 : 35 : auto tracing = st.table("tracing");
26 : 35 : if (!tracing.valid()) {
27 : 35 : return result<void>::make();
28 : : }
29 : :
30 : 0 : auto& cfg = out.tracing;
31 : 0 : cfg.enabled = tracing.read_bool("enabled", false);
32 : 0 : cfg.service_name = tracing.read_string("service_name", "hpactor");
33 : 0 : cfg.propagate_unsampled = tracing.read_bool("propagate_unsampled", true);
34 : 0 : cfg.ring_buffer_capacity =
35 : 0 : tracing.read_uint32("ring_buffer_capacity", 65536);
36 : :
37 : 0 : auto sampler_str = tracing.read_string("sampler", "parent_based_trace_"
38 : 0 : "id_ratio");
39 : 0 : if (sampler_str == "always_off")
40 : 0 : cfg.sampler = hpactor::tracing::SamplerKind::kAlwaysOff;
41 : 0 : else if (sampler_str == "always_on")
42 : 0 : cfg.sampler = hpactor::tracing::SamplerKind::kAlwaysOn;
43 : 0 : else if (sampler_str == "trace_id_ratio")
44 : 0 : cfg.sampler = hpactor::tracing::SamplerKind::kTraceIdRatio;
45 : : else
46 : 0 : cfg.sampler = hpactor::tracing::SamplerKind::kParentBasedTraceIdRatio;
47 : :
48 : 0 : auto exporter_str = tracing.read_string("exporter", "otlp_http");
49 : 0 : if (exporter_str == "noop")
50 : 0 : cfg.exporter = hpactor::tracing::TraceExporterKind::kNoop;
51 : 0 : else if (exporter_str == "memory")
52 : 0 : cfg.exporter = hpactor::tracing::TraceExporterKind::kMemory;
53 : 0 : else if (exporter_str == "json_file")
54 : 0 : cfg.exporter = hpactor::tracing::TraceExporterKind::kJsonFile;
55 : : else
56 : 0 : cfg.exporter = hpactor::tracing::TraceExporterKind::kOtlpHttp;
57 : :
58 : 0 : cfg.otlp_endpoint = tracing.read_string("otlp_endpoint", "http://"
59 : : "127.0.0.1:"
60 : : "4318/v1/"
61 : 0 : "traces");
62 : 0 : cfg.json_file_path = tracing.read_string("json_file_path", "");
63 : 0 : cfg.export_interval = std::chrono::milliseconds(
64 : 0 : tracing.read_uint32("export_interval_ms", 500));
65 : 0 : cfg.max_export_batch_size =
66 : 0 : tracing.read_uint32("max_export_batch_size", 512);
67 : 0 : cfg.max_tracestate_len =
68 : 0 : static_cast<uint16_t>(tracing.read_uint32("max_tracestate_len", 256));
69 : 0 : cfg.record_actor_receive_spans =
70 : 0 : tracing.read_bool("record_actor_receive_spans", true);
71 : 0 : cfg.record_remote_producer_spans =
72 : 0 : tracing.read_bool("record_remote_producer_spans", true);
73 : 0 : cfg.record_local_producer_spans =
74 : 0 : tracing.read_bool("record_local_producer_spans", false);
75 : 0 : cfg.record_payload_size = tracing.read_bool("record_payload_size", true);
76 : 0 : cfg.create_roots_for_actor_context_sends =
77 : 0 : tracing.read_bool("create_roots_for_actor_context_sends", false);
78 : 0 : cfg.create_roots_for_rpc = tracing.read_bool("create_roots_for_rpc", true);
79 : 0 : cfg.create_roots_for_http_ingress =
80 : 0 : tracing.read_bool("create_roots_for_http_ingress", true);
81 : :
82 : : // Sample ratio
83 : 0 : cfg.sample_ratio = tracing.read_double("sample_ratio", 0.01);
84 : :
85 : 0 : return result<void>::make();
86 : 0 : }
87 : : };
88 : :
89 : : const TomlSystemParserRegistration<TracingConfigParser> kRegisterTracingConfigParser;
90 : :
91 : : } // anonymous namespace
92 : : } // namespace hpactor::config
|