]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/Config.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / Config.h
1 /*
2 * Copyright (c) 2017 Uber Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef JAEGERTRACING_CONFIG_H
18 #define JAEGERTRACING_CONFIG_H
19
20 #include "jaegertracing/Compilers.h"
21 #include "jaegertracing/Constants.h"
22 #include "jaegertracing/Tag.h"
23 #include "jaegertracing/baggage/RestrictionsConfig.h"
24 #include "jaegertracing/propagation/HeadersConfig.h"
25 #include "jaegertracing/reporters/Config.h"
26 #include "jaegertracing/samplers/Config.h"
27 #include "jaegertracing/utils/YAML.h"
28
29 namespace jaegertracing {
30
31 class Config {
32 public:
33
34 static constexpr auto kJAEGER_SERVICE_NAME_ENV_PROP = "JAEGER_SERVICE_NAME";
35 static constexpr auto kJAEGER_TAGS_ENV_PROP = "JAEGER_TAGS";
36 static constexpr auto kJAEGER_JAEGER_DISABLED_ENV_PROP = "JAEGER_DISABLED";
37
38 #ifdef JAEGERTRACING_WITH_YAML_CPP
39
40 static Config parse(const YAML::Node& configYAML)
41 {
42 if (!configYAML.IsDefined() || !configYAML.IsMap()) {
43 return Config();
44 }
45
46 const auto serviceName =
47 utils::yaml::findOrDefault<std::string>(configYAML, "service_name", "");
48
49 const auto disabled =
50 utils::yaml::findOrDefault<bool>(configYAML, "disabled", false);
51 const auto samplerNode = configYAML["sampler"];
52 const auto sampler = samplers::Config::parse(samplerNode);
53 const auto reporterNode = configYAML["reporter"];
54 const auto reporter = reporters::Config::parse(reporterNode);
55 const auto headersNode = configYAML["headers"];
56 const auto headers = propagation::HeadersConfig::parse(headersNode);
57 const auto baggageRestrictionsNode = configYAML["baggage_restrictions"];
58 const auto baggageRestrictions =
59 baggage::RestrictionsConfig::parse(baggageRestrictionsNode);
60 return Config(
61 disabled, sampler, reporter, headers, baggageRestrictions, serviceName);
62 }
63
64 #endif // JAEGERTRACING_WITH_YAML_CPP
65
66 explicit Config(bool disabled = false,
67 const samplers::Config& sampler = samplers::Config(),
68 const reporters::Config& reporter = reporters::Config(),
69 const propagation::HeadersConfig& headers =
70 propagation::HeadersConfig(),
71 const baggage::RestrictionsConfig& baggageRestrictions =
72 baggage::RestrictionsConfig(),
73 const std::string& serviceName = "",
74 const std::vector<Tag>& tags = std::vector<Tag>())
75 : _disabled(disabled)
76 , _serviceName(serviceName)
77 , _tags(tags)
78 , _sampler(sampler)
79 , _reporter(reporter)
80 , _headers(headers)
81 , _baggageRestrictions(baggageRestrictions)
82 {
83 }
84
85 bool disabled() const { return _disabled; }
86
87 const samplers::Config& sampler() const { return _sampler; }
88
89 const reporters::Config& reporter() const { return _reporter; }
90
91 const propagation::HeadersConfig& headers() const { return _headers; }
92
93 const baggage::RestrictionsConfig& baggageRestrictions() const
94 {
95 return _baggageRestrictions;
96 }
97
98 const std::string& serviceName() const { return _serviceName; }
99
100 const std::vector<Tag>& tags() const { return _tags; }
101
102 void fromEnv();
103
104 private:
105 bool _disabled;
106 std::string _serviceName;
107 std::vector< Tag > _tags;
108 samplers::Config _sampler;
109 reporters::Config _reporter;
110 propagation::HeadersConfig _headers;
111 baggage::RestrictionsConfig _baggageRestrictions;
112 };
113
114 } // namespace jaegertracing
115
116 #endif // JAEGERTRACING_CONFIG_H