Enhancements to PR #86 Add minimal tracer example#94
Enhancements to PR #86 Add minimal tracer example#94reyang merged 12 commits intoopen-telemetry:masterfrom ankit-bhargava:simple-trace-example
Conversation
|
/check-cla |
| auto processor = std::shared_ptr<sdktrace::SpanProcessor>(new sdktrace::SimpleSpanProcessor( | ||
| std::move(exporter))); // Create a Span Processor given the StdoutExporter defined earlier | ||
| // Initialize a trace provider with the Span Processor instance defined above | ||
| auto provider = nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(processor)); |
There was a problem hiding this comment.
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));
There was a problem hiding this comment.
Reminded me on one thing that I learned long time ago - make the code talk by itself.
|
|
||
| # Simple Trace Example | ||
|
|
||
| This example sets up a tracer in the main application then makes several calls to a custom library instrumented with the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. Specifically, it demonstrates the setup of fundamental Open Telemetry componenets such as Tracers, Tracer Providers and Spans. The example also illustrates context propogation from parent spans to children spans and events. All telemetry output is directed to stdout. |
There was a problem hiding this comment.
I love the idea of having a README for the example. I'd prefer being more concise here. The most important things to point out:
- There's a
foo_librarythat is instrumented with the OpenTelemetry API. - There's an application in
main.ccthat initializes and registers a tracer provider from the OpenTelemetry SDK. Telemetry data is directed to stdout by using a custom exporter.
| bazel-bin/examples/simple/example_simple | ||
| ``` | ||
|
|
||
| ## Useful Links |
There was a problem hiding this comment.
I think this section should be moved somewhere else. Those links aren't specific to this example but useful to the project as a whole (we wouldn't want to have the same information in all examples).
The same would apply to the Build and Run section. I think it would be better to have more general build instructions at a more central location.
There was a problem hiding this comment.
I agree the links aren't relevant. Where would you suggest I move the build/run instructions? I don't think it would hurt to leave them here as well as duplicate them somewhere else as many interns like myself have never used bazel before
There was a problem hiding this comment.
I would move those instructions to the CONTRIBUTING doc. Java has instructions placed there.
|
I removed superfluous comments, polished the README, and moved instructions/links to CONTRIBUTING doc in PR #97 |
|
@ankit-bhargava #86 got merged, please rebase. Thanks. |
|
@reyang Rebased, thanks |
| int main() | ||
| { | ||
| // Removing this line will leave OT initialized with the default noop | ||
| // Removing this line will leave OTel SDK initialized with the default noop |
There was a problem hiding this comment.
This has brought an interesting topic, neither the term OT nor OTel has been officially blessed https://github.com/open-telemetry/opentelemetry-specification/search?q=OTel&unscoped_q=OTel.
There was a problem hiding this comment.
I'll use "OpenTelemetry" to avoid confusion in that case.
|
|
||
| # Simple Trace Example | ||
|
|
||
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. |
There was a problem hiding this comment.
nit: consider using "the application" instead of "an application in main.cc"?
|
|
||
| # Simple Trace Example | ||
|
|
||
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. |
There was a problem hiding this comment.
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. | |
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> OpenTelemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. |
|
|
||
| # Simple Trace Example | ||
|
|
||
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. |
There was a problem hiding this comment.
Please use markdown links.
[Open Telemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp)
|
|
||
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. | ||
|
|
||
| See <a href="https://github.com/open-telemetry/opentelemetry-cpp/blob/master/CONTRIBUTING.md"> CONTRIBUTING.md </a> for instructions on building and running the example. |
| int main() | ||
| { | ||
| // Removing this line will leave OT initialized with the default noop | ||
| // Removing this line will leave OpenTelemetry SDK initialized with the default noop |
There was a problem hiding this comment.
probably "the SDK"? - I don't know - what do you think @pyohannes?
There was a problem hiding this comment.
If we want to split some hairs, leaving out this line has the effect that no SDK is used at all. All the noop stuff is in the API.
Maybe:
Removing this line will leave the default noop TracerProvider in place.
| // tracer, thus being effectively deactivated. | ||
| initTracer(); | ||
|
|
||
| // Call the instrumented library |
|
|
||
| # Simple Trace Example | ||
|
|
||
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. |
There was a problem hiding this comment.
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been manually instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry is directed to stdout through a custom exporter. | |
| In this example, an application in `main.cc` initializes and registers a tracer provider from the <a href="https://github.com/open-telemetry/opentelemetry-cpp"> Open Telemetry SDK </a>. The application then calls a `foo_library` which has been instrumented using the <a href="https://github.com/open-telemetry/opentelemetry-cpp/tree/master/api"> OpenTelemetry API </a>. Resulting telemetry data is directed to stdout through a custom exporter. |
There was a problem hiding this comment.
manually instrumented doesn't really make sense, as we only support manual instrumentation. This might suggest we can do automatic instrumentation, but we don't.
|
|
||
| # 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. |
There was a problem hiding this comment.
Would you add line wrapping at column 80?
There was a problem hiding this comment.
Use one space instead of two for consistency.
There was a problem hiding this comment.
fixed both :)
| { | ||
| auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new StdoutExporter); | ||
| auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new StdoutExporter); | ||
| // Specify the Span Processor: SimpleSpanProcessor forwards spans directly to the exporter |
There was a problem hiding this comment.
Span Processor -> SpanProcessor (remove the space)
I also wonder if this is self-explanatory?
There was a problem hiding this comment.
agreed, removed the comment
|
This is ready to merge, @ankit-bhargava would you rebase? |
| # 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). |
There was a problem hiding this comment.
Can the leading spaces be removed?
Co-authored-by: Reiley Yang <reyang@microsoft.com>
Replacing the unofficial "OTel" shorthand with the "OpenTelemetry"


This PR adds build and run documentation in README.md as well as adds inline comments for the simple tracer example in PR #86 .