Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf: remove NSubstitute from benchmark for Structured Logs
  • Loading branch information
Flash0ver committed Aug 10, 2025
commit a4d2607b711732bc73b97f35d93c223c8e3a18fc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using NSubstitute;
using Sentry.Extensibility;
using Sentry.Internal;

Expand Down Expand Up @@ -30,22 +29,10 @@ public void Setup()
};

var batchInterval = Timeout.InfiniteTimeSpan;

var clientReportRecorder = Substitute.For<IClientReportRecorder>();
clientReportRecorder
.When(static recorder => recorder.RecordDiscardedEvent(Arg.Any<DiscardReason>(), Arg.Any<DataCategory>(), Arg.Any<int>()))
.Throw<UnreachableException>();

var diagnosticLogger = Substitute.For<IDiagnosticLogger>();
diagnosticLogger
.When(static logger => logger.IsEnabled(Arg.Any<SentryLevel>()))
.Throw<UnreachableException>();
diagnosticLogger
.When(static logger => logger.Log(Arg.Any<SentryLevel>(), Arg.Any<string>(), Arg.Any<Exception>(), Arg.Any<object[]>()))
.Throw<UnreachableException>();
var clientReportRecorder = new NullClientReportRecorder();

_hub = new Hub(options, DisabledHub.Instance);
_batchProcessor = new StructuredLogBatchProcessor(_hub, BatchCount, batchInterval, clientReportRecorder, diagnosticLogger);
_batchProcessor = new StructuredLogBatchProcessor(_hub, BatchCount, batchInterval, clientReportRecorder, null);
_log = new SentryLog(DateTimeOffset.Now, SentryId.Empty, SentryLogLevel.Trace, "message");
}

Expand All @@ -66,3 +53,21 @@ public void Cleanup()
_hub.Dispose();
}
}

file sealed class NullClientReportRecorder : IClientReportRecorder
{
public void RecordDiscardedEvent(DiscardReason reason, DataCategory category, int quantity = 1)
{
// no-op
}

public ClientReport GenerateClientReport()
{
throw new UnreachableException();
}

public void Load(ClientReport report)
{
throw new UnreachableException();
}
}