22// SPDX-License-Identifier: Apache-2.0
33
44#include " opentelemetry/logs/provider.h"
5+ #include " opentelemetry/trace/provider.h"
6+ #include " opentelemetry/trace/span.h"
57#include " opentelemetry/exporters/geneva/geneva_logger_exporter.h"
8+ #include " opentelemetry/exporters/geneva/geneva_tracer_exporter.h"
69
710#include < string>
811
912const char *kGlobalProviderName = " OpenTelemetry-ETW-TLD-Geneva-Example" ;
1013std::string providerName = kGlobalProviderName ;
1114
15+ using L = std::vector<std::pair<trace_api::SpanContext, std::map<std::string, std::string>>>;
16+
1217namespace
1318{
19+ auto InitTracer ()
20+ {
21+ static opentelemetry::exporter::etw::TracerProvider tracer_provider;
22+ auto tracer = tracer_provider.GetTracer (providerName, " 1.0" );
23+
24+ return tracer;
25+ }
1426auto InitLogger ()
1527{
16- opentelemetry::exporter::etw::LoggerProvider logger_provider;
28+ static opentelemetry::exporter::etw::LoggerProvider logger_provider;
1729 auto logger = logger_provider.GetLogger (providerName, " 1.0" );
1830
1931 return logger;
@@ -22,8 +34,35 @@ auto InitLogger()
2234
2335int main ()
2436{
37+ auto tracer = InitTracer ();
2538 auto logger = InitLogger ();
2639
40+ auto s1 = tracer->StartSpan (" main" );
41+
42+ {
43+ L link1 = {{s1->GetContext (), {}}};
44+
45+ // Create Span with 1 SpanLink
46+ auto s2 = tracer->StartSpan (" child" , opentelemetry::common::MakeAttributes ({{" key1" , " value 1" }, {" key2" , 1 }}), link1);
47+
48+ s2->SetAttribute (" attr_key1" , 123 );
49+
50+ {
51+ L link2 = {{s1->GetContext (), {}}, {s2->GetContext (), {}}};
52+
53+ // Create Span with 2 SpanLinks
54+ auto s3 = tracer->StartSpan (" grandchild" , opentelemetry::common::MakeAttributes ({{" key3" , " value 3" }, {" key4" , 2 }}), link2);
55+
56+ s3->SetAttribute (" attr_key2" , 456 );
57+
58+ s3->End ();
59+ }
60+
61+ s2->End ();
62+ }
63+
64+ s1->End ();
65+
2766 logger->Info (" Hello World!" );
2867
2968 return 0 ;
0 commit comments