aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/wilson/wilson_span.cpp
blob: 42aa3a6fbdb3cfcc90a900a1afb7987f5c9fc100 (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
#include "wilson_span.h"
#include "wilson_uploader.h"
#include <library/cpp/actors/core/log.h>
#include <google/protobuf/text_format.h>

namespace NWilson {

    using namespace NActors;

    void SerializeValue(TAttributeValue value, NCommonProto::AnyValue *pb) {
        switch (value.index()) {
            case 0:
                pb->set_string_value(std::get<0>(std::move(value)));
                break;

            case 1:
                pb->set_bool_value(std::get<1>(value));
                break;

            case 2:
                pb->set_int_value(std::get<2>(value));
                break;

            case 3:
                pb->set_double_value(std::get<3>(std::move(value)));
                break;

            case 4: {
                auto *array = pb->mutable_array_value();
                for (auto&& item : std::get<4>(std::move(value))) {
                    SerializeValue(std::move(item), array->add_values());
                }
                break;
            }

            case 5: {
                auto *kv = pb->mutable_kvlist_value();
                for (auto&& [key, value] : std::get<5>(std::move(value))) {
                    SerializeKeyValue(std::move(key), std::move(value), kv->add_values());
                }
                break;
            }

            case 6:
                pb->set_bytes_value(std::get<6>(std::move(value)));
                break;
        }
    }

    void SerializeKeyValue(TString key, TAttributeValue value, NCommonProto::KeyValue *pb) {
        pb->set_key(std::move(key));
        SerializeValue(std::move(value), pb->mutable_value());
    }

    void TSpan::Send() {
        if (TlsActivationContext) {
            TActivationContext::Send(new IEventHandleFat(MakeWilsonUploaderId(), {}, new TEvWilson(&Data->Span)));
        }
        Data->Sent = true;
    }

} // NWilson