]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/TracerFactory.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / TracerFactory.cpp
1 /*
2 * Copyright (c) 2018 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 #include "TracerFactory.h"
18
19 #include "jaegertracing/Tracer.h"
20
21 namespace jaegertracing {
22
23 opentracing::expected<std::shared_ptr<opentracing::Tracer>>
24 TracerFactory::MakeTracer(const char* configuration,
25 std::string& errorMessage) const noexcept try {
26 #ifndef JAEGERTRACING_WITH_YAML_CPP
27 errorMessage =
28 "Failed to construct tracer: Jaeger was not build with yaml support.";
29 return opentracing::make_unexpected(
30 std::make_error_code(std::errc::not_supported));
31 #else
32 YAML::Node yaml;
33 try {
34 yaml = YAML::Load(configuration);
35 } catch (const YAML::ParserException& e) {
36 errorMessage = e.what();
37 return opentracing::make_unexpected(
38 opentracing::configuration_parse_error);
39 }
40
41 auto tracerConfig = jaegertracing::Config::parse(yaml);
42
43 if (_readFromEnv) {
44 tracerConfig.fromEnv();
45 }
46
47 if (tracerConfig.serviceName().empty()) {
48 errorMessage = "`service_name` not provided";
49 return opentracing::make_unexpected(
50 opentracing::invalid_configuration_error);
51 }
52
53 return jaegertracing::Tracer::make(tracerConfig);
54 #endif // JAEGERTRACING_WITH_YAML_CPP
55 } catch (const std::bad_alloc&) {
56 return opentracing::make_unexpected(
57 std::make_error_code(std::errc::not_enough_memory));
58 } catch (const std::exception& e) {
59 errorMessage = e.what();
60 return opentracing::make_unexpected(
61 opentracing::invalid_configuration_error);
62 }
63 } // namespace jaegertracing