Bug Report
OpenTelemetry 1.1.0-beta1
Microsoft.Extensions.Logging 5.0.0
Runtime version netcoreapp3.1
Symptom
The BaseExporter<LogRecord> will process incorrect scopes if BatchLogRecordExportProcessor is used. If SimpleLogRecordExportProcessor is used everything is processed correctly. This is a symptom of BatchLogRecordExportProcessor processing the records after the original scopes are disposed.
What is the expected behavior?
The exporter should have access to correct scopes.
What is the actual behavior?
The scopes that the exported are not consistent.
Reproduce
The unit test bellow reproduces the issue:
[TestCase(true)]
[TestCase(false)]
public void VerifyScopes(bool useBatching)
{
BaseProcessor<LogRecord> processor = useBatching ? new BatchLogRecordExportProcessor(new AssertScopesExporter()): new SimpleLogRecordExportProcessor(new AssertScopesExporter());
var logger = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddProcessor(processor);
options.IncludeFormattedMessage = true;
options.IncludeScopes = true;
});
}).CreateLogger(GetType());
for (int i = 0; i < 1000; i++)
{
using (logger.BeginScope(i.ToString()))
{
using (logger.BeginScope(i.ToString()))
{
using (logger.BeginScope(i.ToString()))
{
logger.LogInformation(i.ToString());
}
}
}
}
processor.ForceFlush();
}
private class AssertScopesExporter : BaseExporter<LogRecord>
{
public override ExportResult Export(in Batch<LogRecord> batch)
{
foreach (var log in batch)
{
int scopes = 0;
log.ForEachScope<object>(
(scope, _) =>
{
Assert.AreEqual(log.FormattedMessage, scope.ToString());
scopes++;
},
null);
Assert.AreEqual(3, scopes);
}
return ExportResult.Success;
}
}
We will close this issue if:
- The unit test above will pass for both test cases.
Additional Context
I think the LogRecord needs to be extended with Scopes property and these must be filled directly by the OpenTelemetryLogger. Current API LogRecord.ForEachScope will simply not work if BatchLogRecordExportProcessor is involved.
Bug Report
OpenTelemetry 1.1.0-beta1Microsoft.Extensions.Logging 5.0.0Runtime version
netcoreapp3.1Symptom
The
BaseExporter<LogRecord>will process incorrect scopes ifBatchLogRecordExportProcessoris used. IfSimpleLogRecordExportProcessoris used everything is processed correctly. This is a symptom ofBatchLogRecordExportProcessorprocessing the records after the original scopes are disposed.What is the expected behavior?
The exporter should have access to correct scopes.
What is the actual behavior?
The scopes that the exported are not consistent.
Reproduce
The unit test bellow reproduces the issue:
We will close this issue if:
Additional Context
I think the
LogRecordneeds to be extended withScopesproperty and these must be filled directly by theOpenTelemetryLogger. Current APILogRecord.ForEachScopewill simply not work ifBatchLogRecordExportProcessoris involved.