Skip to content

Commit 1ef815f

Browse files
committed
just some test I've found from user
1 parent 46692ee commit 1ef815f

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

x/rsomla1/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cc_test(
2+
name = "try",
3+
srcs = ["try.cc", "lib.cc"],
4+
deps = ["@otel_sdk//:dll"],
5+
)

x/rsomla1/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
https://github.com/open-telemetry/opentelemetry-cpp/issues/3176
2+
3+
# Download bazelisk, and do this from this folder
4+
5+
bazel test try
6+
7+
```
8+
F:\p\m\opentelemetry-cpp\x\rsomla1>bazel test try
9+
INFO: Invocation ID: a572e4c9-8838-433a-ac10-ba19b92e41a4
10+
WARNING: Streamed test output requested. All tests will be run locally, without sharding, one at a time
11+
INFO: Analyzed target //rsomla1:try (1 packages loaded, 4 targets configured).
12+
INFO: From Linking rsomla1/try.exe:
13+
lld-link: warning: bazel-out/x64_windows-fastbuild/bin/rsomla1/_objs/try/try.obj: locally defined symbol imported: foo (defined in bazel-out/x64_windows-fastbuild/bin/rsomla1/_objs/try/lib.obj) [LNK4217]
14+
foo DONE!
15+
{
16+
name : foo
17+
trace_id : 9a881c06d445a258a4e51401909f7422
18+
span_id : 40bd1aac2e435d33
19+
tracestate :
20+
parent_span_id: 987e069eea5c9aa2
21+
start : 1733110404114213500
22+
duration : 58700
23+
description :
24+
span kind : Internal
25+
status : Unset
26+
attributes :
27+
events :
28+
links :
29+
resources :
30+
telemetry.sdk.language: cpp
31+
telemetry.sdk.name: opentelemetry
32+
telemetry.sdk.version: 1.18.0
33+
service.name: unknown_service
34+
instr-lib : lib-0.0.1
35+
}
36+
Done!
37+
{
38+
name : main
39+
trace_id : 9a881c06d445a258a4e51401909f7422
40+
span_id : 987e069eea5c9aa2
41+
tracestate :
42+
parent_span_id: 0000000000000000
43+
start : 1733110404114169800
44+
duration : 240400
45+
description :
46+
span kind : Internal
47+
status : Unset
48+
attributes :
49+
events :
50+
links :
51+
resources :
52+
telemetry.sdk.language: cpp
53+
telemetry.sdk.name: opentelemetry
54+
telemetry.sdk.version: 1.18.0
55+
service.name: unknown_service
56+
instr-lib : try-0.0.1
57+
}
58+
INFO: Found 1 test target...
59+
Target //rsomla1:try up-to-date:
60+
Q:/b/u/67x23agz/execroot/_main/bazel-out/x64_windows-fastbuild/bin/rsomla1/try.exe
61+
INFO: Elapsed time: 11.789s, Critical Path: 9.35s
62+
INFO: 5 processes: 1 internal, 4 local.
63+
INFO: Build completed successfully, 5 total actions
64+
```

x/rsomla1/lib.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
3+
#ifdef _WIN32
4+
#define EXPORT __declspec(dllexport)
5+
#else
6+
#define EXPORT
7+
#endif
8+
9+
10+
#include <opentelemetry/trace/provider.h>
11+
12+
namespace trace = opentelemetry::trace;
13+
using namespace std;
14+
15+
extern "C" EXPORT void foo()
16+
{
17+
auto provider = trace::Provider::GetTracerProvider();
18+
auto tracer = provider->GetTracer("lib", "0.0.1");
19+
auto span = tracer->StartSpan("foo");
20+
21+
cout << "foo DONE!" << endl;
22+
}

x/rsomla1/try.cc

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <iostream>
2+
3+
#ifdef _WIN32
4+
#define IMPORT __declspec(dllimport)
5+
#else
6+
#define IMPORT
7+
#endif
8+
9+
#include <opentelemetry/exporters/ostream/span_exporter_factory.h>
10+
#include <opentelemetry/sdk/trace/processor.h>
11+
#include <opentelemetry/sdk/trace/simple_processor_factory.h>
12+
#include <opentelemetry/sdk/trace/tracer_provider_factory.h>
13+
#include <opentelemetry/trace/provider.h>
14+
15+
16+
using namespace std;
17+
namespace trace = opentelemetry::trace;
18+
namespace exporter = opentelemetry::exporter;
19+
namespace trace_sdk = opentelemetry::sdk::trace;
20+
namespace nostd = opentelemetry::nostd;
21+
22+
23+
void setup_exporter();
24+
extern "C" IMPORT void foo();
25+
26+
27+
int main(int argc, const char* argv[])
28+
try
29+
{
30+
// Configure trace provider that exports to stdout
31+
32+
using prv_factory = trace_sdk::TracerProviderFactory;
33+
using prc_factory = trace_sdk::SimpleSpanProcessorFactory;
34+
using exp_factory = exporter::trace::OStreamSpanExporterFactory;
35+
36+
trace::Provider::SetTracerProvider(
37+
std::shared_ptr<trace::TracerProvider>{
38+
prv_factory::Create(prc_factory::Create(exp_factory::Create(std::cout)))
39+
}
40+
);
41+
42+
// Get provider and create a span
43+
44+
auto provider = trace::Provider::GetTracerProvider();
45+
auto tracer = provider->GetTracer("try", "0.0.1");
46+
auto span = tracer->StartSpan("main");
47+
trace::Scope scope{tracer->WithActiveSpan(span)};
48+
49+
// Call library function that creates another span.
50+
// Expecting that it will use trace provider configured above.
51+
52+
foo();
53+
54+
cout << "Done!" << endl;
55+
}
56+
catch(const char *e)
57+
{
58+
cout << "ERROR: " << e << endl;
59+
exit(1);
60+
}
61+
catch(std::exception &e)
62+
{
63+
cout << "EXCEPTION: " << e.what() << endl;
64+
exit(1);
65+
}

0 commit comments

Comments
 (0)