https://github.com/tikv/minitrace-go
A high-performance timeline tracing library for Golang, used by TiDB
https://github.com/tikv/minitrace-go
Last synced: about 2 months ago
JSON representation
A high-performance timeline tracing library for Golang, used by TiDB
- Host: GitHub
- URL: https://github.com/tikv/minitrace-go
- Owner: tikv
- License: apache-2.0
- Created: 2020-06-18T12:19:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T06:11:34.000Z (8 months ago)
- Last Synced: 2024-10-25T00:46:35.126Z (8 months ago)
- Language: Go
- Homepage:
- Size: 88.9 KB
- Stars: 45
- Watchers: 19
- Forks: 7
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# Minitrace-Go
[](https://github.com/tikv/minitrace-go/actions)
[](https://github.com/tikv/minitrace-go/blob/master/LICENSE)A high-performance, ergonomic timeline tracing library for Golang.
## Basic Usage
```go
package mainimport (
"context"
"fmt"
"strconv""github.com/tikv/minitrace-go"
)func tracedFunc(ctx context.Context, event string) {
span := minitrace.StartSpan(ctx, event)
// code snippet...
span.Finish()
}func iterTracedFunc(ctx context.Context) {
// extend tracing context from parent context
ctx, span := minitrace.StartSpanWithContext(ctx, "1")span.AddProperty("k2", "v2")
for i := 2; i < 10; i++ {
tracedFunc(ctx, strconv.Itoa(i))
}
span.Finish()
}func main() {
ctx := context.Background()// enable tracing
ctx, root := minitrace.StartRootSpan(ctx, "root", 0, nil)root.AddProperty("k1", "v1")
// pass the context to traced functions
iterTracedFunc(ctx)// collect tracing results into `spans`
spans, _ := root.Collect()// do something with `spans`
fmt.Printf("%+v", spans)
}
```