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

[Examples] Memory ownership issues in InMemorySpanExporter usage example. #1473

Closed
marcalff opened this issue Jul 1, 2022 · 1 comment · Fixed by #1471
Closed

[Examples] Memory ownership issues in InMemorySpanExporter usage example. #1473

marcalff opened this issue Jul 1, 2022 · 1 comment · Fixed by #1471
Labels
bug Something isn't working

Comments

@marcalff
Copy link
Member

marcalff commented Jul 1, 2022

In example multi_processor/main.cc, the code:

Builds a InMemorySpanExporter object

  InMemorySpanExporter *memory_span_exporter = new InMemorySpanExporter();
  auto exporter2 = std::unique_ptr<trace_sdk::SpanExporter>(memory_span_exporter);

Transfers memory ownership to a SpanProcessor

  auto processor2 = std::unique_ptr<trace_sdk::SpanProcessor>(
      new trace_sdk::SimpleSpanProcessor(std::move(exporter2)));

Use the underlying InMemorySpanExporter object directly.

  InMemorySpanExporter *memory_span_exporter = initTracer();

  foo_library();
  auto memory_spans = memory_span_exporter->GetData()->GetSpans();

This usage of InMemorySpanExporter is unsafe, as the exporter pointer is not owned, and the exporter could go away for example when installing a different global tracer provider (if I understand correctly).

Suggested fix:

initTracer() should return the underlying InMemorySpanData instead, which is safe to do because the data is held by a shared pointer.
Even if the exporter goes away, the data will still be accessible.

@marcalff marcalff added the bug Something isn't working label Jul 1, 2022
@marcalff
Copy link
Member Author

Please assign to me.
Fixed by #1471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant