defpdepsdo
[
# Add the following deps
{:telemetry_logger, github:"bamorim/telemetry_logger"},
{:structured_logger, github:"bamorim/structured_logger"}
]
end
Then run mix deps.get
Switch to the new logger and formatter
# Disable Phoenix Logger
config :phoenix, logger:false# Set the formatter and allow all metadata
config :logger, :console,
format: {StructuredLogger, :format},
metadata::all
# Add to your MyApp.Application.start/2
TelemetryLogger.attach_loggers([
{TelemetryLogger.PlugLogger, router: MyAppWeb.Router}
])
Grafana, Loki and LogQL are awesome
Logs Tips
Do use structured logging.
Don't do "print-debugging".
Do take advantage of log levels.
Do allow your system to change log level without redeploying.
Don't nest fields in your logs.
Logs help with debugging, but...
How to check if the system is healthy?
Requests/second.
Average (and other percentiles) latency.
Memory and CPU usage.
Agenda
What is Observability
Event Logging
Metrics
Traces
Metrics
Numerical values sampled over time
Metrics give you a high-level view of your system
Useful both on a technical level (e.g. memory usage) or domain level (e.g. total count of payments processed).
Great for visualizations.
Metrics are cheap and fast to process
Complexity is only dependent on number of timeseries and sample frequency.
plug :set_logger_trace_iddefset_logger_trace_id(conn, _opts) do
span_ctx = OpenTelemetry.Tracer.current_span_ctx()
if span_ctx != :undefineddo
Logger.metadata(trace_id: OpenTelemetry.Span.hex_trace_id(span_ctx))
end
conn
end
Thank You
It's going to be intense
Will throw a bunch of words
There is a demo repo so you can check code afterwards