You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
In example
multi_processor/main.cc
, the code:Builds a
InMemorySpanExporter
objectTransfers memory ownership to a
SpanProcessor
Use the underlying
InMemorySpanExporter
object directly.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 underlyingInMemorySpanData
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.
The text was updated successfully, but these errors were encountered: