Skip to content

Commit

Permalink
chore(trace): add trace ID and span ID
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi.Wu <[email protected]>
  • Loading branch information
appleboy committed Sep 18, 2022
1 parent 6278943 commit 1a33159
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ func main() {
return "foobar"
})), logger.SetLogger(
logger.WithLogger(func(c *gin.Context, l zerolog.Logger) zerolog.Logger {
if trace.SpanFromContext(c.Request.Context()).SpanContext().IsValid() {
l = l.With().
Str("trace_id", trace.SpanFromContext(c.Request.Context()).SpanContext().TraceID().String()).
Str("span_id", trace.SpanFromContext(c.Request.Context()).SpanContext().SpanID().String()).
Logger()
}

return l.With().
Str("id", requestid.Get(c)).
Str("foo", "bar").
Str("path", c.Request.URL.Path).
Str("traceID", trace.SpanFromContext(c.Request.Context()).SpanContext().TraceID().String()).
Logger()
}),
), func(c *gin.Context) {
Expand Down
8 changes: 7 additions & 1 deletion _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ func main() {
return "foobar"
})), logger.SetLogger(
logger.WithLogger(func(c *gin.Context, l zerolog.Logger) zerolog.Logger {
if trace.SpanFromContext(c.Request.Context()).SpanContext().IsValid() {
l = l.With().
Str("trace_id", trace.SpanFromContext(c.Request.Context()).SpanContext().TraceID().String()).
Str("span_id", trace.SpanFromContext(c.Request.Context()).SpanContext().SpanID().String()).
Logger()
}

return l.With().
Str("id", requestid.Get(c)).
Str("foo", "bar").
Str("path", c.Request.URL.Path).
Str("traceID", trace.SpanFromContext(c.Request.Context()).SpanContext().TraceID().String()).
Logger()
}),
), func(c *gin.Context) {
Expand Down

0 comments on commit 1a33159

Please sign in to comment.