https://github.com/peterbourgon/trc
In-process request tracing
https://github.com/peterbourgon/trc
Last synced: 4 months ago
JSON representation
In-process request tracing
- Host: GitHub
- URL: https://github.com/peterbourgon/trc
- Owner: peterbourgon
- License: apache-2.0
- Created: 2022-06-05T15:11:21.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-01T19:56:37.000Z (almost 2 years ago)
- Last Synced: 2025-02-27T18:36:33.963Z (4 months ago)
- Language: Go
- Size: 855 KB
- Stars: 97
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trc [](https://pkg.go.dev/github.com/peterbourgon/trc)  
trc provides in-process request tracing, an efficient alternative to logging.
The package is heavily inspired by https://golang.org/x/net/trace, much
gratitude to those authors.Most users should import [package eztrc][eztrc], which offers an API designed
for most common use cases.[eztrc]: https://pkg.go.dev/github.com/peterbourgon/trc/eztrc
Here's a quick-and-dirty usage example for a typical HTTP server.
```go
func main() {
server := NewServer(...) // your HTTP server
traced := eztrc.Middleware(categorize)(server)
go func() { log.Fatal(http.ListenAndServe(":8080", traced)) }() // normal APItraces := eztrc.Handler()
go func() { log.Fatal(http.ListenAndServe(":8081", traces)) }() // traces UIselect {}
}func categorize(r *http.Request) string {
return r.Method + " " + r.URL.Path // assuming a fixed and finite set of possible paths
}func someFunction(ctx context.Context, ...) {
eztrc.Tracef(ctx, "this is a log statement")
// ...
}
```Traces can be viewed, queried, etc. through a web UI.
See the examples directory for more complete example applications.
The current API is experimental and unstable. Breaking changes are guaranteed.
Use at your own risk.