Skip to content

A high-performance timeline tracing library for Golang, used by TiDB

License

Notifications You must be signed in to change notification settings

tikv/minitrace-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8e6316b · Sep 23, 2022

History

40 Commits
Jun 19, 2020
Jun 23, 2021
Jun 23, 2021
Jun 7, 2020
Jun 19, 2020
Jun 7, 2020
Jun 19, 2020
Dec 1, 2020
Jun 19, 2020
Jun 23, 2021
Dec 1, 2020
Dec 1, 2020
Jun 23, 2021
Sep 23, 2022
Sep 23, 2022
Jun 23, 2021
Jun 23, 2021

Repository files navigation

Minitrace-Go

Actions Status LICENSE

A high-performance, ergonomic timeline tracing library for Golang.

Basic Usage

package main

import (
    "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)
}

About

A high-performance timeline tracing library for Golang, used by TiDB

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages