Dotnet-IO-logger / core

Dotnet Input output logger
https://marketplace.visualstudio.com/items?itemName=Diol.diol
MIT License
28 stars 1 forks source link

EF calls during a transaction override queries #47

Closed OlzhabaevSh closed 4 weeks ago

OlzhabaevSh commented 2 months ago

Describe the bug Using a transaction for multiple operations will override the query value in the DIOL.

Code example:

app.MapPost("/transact1", async (ApplicationDbContext dbContext) =>
{
    using var transaction = await dbContext.Database.BeginTransactionAsync();

    try
    {
        var category = new Category { Name = "New Category" };
        dbContext.Categories.Add(category);
        await dbContext.SaveChangesAsync();

        var product = new Product { Name = "New Product", CategoryId = category.Id };
        dbContext.Products.Add(product);
        await dbContext.SaveChangesAsync();

        await transaction.CommitAsync();
    }
    catch (Exception)
    {
        await transaction.RollbackAsync();
    }

})
.WithName("GetTransact1")
.WithOpenApi();

To Reproduce Steps to reproduce the behavior:

  1. Add a new endpoint with a SQL transaction example (you can take the example above)
  2. Use DIOL
  3. See the result

Expected behavior There are two workable solutions:

  1. keep a transaction as a single row in DIOL and then just attach all queries in it.
  2. Every new query in a transaction will be presented as a new row.

The first approach is simple and has only one concern: what operation and table name should we show on the master page? For example:

  1. Just "Transaction" in the operation section?
  2. the first table name and operation in the transaction?

In real scenario we could expect a lot of queries with transactions. In this case we can face a scenario when every row in DIOL will just show "Transaction" wich will not help to search queries properly.

The second approach is a bit interesting. We can keep all queries as a new row, but we need to decide:

  1. Should we show transactions?
  2. Should we group a set of queries under a transaction?
  3. If yes, how?

Another question is how we can separate queries under the same transaction.

OlzhabaevSh commented 2 months ago

After investigations I can see next:

During running queries under a transaction we can see that

ConnectionOpening: 00006013-0000-0000-0000-000008c19d59 CommandExecuting: 000000db-0001-0000-c838-0000ffdcd7b5 CommandExecuted: 00006013-0000-0000-0000-000008c19d59 CommandExecuting: 000000fc-0001-0000-c838-0000ffdcd7b5 CommandExecuted: 00006013-0000-0000-0000-000008c19d59

Maybe there is an option how we can associate different activity ids.