Linking Logs to Code: Introducing Statement IDs (opens in new tab)

In this blog post, we introduce the concept of statement IDs and how they can be used in Bronto. A statement ID is a unique identifier assigned to log statements in source code. It can be expressed as a simple key-value pair, such as stmt_id=1234567890abcdef.

For instance, the following log statement

Courier Log Bigger Font

log.info(“{} task was performed. duration_sec={}, stmt_id=b5bf893a4bf84d74”, taskName, taskDurationSec)

can lead to many different log entries, e.g.

Courier Log Collection Task

INFOCollection task was performed. duration_sec=2.45, stmt_id=b5bf893a4bf84d74

Courier Log Processing Task

INFOProcessing task was performed. duration_sec=0.03, stmt_id=b5bf893a4bf84d74

Courier Log Aggregation Task

INFOAggregation task was performed. duration_sec=1.06, stmt_id=b5bf893a4bf84d74

As statement IDs are the same between these log entries, we can reliably say that they were issues from the same log statement. This would be more difficult to assert without statement IDs. ‍

Statement IDs Vs File Path and Line Number

Logging frameworks often allow for the file name path and line number representing the location in the source code where a log entry was generated from, to be recorded, e.g. see CODE_FILE and CODE_LINE for SystemD as well as %line and %file for Log4j. This information is valuable for linking log entries back to the exact location in the code. Similarly, statement IDs also help identify the exact source code location from where a log entry is generated.

But they also have other benefits. Because statement IDs are resilient to refactoring, they facilitate identifying log entries from the same source statement, even across different versions of the software, where the file path and line number of these statements may differ between versions. Finally, capturing the file name and line number at runtime can carry a performance penalty (e.g. see Location Information section of https://logging.apache.org/log4j/2.3.x/manual/layouts.html) that certain systems cannot afford. Since statement IDs are introduced at build time, they avoid this issue entirely. ‍

Statement ID Benefits

Regardless of the log management solution you use, there are clear benefits to introducing statement IDs into your logs.

Statement Disambiguity
Loading more...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help