MCPcopy Create free account
hub / github.com/apache/qpid-proton / main

Function main

cpp/examples/tracing_server.cpp:105–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103};
104
105int main(int argc, char **argv) {
106 try {
107 std::string conn_url = argc > 1 ? argv[1] : "//127.0.0.1:5672";
108 std::string addr = argc > 2 ? argv[2] : "examples";
109
110 // 1. Initialize the exporter and the provider
111 // 2. Set the global trace provider
112 // 3. Call proton::initOpenTelemetryTracer()
113
114 // Initialize otlp http Exporter
115 opentelemetry::exporter::otlp::OtlpHttpExporterOptions options;
116 options.url = "localhost:4318";
117 auto exporter = std::unique_ptr<opentelemetry::sdk::trace::SpanExporter>(new opentelemetry::exporter::otlp::OtlpHttpExporter(options));
118
119
120 // Set service-name
121 auto resource_attributes = opentelemetry::sdk::resource::ResourceAttributes
122 {
123 {"service.name", "qpid-example-server"}
124 };
125
126 // Creation of the resource for associating it with telemetry
127 auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes);
128
129 auto processor = std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>(
130 new opentelemetry::sdk::trace::SimpleSpanProcessor(std::move(exporter)));
131 provider = opentelemetry::nostd::shared_ptr<opentelemetry::trace::TracerProvider>(
132 new opentelemetry::sdk::trace::TracerProvider(std::move(processor), resource));
133
134 // Set the global trace provider
135 opentelemetry::trace::Provider::SetTracerProvider(provider);
136
137 // Enable tracing in proton cpp
138 proton::initOpenTelemetryTracer();
139
140 server srv(conn_url, addr);
141 proton::container(srv).run();
142
143 return 0;
144 } catch (const std::exception& e) {
145 std::cerr << e.what() << std::endl;
146 }
147
148 return 1;
149}

Callers

nothing calls this directly

Calls 4

initOpenTelemetryTracerFunction · 0.50
containerClass · 0.50
runMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected