Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Threading;
using System.Threading.Tasks;
using JasperFx.Descriptors;
using Marten;
using Marten.Services;
using Weasel.Postgresql;
using Xunit;
Expand Down Expand Up @@ -714,6 +715,65 @@ public async Task ExecuteBatchPagesAsync_Ensure_The_Correct_Event_And_Tags_Are_E
.ExecuteBatchPagesAsync(_batchPages, _exceptions, CancellationToken.None);
}

[Fact]
public async Task query_session_with_EventTracingConnectionLifetime_uses_storeOptions_logger()
{
var logger = new BatchSuccessRecordingLogger();

var store = DocumentStore.For(options =>
{
options.Connection(ConnectionSource.ConnectionString);
options.OpenTelemetry.TrackConnections = TrackLevel.Normal;

options.Logger(logger);
});

using var listener = new ActivityListener
{
ShouldListenTo = activitySource => activitySource.Name == "Marten",
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllData,
ActivityStarted = _ => { },
ActivityStopped = _ => { }
};

ActivitySource.AddActivityListener(listener);

await using var session = store.QuerySession();

await session.Events.QueryAllRawEvents().FirstOrDefaultAsync();

logger.LastBatch.ShouldNotBeNull();
}

public class BatchSuccessRecordingLogger: IMartenLogger, IMartenSessionLogger
{
public NpgsqlBatch LastBatch;

public void LogFailure(Exception ex, string message) { }

public void RecordSavedChanges(IDocumentSession session, IChangeSet commit) { }

public void OnBeforeExecute(NpgsqlCommand command) { }

public void OnBeforeExecute(NpgsqlBatch batch) { }

public void LogSuccess(NpgsqlCommand command) { }

public void LogFailure(NpgsqlCommand command, Exception ex) { }

public void LogSuccess(NpgsqlBatch batch)
{
LastBatch = batch;
}

public void LogFailure(NpgsqlBatch batch, Exception ex) { }

public IMartenSessionLogger StartSession(IQuerySession session)
{
return this;
}

public void SchemaChange(string sql) { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public EventTracingConnectionLifetime(IConnectionLifetime innerConnectionLifetim
throw new ArgumentException("The tenant id cannot be null, an empty string or whitespace.", nameof(tenantId));
}

InnerConnectionLifetime = innerConnectionLifetime;
Logger = innerConnectionLifetime.Logger;
CommandTimeout = innerConnectionLifetime.CommandTimeout;
InnerConnectionLifetime = innerConnectionLifetime;
_telemetryOptions = telemetryOptions;

var currentActivity = Activity.Current ?? null;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void Dispose()
InnerConnectionLifetime.Dispose();
}

public IMartenSessionLogger Logger { get; set; }
public IMartenSessionLogger Logger { get => InnerConnectionLifetime.Logger; set => InnerConnectionLifetime.Logger = value; }
public int CommandTimeout { get; }
public int Execute(NpgsqlCommand cmd)
{
Expand Down
Loading