SentryKyle TryonTutorial
How to structure a log
Summary
Logging arbitrary JSON objects often produces unstable messages and deeply nested data that complicate searching, aggregating, and debugging production incidents. Structured logging treats log output as real application data by establishing predictable, consistent schemas across services. Engineers should define stable event names using a domain.action pattern and capture dynamic dimensions with flattened, snake_case attributes formatted in dot notation. Attribute payloads must contain only primitive values or primitive arrays rather than arbitrary objects, utilizing low-cardinality result identifiers and explicit units for numeric measurements. Teams can enforce these structural conventions automatically with linting tools such as ESLint, while routing execution durations and timing measurements to tracing spans.
Context
Unstructured log messages with dynamic text and arbitrary nested JSON objects make logs difficult to query, filter, group, aggregate, and analyze during production incident debugging.
Approach / What changed
Adopt a standardized logging schema that utilizes stable domain.action event names, flattened dot-notation attribute keys, primitive values, explicit numeric units, and linting rules for automated enforcement.
Takeaways
Event names should follow a stable domain.action pattern without dynamic strings in the message, placing dynamic variables into scoped attributes instead.
Attributes must use flattened dot-notation keys with snake_case segments and restrict values to primitive types or arrays of primitives rather than raw nested objects.
Numeric attributes should explicitly specify units within their key names, and execution duration measurements should be recorded in tracing spans rather than log attributes.
Source and freshness
- Source
- blog.sentry.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.