2 * Copyright (c) 2018 Uber Technologies, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "TracerFactory.h"
19 #include "jaegertracing/Tracer.h"
21 namespace jaegertracing
{
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
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
));
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
);
41 auto tracerConfig
= jaegertracing::Config::parse(yaml
);
44 tracerConfig
.fromEnv();
47 if (tracerConfig
.serviceName().empty()) {
48 errorMessage
= "`service_name` not provided";
49 return opentracing::make_unexpected(
50 opentracing::invalid_configuration_error
);
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
);
63 } // namespace jaegertracing