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
OStreamLogExporter uses ReadWriteLogRecord as the recordable implementation, and this implementation doesn't maintain copy of message body and attributes:
This can result in the use-after-free crash in case the message body or attributes are cleaned-up before the data is processed by batch processor as in below:
#include"opentelemetry/logs/provider.h"
#include"opentelemetry/sdk/logs/batch_log_record_processor.h"
#include"opentelemetry/sdk/logs/logger_provider.h"
#include"opentelemetry/exporters/ostream/log_record_exporter.h"
#include"opentelemetry/sdk/logs/batch_log_record_processor_factory.h"
#include"opentelemetry/sdk/logs/logger_provider_factory.h"
#include"opentelemetry/sdk/logs/processor.h"namespacelogs_api= opentelemetry::logs;
namespacelogs_sdk= opentelemetry::sdk::logs;
namespacelogs_exporter= opentelemetry::exporter::logs;
usingnamespacestd;namespacenostd= opentelemetry::nostd;
intmain(int argc, char** argv)
{
logs_sdk::BatchLogRecordProcessorOptions batch_opts {};
auto os_exporter = unique_ptr<logs_sdk::LogRecordExporter>(
new opentelemetry::exporter::logs::OStreamLogRecordExporter);
auto os_processor =
logs_sdk::BatchLogRecordProcessorFactory::Create(move(os_exporter), batch_opts);
auto provider =
shared_ptr<logs_api::LoggerProvider>(newlogs_sdk::LoggerProvider(move(os_processor)));
// Set the global logger providerlogs_api::Provider::SetLoggerProvider(provider);
auto logger = logs_api::Provider::GetLoggerProvider()->GetLogger("anything");
string* sp = newstring("a message "s + std::to_string(random()) + " is being created "s +
std::to_string(random()));
logger->Info(*sp);
delete sp;
sp = newstring("a message "s + std::to_string(random()));
logger->Info(*sp);
*sp = "Now it is another message entirely";
delete sp;
sleep(10);
}
Just like SpanData implementation which is used in OStream span exporter, the ReadWriteLogRecord should also maintain the copy of these data.
The text was updated successfully, but these errors were encountered:
Another thought, should we limit the usage of OStreamLogRecordExporter in async pipeline as the BatchLogRecordProcessor? So we don't need to make copies of the attributes for most common cases.
The OStreamLogRecordExporter serves as a demonstration model to implement exporters for logs, and it should do it in right way. And also, good to have parity with OStreamSpanExporter which can be used both with Simple and Batch Processor. SpanData in that case maintains the copy of attributes as shared in link above.
lalitb
changed the title
OStreamLogExporter doesn't copy message data and attributes
OStreamLogRecordExporter doesn't copy message data and attributes
Nov 13, 2023
marcalff
added
bug
Something isn't working
and removed
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
labels
Nov 15, 2023
OStreamLogExporter uses ReadWriteLogRecord as the recordable implementation, and this implementation doesn't maintain copy of message body and attributes:
opentelemetry-cpp/sdk/include/opentelemetry/sdk/logs/read_write_log_record.h
Lines 190 to 191 in 46e20a4
This can result in the use-after-free crash in case the message body or attributes are cleaned-up before the data is processed by batch processor as in below:
Just like SpanData implementation which is used in OStream span exporter, the ReadWriteLogRecord should also maintain the copy of these data.
The text was updated successfully, but these errors were encountered: