Skip to content

Commit

Permalink
Example for traceId.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos authored and appleboy committed Sep 11, 2022
1 parent 755e78d commit c834bc1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ r.Use(GinzapWithConfig(utcLogger, &Config{
If you want to log Open Telemetry TraceId, use `GinzapWithConfig`.

```go
import "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"

r.Use(otelgin.Middleware("demo")) // middleware to extract trace from http request

r.Use(ginzap.GinzapWithConfig(logger, &ginzap.Config{
TimeFormat: time.RFC3339,
UTC: true,
TraceID: true,
}))
```

This will add the `traceId` field to log:

```
{"level":"info","ts":1658442963.805288,"caller":"ginzap/zap.go:82","msg":"/test","status":200,"method":"GET","path":"/test","query":"","ip":"127.0.0.1","user-agent":"curl/7.29.0","latency":0.002036414,"time":"2022-07-21T22:36:03Z","traceId":"285f31ec1dba4b79034c4415ad18e4ed"}
```

0 comments on commit c834bc1

Please sign in to comment.