Skip to content

Add a minimal tracer example#86

Merged
reyang merged 9 commits into
open-telemetry:masterfrom
pyohannes:simple-trace-example
Jun 8, 2020
Merged

Add a minimal tracer example#86
reyang merged 9 commits into
open-telemetry:masterfrom
pyohannes:simple-trace-example

Conversation

@pyohannes
Copy link
Copy Markdown
Contributor

@pyohannes pyohannes commented May 15, 2020

This adds a trivial example, which sets up a tracer in the main application and uses a library that is instrumented with OT. The example tries to be as minimal as possible (the biggest chunk being a stdout exporter).

I had to move some other bits to make the example work:

  • The simple_processor.h needs to be moved to the public include directory to be available for application developers to use.
  • The tracer in the tracer provider needs to be stored as in a shared_ptr instead of a nostd::shared_ptr, otherwise we run into problems with shared_from_this.

Some things still need to be done: timestamps, durations and ids are not initialized for spans. I'll probably look into this in a separate PR.

Copy link
Copy Markdown
Contributor

@g-easy g-easy left a comment

Choose a reason for hiding this comment

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

Nice!

Comment thread examples/simple/BUILD Outdated
Comment thread examples/simple/library.cc Outdated
Comment thread examples/simple/library.cc Outdated
Comment thread examples/simple/library.cc
Comment thread examples/simple/main.cc Outdated
Comment thread examples/simple/main.cc
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new StdoutExporter);
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

std::move(processor) ?

Comment thread examples/simple/main.cc
auto processor = std::shared_ptr<sdktrace::SpanProcessor>(
new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<trace::TracerProvider>(new sdktrace::TracerProvider(processor));
trace::Provider::SetTracerProvider(provider);
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/should this also be std::moved?

Comment thread examples/simple/stdout_exporter.h
Comment thread examples/simple/stdout_exporter.h Outdated
return std::unique_ptr<sdktrace::Recordable>(new sdktrace::SpanData);
}

sdktrace::ExportResult Export(nostd::span<std::unique_ptr<sdktrace::Recordable>> &spans) noexcept
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.

How come none of this is const?

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 changed the span to const (although I think it wouldn't matter much, as the processor sees the content of the span as invalidated anyway after the call to Export).

Was this the intent of your question? Or do you also think the recordable itself should be const?

Comment thread examples/simple/stdout_exporter.h Outdated
@pyohannes pyohannes force-pushed the simple-trace-example branch from 0158c24 to 8251da7 Compare June 8, 2020 22:22
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. #94 will cover more improvements.

@reyang reyang merged commit 2973baa into open-telemetry:master Jun 8, 2020
reyang pushed a commit that referenced this pull request Jun 19, 2020
@pyohannes pyohannes mentioned this pull request Jul 7, 2020
GerHobbelt pushed a commit to GerHobbelt/opentelemetry-cpp that referenced this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants