flow-emulator icon indicating copy to clipboard operation
flow-emulator copied to clipboard

Add transaction ID to Cadence log entries

Open bartolomej opened this issue 2 years ago • 2 comments

Issue To Be Solved

Let's say we have a transaction that uses the log() function to print something.

transaction {
  execute {
    log("Hello!")
  }
}

When that transaction is executed on the local emulator blockchain, the produced log outputs are displayed as emulator (Flow CLI) logs like so:

9:24PM INF LOG: "Hello!"
9:25PM INF LOG: "Hello!"

Problem: There is no way to tie a log entry to the transaction that emitted it. I believe this would be useful for many reasons:

  • users of Flow CLI can clearly see which logs were emitted within the same transaction (even if they can't remember the transaction ID)
    • this is especially useful in cases where each transaction emits multiple logs, which makes it harder to visually categorize them
  • developer tools using flow-emulator (e.g. Flowser, Flow playground,...) can provide a better UX
    • this would allow such tools to extract the transaction ID from each log and show it within the UI of the corresponding transaction

Suggest A Solution

We could solve this by including the transaction ID in each Cadence log entry, like so:

9:24PM INF transactionId=33d14437d6e5cb23b4d6de3b70ea754a815e2d4fac79ae85a29558da2b942aef LOG: "Hello!"
9:25PM INF transactionId=70d05c026c8c400dbd7a8627daffdd89cd3ca3d64c1fdf621275b8fd0f245833 LOG: "Hello!"

... or we could include only a subset ID to make it easier to view in the terminal:

9:24PM INF transactionId=33d14...422aef LOG: "Hello!"
9:25PM INF transactionId=70d05...45833 LOG: "Hello!"

Context

In the Flowser app, we have a logs view that shows all historic logs that ever happened (in the current emulator session). But when you execute a transaction in isolation, you usually only care about that transaction's logs and not all the historic ones.

This change would allow us to show currently executed transaction logs within that transaction's info view (related to this feature we just built: https://github.com/onflowser/flowser/pull/170).

bartolomej avatar Aug 19 '23 19:08 bartolomej

I think this is a nice idea, can be implemented, but maybe we can put it behind a flag. txId is pretty long and takes a lot of space ( or maybe we can put it after the message ) what do you think @sideninja ?

9:24PM INF LOG: "Hello!" transactionId=33d14437d6e5cb23b4d6de3b70ea754a815e2d4fac79ae85a29558da2b942aef 
9:25PM INF LOG: "Hello!" transactionId=70d05c026c8c400dbd7a8627daffdd89cd3ca3d64c1fdf621275b8fd0f245833 
9:24PM INF log="Hello!" transactionId=33d14437d6e5cb23b4d6de3b70ea754a815e2d4fac79ae85a29558da2b942aef 
9:25PM INF log="Hello!" transactionId=70d05c026c8c400dbd7a8627daffdd89cd3ca3d64c1fdf621275b8fd0f245833 

bluesign avatar Aug 20 '23 11:08 bluesign

I would put it after the message. @chasefleming will be taking this on as his onboarding task.

devbugging avatar Aug 21 '23 10:08 devbugging