]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #ifndef OPENTRACING_TRACER_FACTORY_H |
2 | #define OPENTRACING_TRACER_FACTORY_H | |
3 | ||
4 | #include <opentracing/symbols.h> | |
5 | #include <opentracing/tracer.h> | |
6 | #include <opentracing/version.h> | |
7 | ||
8 | namespace opentracing { | |
9 | BEGIN_OPENTRACING_ABI_NAMESPACE | |
10 | // Returns the std::error_category class used for tracer factory errors. | |
11 | // | |
12 | // See | |
13 | // http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html | |
14 | // https://ned14.github.io/boost.outcome/md_doc_md_03-tutorial_b.html | |
15 | OPENTRACING_API const std::error_category& tracer_factory_error_category(); | |
16 | ||
17 | // `configuration_parse_error` occurs when the configuration string used to | |
18 | // construct a tracer does not adhere to the expected format. | |
19 | const std::error_code configuration_parse_error( | |
20 | 1, tracer_factory_error_category()); | |
21 | ||
22 | // `invalid_configuration_error` occurs if the requested configuration for a | |
23 | // tracer has invalid values. | |
24 | const std::error_code invalid_configuration_error( | |
25 | 2, tracer_factory_error_category()); | |
26 | ||
27 | // TracerFactory constructs tracers from configuration strings. | |
28 | class OPENTRACING_API TracerFactory { | |
29 | public: | |
30 | virtual ~TracerFactory() = default; | |
31 | ||
32 | // Creates a tracer with the requested `configuration`. | |
33 | // | |
34 | // Example, | |
35 | // const char* configuration = R"( | |
36 | // "collector": "localhost:123", | |
37 | // "max_buffered_spans": 500 | |
38 | // )"; | |
39 | // std:string error_message; | |
40 | // auto tracer_maybe = tracer_factory->MakeTracer(configuration, | |
41 | // error_message); | |
42 | // if (tracer_mabye) { | |
43 | // // success | |
44 | // std::shared_ptr<opentracing::Tracer> tracer = *tracer_maybe; | |
45 | // } else { | |
46 | // // failure | |
47 | // std::error_code error = tracer_maybe.error(); | |
48 | // // `error_message` may also contain a more descriptive message | |
49 | // } | |
50 | virtual expected<std::shared_ptr<Tracer>> MakeTracer( | |
51 | const char* configuration, std::string& error_message) const noexcept = 0; | |
52 | }; | |
53 | END_OPENTRACING_ABI_NAMESPACE | |
54 | } // namespace opentracing | |
55 | ||
56 | #endif // OPENTRACING_TRACER_FACTORY_H |