traceis a wrapper for the net/trace packagethat adds logging and metrics to de-clutter your functions.
tracewraps all of the functionality of net/trace, but also replicates the logs to a structured logger built on Go's standard logging library.
Metrics are exported to Prometheus with trace duration histograms by name/family, trace counts by name/family, and errors by trace name/family.
the net/trace#EventLog is also implemented in the same manner, minus metrics exposition, which doesn't make sense there.
examples/gogrep has an example command-line application that shows usage of the tracefunctionality to both capture trace information and logs with a single tool.
examples/service has an example web application that shows usage of the tracefunctionality to both capture trace information and logs with a single tool, combined with the trace.EventLogwhich serves as a single logging and event source for your application.
Log Output - trace
[code]2016/10/03 00:34:05 name=http - Listening on :3000[/code] Metrics Output
traceoffers two useful and one fun way to expose your metrics.
trace.ServeMetrics()will serve the metrics in Prometheus text format. Use this for long-running apps/services.
trace.PushMetrics()will push the metrics to a Prometheus push server. Use this for command-line utilities.
trace.DumpMetrics()will return a string with the metrics that Prometheus would serve, suitable for inspection, printing, tests.
traceexposes the underlying net/trace /debug/requests and /debug/events endpoints for handy visual representation of the traces, their timing/histograms, and the event log of your application.