Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to PR #86 Add minimal tracer example #94

Merged
merged 12 commits into from
Jun 19, 2020
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ include(CTest)
find_package(Threads)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Options for Visual C++ compiler:
# /Zc:__cplusplus - report an updated value for recent C++ language standards.
# Without this option MSVC returns the value of __cplusplus="199711L"
# Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value
# for recent C++ language standards. Without this option MSVC returns the
# value of __cplusplus="199711L"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
endif()

Expand Down
10 changes: 10 additions & 0 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Simple Trace Example

In this example, the application in `main.cc` initializes and registers a tracer
provider from the [OpenTelemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp).
The application then calls a `foo_library` which has been instrumented using
the [OpenTelemetry API](https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api).
Resulting telemetry is directed to stdout through a custom exporter.

See [CONTRIBUTING.md](../../CONTRIBUTING.md) for instructions on building and running the example.
4 changes: 2 additions & 2 deletions examples/simple/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ void initTracer()
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(processor));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more sparse with inline comments and only use them to hint at things that cannot be inferred from the code itself. Otherwise they tend to make code harder to read instead of making it easier. There's no information in

// Initialize a trace provider with the Span Processor instance defined above

that cannot be inferred from

auto provider = nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(processor));

Copy link
Member

@reyang reyang Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminded me on one thing that I learned long time ago - make the code talk by itself.

// Set the global trace provider
trace::Provider::SetTracerProvider(provider);
}
} // namespace

int main()
{
// Removing this line will leave OT initialized with the default noop
// tracer, thus being effectively deactivated.
// Removing this line will leave the default noop TracerProvider in place.
initTracer();

foo_library();
Expand Down