OpsCanary
Back to daily brief
observabilityloggingPractitioner

Mastering Logs for Effective Observability in Production

5 min read OpenTelemetry DocsApr 27, 2026
Share
PractitionerHands-on experience recommended

Logs exist to capture events in your systems, providing a timestamped record that helps you understand what’s happening in production. They can be structured, unstructured, or semistructured, but structured logs are recommended for their reliability and ease of analysis. In a world where observability is key, having a robust logging strategy can make or break your incident response and debugging processes.

OpenTelemetry simplifies log management by allowing you to create logs with any logging library or built-in capabilities. When you activate the SDK or use autoinstrumentation, it automatically correlates your logs with active traces and spans, wrapping the log body with their IDs. This means that every log entry can be tied back to specific requests, giving you a clear view of the context in which events occur. For example, a structured log might look like this: {"timestamp":"2024-08-04T12:34:56.789Z","level":"INFO","service":"user-authentication","message":"User login successful","context":{"userId":"12345"}}. This format allows for easy parsing and interpretation by downstream systems.

In production, you must prioritize structured logging. Unstructured logs can be a nightmare to parse and analyze, especially at scale. While it’s possible to extract insights from unstructured logs, the effort often outweighs the benefits. Be wary of hybrid formats that mix structured and unstructured data, as they can complicate your logging strategy. Remember, a log encoded as JSON is not automatically structured; it may still be semistructured, which can lead to inconsistencies in your data.

Key takeaways

  • Use structured logs with defined schemas for reliable parsing and analysis.
  • Leverage OpenTelemetry to automatically correlate logs with traces and spans.
  • Avoid unstructured logs in production due to their complexity in analysis.
  • Be cautious of hybrid log formats that combine structured and unstructured data.

Why it matters

Effective logging directly impacts your ability to troubleshoot and maintain systems. Structured logs enable quick identification of issues, reducing downtime and improving overall system reliability.

Code examples

chroma
{"timestamp":"2024-08-04T12:34:56.789Z","level":"INFO","service":"user-authentication","environment":"production","message":"User login successful","context":{"userId":"12345","username":"johndoe","ipAddress":"192.168.1.1","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"},"transactionId":"abcd-efgh-ijkl-mnop","duration":200,"request":{"method":"POST","url":"/api/v1/login","headers":{"Content-Type":"application/json","Accept":"application/json"},"body":{"username":"johndoe","password":"******"}},"response":{"statusCode":200,"body":{"success":true,"token":"jwt-token-here"}}}
chroma
2024-08-04T12:45:23Z level=ERROR service=user-authentication userId=12345 action=login message="Failed login attempt" error="Invalid password" ipAddress=192.168.1.1 userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
chroma
[ERROR] 2024-08-04 12:45:23 - Failed to connect to database. Exception: java.sql.SQLException: Timeout expired. Attempted reconnect 3 times. Server: db.example.com, Port: 5432System reboot initiated at 2024-08-04 03:00:00 by user: admin. Reason: Scheduled maintenance. Services stopped: web-server, database, cache. Estimated downtime: 15 minutes.DEBUG - 2024-08-04 09:30:15 - User johndoe performed action: file_upload. Filename: report_Q3_2024.pdf, Size: 2.3 MB, Duration: 5.2 seconds. Result: Success

When NOT to use this

Unstructured logs are not preferred for production observability purposes, as they are much more difficult to parse and analyze at scale. The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.