Skip to content

Enhancements to PR #86 Add minimal tracer example#94

Merged
reyang merged 12 commits intoopen-telemetry:masterfrom
ankit-bhargava:simple-trace-example
Jun 19, 2020
Merged

Enhancements to PR #86 Add minimal tracer example#94
reyang merged 12 commits intoopen-telemetry:masterfrom
ankit-bhargava:simple-trace-example

Conversation

@ankit-bhargava
Copy link
Copy Markdown
Contributor

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

@WillsonHG
Copy link
Copy Markdown

/check-cla

Comment thread examples/simple/main.cc
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));
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_library that is instrumented with the OpenTelemetry API.
  • There's an application in main.cc that initializes and registers a tracer provider from the OpenTelemetry SDK. Telemetry data is directed to stdout by using a custom exporter.

Comment thread examples/simple/README.md Outdated
bazel-bin/examples/simple/example_simple
```

## Useful Links
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would move those instructions to the CONTRIBUTING doc. Java has instructions placed there.

@ankit-bhargava
Copy link
Copy Markdown
Contributor Author

I removed superfluous comments, polished the README, and moved instructions/links to CONTRIBUTING doc in PR #97

@reyang
Copy link
Copy Markdown
Member

reyang commented Jun 8, 2020

@ankit-bhargava #86 got merged, please rebase. Thanks.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jun 11, 2020

CLA Check
The committers are authorized under a signed CLA.

@ankit-bhargava
Copy link
Copy Markdown
Contributor Author

@reyang Rebased, thanks

Comment thread examples/simple/README.md Outdated
Comment thread examples/simple/main.cc Outdated
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll use "OpenTelemetry" to avoid confusion in that case.

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: consider using "the application" instead of "an application in main.cc"?

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove the extra space before/after <a>/</a>. Otherwise it'll render an extra white space which is buggy.

image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use markdown links.

[Open Telemetry SDK](https://github.com/open-telemetry/opentelemetry-cpp)

Comment thread examples/simple/README.md Outdated

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use relative link.

Comment thread examples/simple/main.cc Outdated
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably "the SDK"? - I don't know - what do you think @pyohannes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread examples/simple/main.cc Outdated
// tracer, thus being effectively deactivated.
initTracer();

// Call the instrumented library
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here, seems unnecessary.

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread examples/simple/README.md Outdated

# 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you add line wrapping at column 80?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use one space instead of two for consistency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed both :)

Comment thread examples/simple/main.cc Outdated
{
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Span Processor -> SpanProcessor (remove the space)

I also wonder if this is self-explanatory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agreed, removed the comment

@reyang reyang added the documentation Improvements or additions to documentation label Jun 16, 2020
@ankit-bhargava ankit-bhargava requested a review from a team June 17, 2020 14:58
Copy link
Copy Markdown
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

@reyang
Copy link
Copy Markdown
Member

reyang commented Jun 17, 2020

This is ready to merge, @ankit-bhargava would you rebase?

Comment thread examples/simple/README.md Outdated
# 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).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can the leading spaces be removed?

@reyang reyang merged commit c86794e into open-telemetry:master Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants