Skip to content

Commit

Permalink
Add README & CLI tool to inspect TraceId timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Mar 5, 2024
1 parent 09fb6aa commit 86d3c9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# TraceId

Go package that helps create and pass `TraceId` header among microservices for simple tracing capabilities and log grouping.

The generated `TraceId` value is [UUIDv7](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-03#name-uuid-version-7), which lets you infer the time of the trace creation from its value.

## Example

TODO

## Get time from UUIDv7 value

```
$ go run github.com/go-chi/traceid/cmd/traceid 018e0ee7-3605-7d75-b344-01062c6fd8bc
2024-03-05 14:56:57.477 +0100 CET
```

### Create new UUIDv7:
```
$ go run github.com/go-chi/traceid/cmd/traceid
018e0ee7-3605-7d75-b344-01062c6fd8bc
```

## License
[MIT](./LICENSE)
25 changes: 25 additions & 0 deletions cmd/traceid/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"
"log"
"os"
"time"

"github.com/google/uuid"
)

func main() {
if len(os.Args) <= 1 {
fmt.Println(uuid.Must(uuid.NewV7()))
os.Exit(0)
}

uuid, err := uuid.Parse(os.Args[1])
if err != nil {
log.Fatal(err)
}

t := time.Unix(uuid.Time().UnixTime())
fmt.Println(t)
}

0 comments on commit 86d3c9a

Please sign in to comment.